Comments (11)
Ok, I thought long and hard, and this is the most elegant solution I could come up with:
Store a minFitness similar to how we store a maxFitness:
let minFitness = [1000, 0, 0, 0];
else if (populationProfits[i] < minFitness[0])
minFitness = [populationProfits[i], populationSharpes[i], populationScores[i], i];
If we are dealing with negative profits, offset everything based on the lowest profit to ensure all values are > 0, and recalculate fitnessSum:
if (minFitness[0] < 0) {
let offset = 0 - minFitness[0];
fitnessSum = 0;
for (let i = 0; i < this.populationAmt; i++) {
populationProfits[i] += offset;
fitnessSum += populationProfits[i];
}
}
Calculate fitness like this, while summing the weights:
selectionProb[j] = populationProfits[j] / fitnessSum;
sumOfWeights += selectionProb[j];`
When selecting parents to breed, we do this:
let selectedProb = randomExt.float(sumOfWeights, 0);
instead of
let selectedProb = randomExt.float(1, 0);
I also think it's a nice idea to do:
let a=0, b=0;
while (a == b) {
to ensure we aren't breeding a parent with itself.
from gekkoga.
I'm actually not sure about that formula for calculating fitness on a negative profit. Might want to look into that.
from gekkoga.
I am facing the same issue, I tried to update the code with your changes but it seems the selection is still random when profits are minus. Has there been a patch? Something in another branch that solves this?
from gekkoga.
Nice find @kerbe6. It also needs to be fixed so that even negative profit is improved. As it is.. it will infinite loop until it has profit greater than zero, meaning we never get genes to start from. Currently it isnt a big deal with 10 loose settings and a decent strat... but if you have 20+ settings or multiple candles it starts to get a little tougher to get off the ground. There is no patch, the fix is pretty simple. Someone just needs to PR the fix or I can do it next time Im testing a strat though Im kinda backed up and have alot on the backburner.
from gekkoga.
@kerbe6 your adjustments are great suggestions, be aware that now the reported profits are by definition to positive!!! You add an offset to the to make them positive.
from gekkoga.
@kerbe6 I do not understand why you do this:
When selecting parents to breed, we do this:
let selectedProb = randomExt.float(sumOfWeights, 0);
instead of
let selectedProb = randomExt.float(1, 0);
The selectProb is already a proportion, a probability should be between 0 and 1 so why the extra step?
from gekkoga.
my suggestion is to split populationProfit and populationFitness so we can create a custom fitness function regardless of the actual profits a strat makes...
from gekkoga.
could there be (as a first step) a way to keep the best profit even if negative?
If marked is going down and down in a timespan this might be good way to minimize losses...
from gekkoga.
Any news here?
from gekkoga.
I've visited this a couple times without solving it. I just haven't had the time to figure it out and got my hands full at the moment.
from gekkoga.
could there be (as a first step) a way to keep the best profit even if negative?
If marked is going down and down in a timespan this might be good way to minimize losses...
Any news?
from gekkoga.
Related Issues (20)
- Feature request: log all backtests HOT 2
- Error when starting a genetic simulation on actual config (macos)
- Calculation error of yearlyProfit HOT 1
- no "stratName" and "daterange" in result file
- One random number for two parameters HOT 1
- tulindError: needs to be number HOT 1
- update for gekko 0.6 HOT 2
- 500 - "Internal Server Error" HOT 6
- Score as mainObjective HOT 2
- General purpose of this project HOT 1
- Cannot read property 'exchange' of undefined HOT 4
- Parameter units HOT 1
- sharpe: null - global maximums can't get filled HOT 1
- Startprice/Endprice question HOT 1
- Critical security vulnerability during npm install HOT 4
- Questions - Number of Epochs & relaunch of GA session HOT 2
- "Global maximum" not persistent when profits are negative
- always picking up and working through default parameters.. // HOT 3
- Manual backtest results don't match GA results HOT 1
- Your website HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gekkoga.