How can I speed up runBacktest that is part of Financial Toolbox?
Show older comments
I am invoking runBacktest on tickdata and the function takes considerable time (several minutes on about 1 million ticks). Given that the strategy is computed separately and is trivial, it is quite slow.
Here is a sampe code:
load('./price.mat')
%% Create a simple strategy
sma5 = movavg(price,'simple',50);
sma20 = movavg(price,'simple',200);
smaSignal_ = timetable(sma5.Time,...
double(sma5.("price") > sma20.("price")),...
'VariableNames', {'strategy'});
smaSignal = synchronize(price, smaSignal_);
%% Test the strategy
smaRebalanceFcn = @(weights, prices, signal)...
crossoverRebalanceFcn(weights, prices, signal);
smaStrategy = backtestStrategy('SMA',smaRebalanceFcn,...
'TransactionCosts', 0.05,...
'LookbackWindow', 2,...
'InitialWeights', []);
% Create the backtesting engine.
bt = backtestEngine(smaStrategy);
% Run the backtest.
bt = runBacktest(bt, smaSignal(:,1), smaSignal(:,2));
How can I speed it up? Perhpas I can run in on multiple cores? Could RAM be the bottleneck?
2 Comments
Jan
on 6 Mar 2022
Without seeing the code and based on the lean description of what you are doing, the best possible answer is to run it on faster hardware.
If you provide the code and some typical input data, a more explicit suggestion for improving the code is likely. Add the information you get by running the profiler, such that it gets clear, what the bottleneck of the code is.
Artem Lensky
on 7 Mar 2022
Accepted Answer
More Answers (0)
Categories
Find more on Transaction Cost Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!