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;
}
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);
}
Aggregations