Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

For #1002 - ensure start/end are passed along to future calls #1029

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions scripts/genetic_backtester/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -561,10 +573,10 @@ var generateCommandParams = input => {
if(key == "selector"){
result = input[key].normalized + result;
}

else result += " --"+key+"="+input[key];
}

}
return result;
}
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -635,33 +647,33 @@ 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}.`);
}

// 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();
}
});

});
};

Expand Down