# [math] algorithm to establish value of parameter giving max value of equation Classic List Threaded 8 messages Open this post in threaded view
|

## [math] algorithm to establish value of parameter giving max value of equation

 Please excuse my ignorance to begin with, it's been years since my last mathematics or statistics class in school. I looked through the user guide on commons.apache.org but I was struggling with the terminology, and had a hard time figuring out whether I could find what I'm looking for. Also apologies if this is the wrong list - I'm following the advice on the commons-math proposal page which said to post here. I have two equations: HPR = (( profit_loss / biggest_loss ) * f ) + 1 where HPR = 'holding period return' (percent gain) profit_loss = dollar win (or loss if negative) biggest_loss = worst loss (given beforehand) and f = 'fixed fraction' (to optimize) TWR = product of all HPRs for a series of profits and losses from a financial trading or gambling system for value of f Solving this by "brute force", I would find the value of 'f' by incrementing up from 0.01 in steps of perhaps 0.01 and solving TWR for each value until TWR peaks. Fortunately it will always peak before f reaches 1.0. Would it be possible to use part of commons-math to do this rather than writing loops within loops to iterate the profits and losses and then the f-values? Best regards Adam --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]
Open this post in threaded view
|

## Re: [math] algorithm to establish value of parameter giving max value of equation

Open this post in threaded view
|

## Re: [math] algorithm to establish value of parameter giving max value of equation

Open this post in threaded view
|

## Re: [math] algorithm to establish value of parameter giving max value of equation

Open this post in threaded view
|

## Re: [math] algorithm to establish value of parameter giving max value of equation

Open this post in threaded view
|

## Re: [math] algorithm to establish value of parameter giving max value of equation

 [hidden email] on 29/05/08 10:24, wrote: > In the previous message, I called twr what was really twrPrime, and I used a too slow method to compute it with a double loop. Here is a much simpler and faster way to compute this derivative: > > public class TwrDerivative implements UnivariateRealFunction { > >   private final double[] a; > >   public TwrDerivative(double[] pl, double[] b) { >     a = new double[pl.length]; >     for (int i = 0; i < a.length; ++i) { >       a[i] = pl[i] / b[i]; >     } >   } > >   public double value(double f) { >     double twr      = 1; >     double twrPrime = 0; >     for (int i = 0; i < a.length; ++i) { >       double factor = 1 + a[i] * f; >       twrPrime = twrPrime * factor + twr * a[i]; >       twr     *= factor; >     } >     return twrPrime; >   } > > } OK, great, I'll replace that. I'm just coding it now. The iteration count for the solver is 7, which is great considering it would have been 22 by the brute force algorithm, and potentially 100 with other data. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]