Optimization for multi-symbol strategies is slow
Author: avishn
Creation Date: 10/12/2009 10:57 AM
profile picture

avishn

#1
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?
profile picture

avishn

#2
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.


profile picture

Eugene

#3
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?
profile picture

avishn

#4
Thank you.
Filed a ticket w/ a code snippet.
profile picture

avishn

#5
The performance issue was caused by the "Update Data on Demand" flag being set. Clearing the flag resolved the issue.
profile picture

Eugene

#6
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.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).