use of suite.trade.backalloc.BackAllocTester.Simulate in project suite by stupidsing.
the class DailyMain method alloc.
private Result alloc(String tag, float fund, BackAllocator backAllocator, Streamlet<Asset> assets) {
TimeRange period = TimeRange.daysBefore(64);
Simulate sim = BackAllocTester.of(cfg, period, assets, backAllocator, log).simulate(fund);
Account account0 = Account.ofPortfolio(cfg.queryHistory().filter(r -> String_.equals(r.strategy, tag)));
Account account1 = sim.account;
Map<String, Integer> assets0 = account0.assets();
Map<String, Integer> assets1 = account1.assets();
Set<String> symbols = Set_.union(assets0.keySet(), assets1.keySet());
Map<String, Float> priceBySymbol = cfg.quote(symbols);
List<Trade> trades = Trade_.diff(Trade.NA, assets0, assets1, priceBySymbol::get).toList();
sb.append("\nstrategy = " + tag + ", " + sim.conclusion());
return new Result(tag, trades);
}
use of suite.trade.backalloc.BackAllocTester.Simulate in project suite by stupidsing.
the class BackTestMain method run.
@Override
protected boolean run(String[] args) {
// BEGIN
// END
String arg0 = 0 < args.length ? args[0] : "";
String arg1 = 1 < args.length ? args[1] : "";
String arg2 = 2 < args.length ? args[2] : "";
Streamlet<String> strategyMatches = !arg0.isEmpty() ? Read.from(arg0.split(",")) : null;
Streamlet<Integer> years = !arg1.isEmpty() ? //
Read.from(//
arg1.split(",")).concatMap(s -> {
Pair<String, String> pair = ParseUtil.search(s, "-", Assoc.RIGHT);
return //
pair != null ? //
Ints_.range(Integer.valueOf(pair.t0), Integer.valueOf(pair.t1)).map(i -> i) : Read.each(Integer.valueOf(s));
}) : //
Ints_.range(2007, Trade_.thisYear).map(i -> i);
Fun<Time, Streamlet<Asset>> fun = //
!arg2.isEmpty() ? //
time -> Read.from(arg2.split(",")).map(cfg::queryCompany).collect(As::streamlet) : cfg::queryCompaniesByMarketCap;
BackAllocConfigurations bac_ = new BackAllocConfigurations(cfg, fun);
Streamlet2<String, BackAllocConfiguration> bacByTag = bac_.bacs().bacByName;
Streamlet2<String, Simulate> simulationByKey = //
bacByTag.filterKey(//
n -> strategyMatches == null || strategyMatches.isAny(sm -> Wildcard.match(sm, n) != null)).map(//
Pair::of).join2(//
years.sort(Object_::compare).map(TimeRange::ofYear)).map2((pair, period) -> pair.t0, (pair, period) -> {
BackAllocConfiguration bac = pair.t1;
Streamlet<Asset> assets = bac.assetsFun.apply(period.from);
return runner.backTest(bac.backAllocator, period, assets);
}).collect(As::streamlet2);
String content0 = //
Read.bytes(//
Paths.get("src/main/java/" + getClass().getName().replace('.', '/') + ".java")).collect(//
As::utf8decode).map(//
Chars::toString).collect(As::joined);
String content1 = ParseUtil.fit(content0, "// BEGIN", "// END")[1];
System.out.println(content1);
System.out.println(runner.conclude(simulationByKey));
return true;
}
use of suite.trade.backalloc.BackAllocTester.Simulate in project suite by stupidsing.
the class BackAllocBackTestTest method testBackTest.
@Test
public void testBackTest() {
BackAllocator backAllocator = new PmamrBackAllocator().backAllocator();
Simulate sim = runner.backTest(backAllocator, period);
SummarizeByStrategy<String> sbs = Summarize.of(cfg, Read.from(sim.trades)).summarize(trade -> trade.symbol);
System.out.println(sbs.log);
assertGrowth(out(sim));
}
Aggregations