Coder Social home page Coder Social logo

Comments (11)

kerbe6 avatar kerbe6 commented on June 9, 2024 1

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.

kerbe6 avatar kerbe6 commented on June 9, 2024

I'm actually not sure about that formula for calculating fitness on a negative profit. Might want to look into that.

from gekkoga.

illion20 avatar illion20 commented on June 9, 2024

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.

generalectric avatar generalectric commented on June 9, 2024

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.

hugokoopmans avatar hugokoopmans commented on June 9, 2024

@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.

hugokoopmans avatar hugokoopmans commented on June 9, 2024

@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.

hugokoopmans avatar hugokoopmans commented on June 9, 2024

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.

mboremski avatar mboremski commented on June 9, 2024

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.

mboremski avatar mboremski commented on June 9, 2024

Any news here?

from gekkoga.

generalectric avatar generalectric commented on June 9, 2024

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.

mboremski avatar mboremski commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.