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

Filter the simulation output from ansi-codes so that the results can … #581

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions scripts/auto_backtester/backtester.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let parallel = require('run-parallel-limit');
let json2csv = require('json2csv');
let roundp = require('round-precision');
let fs = require('fs');
let StripAnsi = require('strip-ansi');

let VERSION = 'Zenbot 4.04 Backtester v0.2';

Expand Down Expand Up @@ -72,7 +73,7 @@ let objectProduct = obj => {
let runCommand = (strategy, cb) => {
countArr.push(1);
let strategyArgs = {
cci_srsi: `--cci_periods=${strategy.rsi_periods} --rsi_periods=${strategy.srsi_periods} --srsi_periods=${strategy.srsi_periods} --srsi_k=${strategy.srsi_k} --srsi_d=${strategy.srsi_d} --oversold_rsi=${strategy.oversold_rsi} --overbought_rsi=${strategy.overbought_rsi} --oversold_cci=${strategy.oversold_cci} --overbought_cci=${strategy.overbought_cci} --constant=${strategy.constant}`,
cci_srsi: `--cci_periods=${strategy.rsi_periods} --rsi_periods=${strategy.srsi_periods} --srsi_periods=${strategy.srsi_periods} --srsi_k=${strategy.srsi_k} --srsi_d=${strategy.srsi_d} --oversold_rsi=${strategy.oversold_rsi} --overbought_rsi=${strategy.overbought_rsi} --oversold_cci=${strategy.oversold_cci} --overbought_cci=${strategy.overbought_cci} --constant=${strategy.constant}`,
srsi_macd: `--rsi_periods=${strategy.rsi_periods} --srsi_periods=${strategy.srsi_periods} --srsi_k=${strategy.srsi_k} --srsi_d=${strategy.srsi_d} --oversold_rsi=${strategy.oversold_rsi} --overbought_rsi=${strategy.overbought_rsi} --ema_short_period=${strategy.ema_short_period} --ema_long_period=${strategy.ema_long_period} --signal_period=${strategy.signal_period} --up_trend_threshold=${strategy.up_trend_threshold} --down_trend_threshold=${strategy.down_trend_threshold}`,
macd: `--ema_short_period=${strategy.ema_short_period} --ema_long_period=${strategy.ema_long_period} --signal_period=${strategy.signal_period} --up_trend_threshold=${strategy.up_trend_threshold} --down_trend_threshold=${strategy.down_trend_threshold} --overbought_rsi_periods=${strategy.overbought_rsi_periods} --overbought_rsi=${strategy.overbought_rsi}`,
rsi: `--rsi_periods=${strategy.rsi_periods} --oversold_rsi=${strategy.oversold_rsi} --overbought_rsi=${strategy.overbought_rsi} --rsi_recover=${strategy.rsi_recover} --rsi_drop=${strategy.rsi_drop} --rsi_divisor=${strategy.rsi_divisor}`,
Expand Down Expand Up @@ -102,7 +103,8 @@ let processOutput = output => {
let wlRegexp = /win\/loss: (\d+)\/(\d+)/g;
let errRegexp = /error rate: (.*)%/g;

let output2 = output.substr(output.length - 3000);
let strippedOutput = StripAnsi(output);
let output2 = strippedOutput.substr(strippedOutput.length - 3500);

let rawParams = jsonRegexp.exec(output2)[1];
let params = JSON.parse(rawParams);
Expand Down Expand Up @@ -134,12 +136,12 @@ let processOutput = output => {
cciPeriods: params.cci_periods,
rsiPeriods: params.rsi_periods,
srsiPeriods: params.srsi_periods,
srsiK: params.srsi_k,
srsiD: params.srsi_d,
oversoldRsi: params.oversold_rsi,
srsiK: params.srsi_k,
srsiD: params.srsi_d,
oversoldRsi: params.oversold_rsi,
overboughtRsi: params.overbought_rsi,
oversoldCci: params.oversold_cci,
overboughtCci: params.overbought_cci,
oversoldCci: params.oversold_cci,
overboughtCci: params.overbought_cci,
constant: params.consant,

// srsi_macd
Expand Down Expand Up @@ -296,7 +298,7 @@ parallel(tasks, PARALLEL_LIMIT, (err, results) => {
let filedsGeneral = ['roi', 'vsBuyHold', 'errorRate', 'wlRatio', 'frequency', 'endBalance', 'buyHold', 'wins', 'losses', 'period', 'min_periods', 'days'];
let filedNamesGeneral = ['ROI (%)', 'VS Buy Hold (%)', 'Error Rate (%)', 'Win/Loss Ratio', '# Trades/Day', 'Ending Balance ($)', 'Buy Hold ($)', '# Wins', '# Losses', 'Period', 'Min Periods', '# Days'];
let fields = {
cci_srsi: filedsGeneral.concat(['cciPeriods', 'rsiPeriods', 'srsiPeriods', 'srsiK', 'srsiD', 'oversoldRsi', 'overboughtRsi', 'oversoldCci', 'overboughtCci', 'Constant', 'params']),
cci_srsi: filedsGeneral.concat(['cciPeriods', 'rsiPeriods', 'srsiPeriods', 'srsiK', 'srsiD', 'oversoldRsi', 'overboughtRsi', 'oversoldCci', 'overboughtCci', 'Constant', 'params']),
srsi_macd: filedsGeneral.concat(['rsiPeriods', 'srsiPeriods', 'srsiK', 'srsiD', 'oversoldRsi', 'overboughtRsi', 'emaShortPeriod', 'emaLongPeriod', 'signalPeriod', 'upTrendThreshold', 'downTrendThreshold', 'params']),
macd: filedsGeneral.concat([ 'emaShortPeriod', 'emaLongPeriod', 'signalPeriod', 'upTrendThreshold', 'downTrendThreshold', 'overboughtRsiPeriods', 'overboughtRsi', 'params']),
rsi: filedsGeneral.concat(['rsiPeriods', 'oversoldRsi', 'overboughtRsi', 'rsiRecover', 'rsiDrop', 'rsiDivsor', 'params']),
Expand All @@ -305,7 +307,7 @@ parallel(tasks, PARALLEL_LIMIT, (err, results) => {
trend_ema: filedsGeneral.concat(['trendEma', 'neutralRate', 'oversoldRsiPeriods', 'oversoldRsi', 'params'])
};
let fieldNames = {
cci_srsi: filedNamesGeneral.concat(['CCI Periods', 'RSI Periods', 'SRSI Periods', 'SRSI K', 'SRSI D', 'Oversold RSI', 'Overbought RSI', 'Oversold CCI', 'Overbought CCI', 'Constant', 'Full Parameters']),
cci_srsi: filedNamesGeneral.concat(['CCI Periods', 'RSI Periods', 'SRSI Periods', 'SRSI K', 'SRSI D', 'Oversold RSI', 'Overbought RSI', 'Oversold CCI', 'Overbought CCI', 'Constant', 'Full Parameters']),
srsi_macd: filedNamesGeneral.concat(['RSI Periods', 'SRSI Periods', 'SRSI K', 'SRSI D', 'Oversold RSI', 'Overbought RSI', 'EMA Short Period', 'EMA Long Period', 'Signal Period', 'Up Trend Threshold', 'Down Trend Threshold', 'Full Parameters']),
macd: filedNamesGeneral.concat(['EMA Short Period', 'EMA Long Period', 'Signal Period', 'Up Trend Threshold', 'Down Trend Threshold', 'Overbought Rsi Periods', 'Overbought Rsi', 'Full Parameters']),
rsi: filedNamesGeneral.concat(['RSI Periods', 'Oversold RSI', 'Overbought RSI', 'RSI Recover', 'RSI Drop', 'RSI Divisor', 'Full Parameters']),
Expand Down
113 changes: 97 additions & 16 deletions scripts/auto_backtester/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/auto_backtester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"json2csv": "^3.7.3",
"round-precision": "^1.0.0",
"run-parallel-limit": "^1.0.3",
"shelljs": "^0.7.8"
"shelljs": "^0.7.8",
"strip-ansi": "^4.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may also want to update package-lock.json in this directory:

rm -rf package-lock.json
npm i
git add . # etc etc

}
}
8 changes: 5 additions & 3 deletions scripts/genetic_backtester/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let json2csv = require('json2csv');
let roundp = require('round-precision');
let fs = require('fs');
let GeneticAlgorithmCtor = require('geneticalgorithm');
let StripAnsi = require('strip-ansi');

let Phenotypes = require('./phenotype.js');

Expand Down Expand Up @@ -98,7 +99,8 @@ let processOutput = output => {
let wlRegexp = /win\/loss: (\d+)\/(\d+)/g;
let errRegexp = /error rate: (.*)%/g;

let output2 = output.substr(output.length - 3500);
let strippedOutput = StripAnsi(output);
let output2 = strippedOutput.substr(strippedOutput.length - 3500);

let rawParams = jsonRegexp.exec(output2)[1];
let params = JSON.parse(rawParams);
Expand Down Expand Up @@ -427,7 +429,7 @@ let simulateGeneration = () => {
console.log(`\n\n=== Simulating generation ${generationCount++} ===\n`);

runUpdate(argv.days, argv.selector);

iterationCount = 1;
let tasks = selectedStrategies.map(v => pools[v]['pool'].population().map(phenotype => {
return cb => {
Expand All @@ -442,7 +444,7 @@ let simulateGeneration = () => {
});

results.sort((a, b) => (a.fitness < b.fitness) ? 1 : ((b.fitness < a.fitness) ? -1 : 0));

let fieldsGeneral = ['fitness', 'vsBuyHold', 'wlRatio', 'frequency', 'strategy', 'order_type', 'endBalance', 'buyHold', 'wins', 'losses', 'period', 'min_periods', 'days', 'params'];
let fieldNamesGeneral = ['Fitness', 'VS Buy Hold (%)', 'Win/Loss Ratio', '# Trades/Day', 'Strategy', 'Order Type', 'Ending Balance ($)', 'Buy Hold ($)', '# Wins', '# Losses', 'Period', 'Min Periods', '# Days', 'Full Parameters'];

Expand Down
31 changes: 27 additions & 4 deletions scripts/genetic_backtester/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/genetic_backtester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"round-precision": "^1.0.0",
"run-parallel-limit": "^1.0.3",
"shelljs": "^0.7.8",
"yargs": "^8.0.2"
"yargs": "^8.0.2",
"strip-ansi": "^4.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may also want to update package-lock.json in this directory:

rm -rf package-lock.json
npm i
git add . # etc etc

}
}