From fb8526b8973fdc55960151d809e695f2a362f0f4 Mon Sep 17 00:00:00 2001 From: Rick Tonoli Date: Fri, 5 Jan 2018 01:06:13 +1300 Subject: [PATCH] Fix bug where fitness function assigned higher fitness to worse results. (#1043) The fitness calculation does not appear to work correctly when win < loss AND buyvsHold value is negative. It results in a higher fitness value being assigned to worse results. In generation runs where ONLY negative results are returned, each subsequent generation gets progressively worse, not better. To test this I ran trend_ema, 60 days on cexio.ETH_USD and the results now assign the best fitness to the best result correctly, where it was incorrect before. --- scripts/genetic_backtester/phenotype.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/genetic_backtester/phenotype.js b/scripts/genetic_backtester/phenotype.js index 54ac1beac2..e55c6ca54e 100644 --- a/scripts/genetic_backtester/phenotype.js +++ b/scripts/genetic_backtester/phenotype.js @@ -68,7 +68,8 @@ module.exports = { if (typeof phenotype.sim === 'undefined') return 0; var vsBuyHoldRate = (phenotype.sim.vsBuyHold / 50); - var wlRatioRate = 1.0 / (1.0 + Math.pow(2.71828, -(phenotype.sim.wins - phenotype.sim.losses))); + var wlRatio = phenotype.sim.wins - phenotype.sim.losses + var wlRatioRate = 1.0 / (1.0 + Math.pow(2.71828, wlRatio < 0 ? wlRatio:-(wlRatio))); var rate = vsBuyHoldRate * (wlRatioRate); return rate; },