I have a strategy which goes long/short on certain signals. There are multiple optimization parameters. Total optimization time on my desktop machine is about 50 sec (perfectly acceptable). Now I modify the strategy to trade leveraged ETF pairs (like SSO/SDS), where one is inverse of another, so instead of shorting the primary symbol, I go long with the inverse one. With that change when I run the optimization it takes about 17 min to complete. The only difference is this piece of code:
SetContext(altSymbol, true);
SellAtMarket(bar + 1, p, "");
RestoreContext();
Am I doing something wrong? Is there a way to speed the things up?
Size:
Color:
Correction -- it appears that I don't need to switch context to the secondary symbol when selling (symbol is already stored w/ the Position object). I obviously still need to do context switching when buying, though:
SetContext(altSymbol, true);
BuyAtMarket(bar + 1, "");
RestoreContext();
Now the optimization time is down from 17 min to 11 min on the same data set (130 bars), which is still way too slow.
Size:
Color:
Sounds like there could be other bottlenecks in the code, so start by including a sufficient code snippet, your optimization settings, data loaded, number of symbols:
How to report a Problem?
Size:
Color:
Thank you.
Filed a ticket w/ a code snippet.
Size:
Color:
The performance issue was caused by the "Update Data on Demand" flag being set. Clearing the flag resolved the issue.
Size:
Color:
Thank you for the information. Having found no bottleneck in your code, I was thinking about it as well. For backtesting, it's better keeping data up to date and not enabling the checkbox.
Size:
Color: