From 203d3bd1db4c6d7fa3e91e2150dd5522609c7c48 Mon Sep 17 00:00:00 2001 From: Glenn Sidney Date: Mon, 1 Jan 2018 17:40:19 -0500 Subject: [PATCH] For #1002 - ensure start/end are passed along to future calls --- scripts/genetic_backtester/darwin.js | 40 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/scripts/genetic_backtester/darwin.js b/scripts/genetic_backtester/darwin.js index f99a7afc36..8d78ea3343 100755 --- a/scripts/genetic_backtester/darwin.js +++ b/scripts/genetic_backtester/darwin.js @@ -119,6 +119,8 @@ let processOutput = output => { let losses = wlMatch !== null ? parseInt(wlMatch[2]) : 0; let errorRate = errMatch !== null ? parseInt(errMatch[1]) : 0; let days = parseInt(params.days); + let start = parseInt(params.start); + let end = parseInt(params.start); let roi = roundp( ((endBalance - params.currency_capital) / params.currency_capital) * 100, @@ -136,10 +138,21 @@ let processOutput = output => { delete r.population_data; delete r.sell_pct; delete r.start; + delete r.end; delete r.stats; delete r.use_strategies; delete r.verbose; + if (start) { + r.start = moment(start).format("YYYYMMDDhhmm"); + } + if (end) { + r.end = moment(end).format("YYYYMMDDhhmm"); + } + if (!start && !end && params.days) { + r.days = params.days; + } + return { params: 'module.exports = ' + JSON.stringify(r), endBalance: parseFloat(endBalance), @@ -148,7 +161,6 @@ let processOutput = output => { wins: wins, losses: losses, errorRate: parseFloat(errorRate), - days: days, periodLength: params.periodLength, min_periods: params.min_periods, markup_pct: params.markup_pct, @@ -561,10 +573,10 @@ var generateCommandParams = input => { if(key == "selector"){ result = input[key].normalized + result; } - + else result += " --"+key+"="+input[key]; } - + } return result; } @@ -589,7 +601,7 @@ let simulateGeneration = () => { if (!days) { if (argv.start) { var start = moment(argv.start, "YYYYMMDDhhmm"); - days = moment().diff(start, 'days'); + days = Math.max(1, moment().diff(start, 'days')); } else { var end = moment(argv.end, "YYYYMMDDhhmm"); @@ -624,7 +636,7 @@ let simulateGeneration = () => { let fileDate = Math.round(+new Date() / 1000); let csvFileName = `simulations/backtesting_${fileDate}.csv`; - + let poolData = {}; selectedStrategies.forEach(function(v) { poolData[v] = pools[v]['pool'].population(); @@ -635,13 +647,13 @@ let simulateGeneration = () => { var filesSaved = 0; saveGenerationData(csvFileName, jsonFileName, dataCSV, dataJSON, (id)=>{ filesSaved++; - if(filesSaved == 2){ + if(filesSaved == 2){ console.log(`\n\nGeneration's Best Results`); selectedStrategies.forEach((v)=> { - let best = pools[v]['pool'].best(); + let best = pools[v]['pool'].best(); if(best.sim){ console.log(`\t(${v}) Sim Fitness ${best.sim.fitness}, VS Buy and Hold: ${best.sim.vsBuyHold} End Balance: ${best.sim.endBalance}, Wins/Losses ${best.sim.wins}/${best.sim.losses}.`); - + } else { console.log(`\t(${v}) Result Fitness ${results[0].fitness}, VS Buy and Hold: ${results[0].vsBuyHold}, End Balance: ${results[0].endBalance}, Wins/Losses ${results[0].wins}/${results[0].losses}.`); } @@ -649,19 +661,19 @@ let simulateGeneration = () => { // prepare command snippet from top result for this strat let prefix = './zenbot.sh sim '; let bestCommand = generateCommandParams(results[0]); - + bestCommand = prefix + bestCommand; - bestCommand = bestCommand + ' --days=' + argv.days + ' --asset_capital=' + argv.asset_capital + ' --currency_capital=' + argv.currency_capital; - + bestCommand = bestCommand + ' --asset_capital=' + argv.asset_capital + ' --currency_capital=' + argv.currency_capital; + console.log(bestCommand + '\n'); - + let nextGen = pools[v]['pool'].evolve(); }); - + simulateGeneration(); } }); - + }); };