use of primal.streamlet.Streamlet in project suite by stupidsing.
the class Trade_ method collectBrokeredTrades.
public static Streamlet<Trade> collectBrokeredTrades(Puller<Trade> puller) {
var trades0 = puller.toArray(Trade.class);
var trades1 = new ArrayList<Trade>();
var length0 = trades0.length;
var i0 = 0;
IntIntSink tx = (i0_, i1_) -> {
if (forInt(i0_, i1_).mapInt(i -> trades0[i].buySell).sum() != 0)
while (i0_ < i1_) {
var trade0 = trades0[i0_++];
if (!Equals.string(trade0.remark, "#"))
trades1.add(trade0);
}
};
for (var i = 1; i < length0; i++) {
var trade0 = trades0[i0];
var trade1 = trades0[i];
var isGroup = //
true && //
Equals.string(trade0.date, trade1.date) && //
Equals.string(trade0.symbol, trade1.symbol) && trade0.price == trade1.price;
if (!isGroup) {
tx.sink2(i0, i);
i0 = i;
}
}
tx.sink2(i0, length0);
return Read.from(trades1);
}
use of primal.streamlet.Streamlet 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;
}
use of primal.streamlet.Streamlet in project suite by stupidsing.
the class Plotty method plot.
public boolean plot(Streamlet<float[]> xyts) {
var data = //
xyts.map(//
xyt -> ReadFlt.from(xyt).index().map((y, x) -> FltFltPair.of(x, y)).collect(this::xyt) + ",").toJoinedString();
var file = Tmp.path("plot$" + Get.temp() + ".html");
WriteFile.to(file).writeAndClose(//
"" + //
"<head><script src='https://cdn.plot.ly/plotly-latest.min.js'></script></head>" + //
"<body><div id='plot'></div></body>" + //
"<script>" + "Plotly.newPlot('plot', [" + data + //
"], {" + //
" yaxis: { rangemode: 'tozero', zeroline: true, }" + //
"});" + "</script>");
Read.from(browsers).filter(b -> new File(b).exists()).forEach(browser -> Execute.shell("'" + browser + "' --incognito '" + file + "'"));
return true;
}
Aggregations