Before Quantopian I was into auto-tuning to some degree (eventually will revisit via Zipline I suppose). Picture 20 to 30 variables like thresholds and lookback window values for indicators like sma, macd, whatever. If I had tried to run every possible combination it would have taken years to run all the way thru. So instead used an infinite loop and dictionary something like below. First it would run everything with the base values. Next, pick the first parameter, say, ['sma']['fst'] and change its base by the given increment upward, from 6 to 7 in that case. Do the entire run again. If the output is higher, increment that upward one more time. If lower, try from 6 to 5 downward etc.
I was only deviating from the base two increments up or down. Once a higher run value was obtained the base value would be set so others would be using that better value. At the end of each run in the loop, the result and all variables were saved/printed for the record (later changed to only print when the result was higher). Checking a 24/7 machine and finding the result is up another 2.7% is awesome.
tweaks = {
'sma': {
'fst': {
'base': 6,
'increment': 1,
},
'slw': {
'base': 35,
'increment': 3,
},
},
'rsi': {
'fst': {
'base': 7,
'increment': 1,
},
'slw': {
'base': 82,
'increment': 4,
},
},
'threshold': {
'sell_above_buy': {
'base': 1.29,
'increment': .03,
},
},
}