Search in sources :

Example 1 with LngIntPair

use of suite.primitive.adt.pair.LngIntPair in project suite by stupidsing.

the class Trade_ method dividend.

public static float dividend(Streamlet<Trade> trades, Fun<String, LngFltPair[]> fun, Dbl_Dbl feeFun) {
    float sum = 0f;
    for (Pair<String, List<Trade>> pair : trades.toMultimap(trade -> trade.symbol).listEntries()) {
        LngFltPair[] dividends = fun.apply(pair.t0);
        Outlet<Trade> outlet = Outlet.of(pair.t1);
        LngIntPair tn = LngIntPair.of(0l, 0);
        Source<LngIntPair> tradeSource = () -> {
            Trade trade = outlet.next();
            long t = trade != null ? Time.of(trade.date + " 12:00:00").epochSec(8) : Long.MAX_VALUE;
            return LngIntPair.of(t, tn.t1 + (trade != null ? trade.buySell : 0));
        };
        LngIntPair tn1 = tradeSource.source();
        for (LngFltPair dividend : dividends) {
            while (tn1 != null && tn1.t0 < dividend.t0) {
                tn.update(tn1.t0, tn1.t1);
                tn1 = tradeSource.source();
            }
            float amount = tn.t1 * dividend.t1;
            sum += amount - feeFun.apply(amount);
        }
    }
    return sum;
}
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) LngFltPair(suite.primitive.adt.pair.LngFltPair) LngIntPair(suite.primitive.adt.pair.LngIntPair) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with LngIntPair

use of suite.primitive.adt.pair.LngIntPair in project suite by stupidsing.

the class LngIntMap method forEach.

public void forEach(LngIntSink sink) {
    LngIntPair pair = LngIntPair.of((long) 0, (int) 0);
    LngIntSource source = source_();
    while (source.source2(pair)) sink.sink2(pair.t0, pair.t1);
}
Also used : LngIntPair(suite.primitive.adt.pair.LngIntPair) LngIntSource(suite.primitive.LngIntSource)

Aggregations

LngIntPair (suite.primitive.adt.pair.LngIntPair)2 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 LngIntSource (suite.primitive.LngIntSource)1 IntFltPair (suite.primitive.adt.pair.IntFltPair)1 LngFltPair (suite.primitive.adt.pair.LngFltPair)1 As (suite.streamlet.As)1 Outlet (suite.streamlet.Outlet)1 Read (suite.streamlet.Read)1 Streamlet (suite.streamlet.Streamlet)1