use of suite.trade.walkforwardalloc.WalkForwardAllocConfiguration in project suite by stupidsing.
the class WalkForwardRecorderMain method run.
@Override
protected boolean run(String[] args) {
Streamlet<Asset> assets = cfg.queryCompaniesByMarketCap(Time.now());
float fund0 = 1000000f;
Trade_.isCacheQuotes = false;
Trade_.isShortSell = true;
Trade_.leverageAmount = fund0;
if (Boolean.FALSE) {
// record
String ts = Time.now().ymdHms().replace("-", "").replace(" ", "-").replace(":", "");
String filename = "wfa." + ts + ".csv";
Schedule schedule = //
Schedule.ofRepeat(5, () -> {
String ymdHms = Time.now().ymdHms();
Map<String, Float> priceBySymbol = cfg.quote(assets.map(asset -> asset.symbol).toSet());
try (OutputStream os = //
Files.newOutputStream(//
HomeDir.resolve(filename), //
StandardOpenOption.APPEND, //
StandardOpenOption.CREATE, //
StandardOpenOption.WRITE);
PrintWriter bw = new PrintWriter(os)) {
for (Entry<String, Float> e : priceBySymbol.entrySet()) bw.println(ymdHms + ", " + e.getKey() + ", " + e.getValue());
} catch (IOException ex) {
Fail.t(ex);
}
});
Scheduler.of(schedule.filterTime(dt -> HkexUtil.isMarketOpen(Time.of(dt)))).run();
} else {
// replay
String ts = "20170612-092616";
String filename = "wfa." + ts + ".csv";
Map<Time, Map<String, Float>> data = new TreeMap<>();
try (//
InputStream is = Files.newInputStream(HomeDir.resolve(filename));
//
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr)) {
while (br.ready()) {
String[] array = br.readLine().split(",");
Time time = Time.of(array[0].trim());
String symbol = array[1].trim();
float price = Float.parseFloat(array[2].trim());
data.computeIfAbsent(time, s -> new HashMap<>()).put(symbol, price);
}
} catch (IOException ex) {
Fail.t(ex);
}
WalkForwardAllocConfiguration wfac = new //
WalkForwardAllocConfiguration(//
cfg.queryCompaniesByMarketCap(Time.now()), bag.rsi.unleverage().walkForwardAllocator());
WalkForwardAllocTester tester = new WalkForwardAllocTester(cfg, wfac.assets, fund0, wfac.walkForwardAllocator);
for (Entry<Time, Map<String, Float>> e : data.entrySet()) System.out.println(tester.tick(e.getKey(), e.getValue()));
System.out.println(tester.conclusion());
}
return true;
}
use of suite.trade.walkforwardalloc.WalkForwardAllocConfiguration in project suite by stupidsing.
the class WalkForwardTestMain method run.
@Override
protected boolean run(String[] args) {
float fund0 = 1000000f;
Trade_.isCacheQuotes = false;
Trade_.isShortSell = true;
Trade_.leverageAmount = fund0;
WalkForwardAllocConfiguration wfac = new //
WalkForwardAllocConfiguration(//
cfg.queryCompaniesByMarketCap(Time.now()), bag.rsi.unleverage().walkForwardAllocator());
WalkForwardAllocTester tester = new WalkForwardAllocTester(cfg, wfac.assets, fund0, wfac.walkForwardAllocator);
Schedule schedule = //
Schedule.ofRepeat(5, //
() -> System.out.println(tester.tick())).filterTime(dt -> HkexUtil.isMarketOpen(Time.of(dt)));
Scheduler.of(schedule).run();
return true;
}
Aggregations