gekkowarez / gekkoga

Genetic Algorithm for solving optimization of trading strategies using Gekko
313 stars 104 forks source link

Mutate selection always chooses first element to mutate #29

Closed kerbe6 closed 6 years ago

kerbe6 commented 6 years ago

Problem is this line: let position = randomExt.integer(0, a.length);

Should be: let position = randomExt.integer(a.length, 0);

kerbe6 commented 6 years ago

Actually it should be: let position = randomExt.integer(allProps.length - 1, 0);

kerbe6 commented 6 years ago

Also, I'd like to suggest an additional method of mutating a parameter. Instead of selecting a new parameter randomly, it would be nice if one could "jiggle" the existing parameter. Maybe by a user-defined percentage. For example:

maxMutataePercent = 0.1
newParam = oldParam * randomExt.float(maxMutatePercent, -maxMutatePercent)
stereohelix commented 6 years ago

Could you submit a pull request with these changes?

The "jiggle" feature sounds interesting.

generalectric commented 6 years ago

@kerbe6 nice find would you like to PR it? That jiggle idea though... love it! Unfortunately my hands are tied atm so it wont be me that brings it to fruition, but id love to see it eventually.

generalectric commented 6 years ago

Should be: let position = randomExt.integer(a.length, 0);

@kerbe6 i finally had time to take a look. Good eye just one more thing though. Being 'a' is an object not an array, we get the length of the object keys Object.keys(a).length..... again very nice find im gonna go ahead and get the fix pushed.