Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Finding the optimal value of a parameter or set of parameters

I want to find the optimal trailing stop percent on a stock or set of stocks from a given date. For example, a backtest of Pandora stock (P) starting on April 2nd 2014: If I were to buy Pandora stock on on April 2nd, what is the optimal trailing stop? I would want to test trailing stops of (1, 2, 3, 4, 5, 6, 7, 8, etc). Is there any easy way to loop through different parameters in Quantopian and arrive at the optimal value(s) for a parameter or set of parameters?

Although trailing stop is the subject here, the question can be extended to include crossovers, momentum measures, etc. For example, what is the optimal short/long crossover pair to indicate a buy signal ((10day, 20day), (10day, 30day), (50day, 200day), etc)

Thanks,
Mike

2 responses

I think you have a bigger issue than speed to consider. Trialing parameters like this requires extensive back testing to be rigorous. I dont know how much you are into statistics, but model over fitting is a big issse with optimization of fundamental parameters like these.
Statistically, there will always be a best for any given data set, but that doesn't mean it is the best parameter to use. Its not an issue finding parameters that work well during crazy bull markets, but those same ones may also expose you to massive downsides outside of this market type. Anything lime this really should be tested on multiple time periods of different lengths.

While you probably could write something to track the performance of different parameters, you are probably best doing them manually. If you cant see it, you cant understand it normally. You need to see more than return above the benchmark, you need to see how it evolved, what exposure you had to downturns etc etc. Lets not forget the results of a back test have a real recency bias. If it ends above the benchmark, its so temptjng to see it as a good result, even if it underperformed for the majority of the period. The very last result is no more important than the second one, and a strategy that leaves you watching a declining performance over several years will probably not be successful as you will most likely loose your nerve watching it evolve in realtime, with no guarantee of a strong improvement to get those 20% extra gains.

Hey Chris, great points. I like how you brought up the point about overfitting - that certainly seems like it would be an issue in finding the optimal value for such parameters