Skip to content

Commit

Permalink
fix phenotype win loss ratio weighting (DeviaVir#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystophv authored and Heerpa committed Feb 4, 2018
1 parent 6935517 commit dc56423
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/genetic_backtester/phenotype.js
Expand Up @@ -70,9 +70,11 @@ module.exports = {
if (typeof phenotype.sim === 'undefined') return 0

var vsBuyHoldRate = (phenotype.sim.vsBuyHold / 50)
var wlRatio = phenotype.sim.wins - phenotype.sim.losses
// 2.71828 is https://en.wikipedia.org/wiki/E_(mathematical_constant)
var wlRatioRate = 1.0 / (1.0 + Math.pow(2.71828, wlRatio < 0 ? wlRatio:-(wlRatio)))
var wlRatio = phenotype.sim.wins / phenotype.sim.losses
if(isNaN(wlRatio)) { // zero trades will result in 0/0 which is NaN
wlRatio = 1
}
var wlRatioRate = 1.0 / (1.0 + Math.pow(Math.E, -wlRatio))
var rate = vsBuyHoldRate * (wlRatioRate)
return rate
},
Expand Down

0 comments on commit dc56423

Please sign in to comment.