Search in sources :

Example 1 with IntIntSink

use of suite.primitive.IntIntSink in project suite by stupidsing.

the class Trade_ method collectBrokeredTrades.

public static Streamlet<Trade> collectBrokeredTrades(Outlet<Trade> outlet) {
    Trade[] trades0 = outlet.toArray(Trade.class);
    List<Trade> trades1 = new ArrayList<>();
    int length0 = trades0.length;
    int i0 = 0;
    IntIntSink tx = (i0_, i1_) -> {
        if (Ints_.range(i0_, i1_).mapInt(i -> trades0[i].buySell).sum() != 0)
            while (i0_ < i1_) {
                Trade trade0 = trades0[i0_++];
                if (!String_.equals(trade0.remark, "#"))
                    trades1.add(trade0);
            }
    };
    for (int i = 1; i < length0; i++) {
        Trade trade0 = trades0[i0];
        Trade trade1 = trades0[i];
        boolean isGroup = // 
        true && // 
        String_.equals(trade0.date, trade1.date) && // 
        String_.equals(trade0.symbol, trade1.symbol) && trade0.price == trade1.price;
        if (!isGroup) {
            tx.sink2(i0, i);
            i0 = i;
        }
    }
    tx.sink2(i0, length0);
    return Read.from(trades1);
}
Also used : LngIntPair(suite.primitive.adt.pair.LngIntPair) Outlet(suite.streamlet.Outlet) Read(suite.streamlet.Read) Obj_Flt(suite.primitive.FltPrimitives.Obj_Flt) IntFltPair(suite.primitive.adt.pair.IntFltPair) IntIntSink(suite.primitive.IntIntSink) HashMap(java.util.HashMap) Fun(suite.util.FunUtil.Fun) ArrayList(java.util.ArrayList) String_(suite.util.String_) Dbl_Dbl(suite.primitive.Dbl_Dbl) Map(java.util.Map) Ints_(suite.primitive.Ints_) Valuation(suite.trade.Account.Valuation) Set_(suite.util.Set_) LngFltPair(suite.primitive.adt.pair.LngFltPair) Friends.min(suite.util.Friends.min) Source(suite.util.FunUtil.Source) Set(java.util.Set) Pair(suite.adt.pair.Pair) Friends.max(suite.util.Friends.max) List(java.util.List) Obj_Int(suite.primitive.IntPrimitives.Obj_Int) Streamlet(suite.streamlet.Streamlet) Eod(suite.trade.data.DataSource.Eod) MathUtil(suite.math.MathUtil) As(suite.streamlet.As) IntIntSink(suite.primitive.IntIntSink) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Pair (suite.adt.pair.Pair)1 MathUtil (suite.math.MathUtil)1 Dbl_Dbl (suite.primitive.Dbl_Dbl)1 Obj_Flt (suite.primitive.FltPrimitives.Obj_Flt)1 IntIntSink (suite.primitive.IntIntSink)1 Obj_Int (suite.primitive.IntPrimitives.Obj_Int)1 Ints_ (suite.primitive.Ints_)1 IntFltPair (suite.primitive.adt.pair.IntFltPair)1 LngFltPair (suite.primitive.adt.pair.LngFltPair)1 LngIntPair (suite.primitive.adt.pair.LngIntPair)1 As (suite.streamlet.As)1 Outlet (suite.streamlet.Outlet)1 Read (suite.streamlet.Read)1 Streamlet (suite.streamlet.Streamlet)1 Valuation (suite.trade.Account.Valuation)1