use of primal.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) {
var sum = 0f;
for (var pair : Read.fromMultimap(trades.toMultimap(trade -> trade.symbol))) {
var dividends = fun.apply(pair.k);
var puller = Puller.of(pair.v);
LngIntPair tn = LngIntPair.of(0l, 0);
Source<LngIntPair> tradeSource = () -> {
var trade = puller.pull();
var 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));
};
var tn1 = tradeSource.g();
for (var dividend : dividends) {
while (tn1 != null && tn1.t0 < dividend.t0) {
tn.update(tn1.t0, tn1.t1);
tn1 = tradeSource.g();
}
var amount = tn.t1 * dividend.t1;
sum += amount - feeFun.apply(amount);
}
}
return sum;
}
Aggregations