use of suite.trade.Trade_.UpdatePortfolio in project suite by stupidsing.
the class WalkForwardAllocTester method tick.
public String tick(Time time, Map<String, Float> priceBySymbol) {
int last = windowSize - 1;
System.arraycopy(times, 0, times, 1, last);
times[last] = time.epochSec();
for (Entry<String, DataSource> e : dsBySymbol.entrySet()) {
String symbol = e.getKey();
float[] prices = e.getValue().prices;
System.arraycopy(prices, 0, prices, 1, last);
prices[last] = priceBySymbol.get(symbol);
}
AlignKeyDataSource<String> akds = new AlignKeyDataSource<>(times, Read.from2(dsBySymbol));
List<Pair<String, Double>> ratioBySymbol = wfa.allocate(akds, windowSize);
UpdatePortfolio up = Trade_.updatePortfolio(time.ymdHms(), account, ratioBySymbol, assetBySymbol, Read.from2(priceBySymbol).mapValue(Eod::of).toMap());
float valuation_;
valuations.append(valuation_ = up.valuation0);
for (Pair<String, Float> e : up.val0.streamlet()) holdBySymbol.compute(e.t0, (s, h) -> e.t1 / valuation_ + (h != null ? h : 0d));
List<Trade> trades_ = up.trades;
String actions;
if (windowSize <= valuations.size())
actions = play(trades_);
else
actions = "wait";
return //
time.ymdHms() + ", valuation = " + //
valuation_ + ", portfolio = " + //
account + ", actions = " + actions;
}
Aggregations