|
Dave Walton
2014-10-24 18:42:48
|
|
Hi QS,
I'm trying to port a trading system from QS script to entirely within AMM so I can control every detail the way I want it. I get identical results when doing this, but I've noticed that the AMM version performance is poor in comparison.
Through trial and error, I've found that the source of the performance seems to be parsing a specific QS language function that uses TimeframeDecompress(TimeframeApply()).
Any idea why the performance of this command in AMM is 2x slower than within the QS script editor? Would it have something to do with differences in what is kept in memory?
More importantly, is there anything I can do to help this?
|
|
|
|
QuantShare
2014-10-25 04:08:33
0
|
|
Hi Dave,
Yes, it could be because some internal optimizations are not triggered when parsing formula from AMM scripts. There are many reasons that could explain this.
Can I have a look at part of the code? or if you want you can send that by email.
|
|
|
|
Dave Walton
2014-10-25 09:22:03
0
|
|
Hi QS,
here is the code snippet that results in lower performance within OnEndPeriod:
MMParser RuleParser = Data.ParseFormula("ProfitTarget = TimeframeDecompress(TimeframeApply(7, ATR(14)));");
TimeSeries ProfitTargetRule;
ProfitTargetRule = RuleParser .GetTimeSeries(Gl_SymbolRankList[i].SymbolName, "ProfitTarget");
if (RuleParser.IsErrors) throw new InvalidOperationException("\r
Fatal Error: Profit Target Rule parsing error!\r
");
// do NOT enter a negative number here unless you know what you are doing. This creates lookahead bias.
ProfitTargetRuleDouble = ProfitTargetRule[0];
if (double.IsNaN(ProfitTargetRuleDouble))
{
ProfitTargetRuleDouble = 0;
Gl_NumberErrors++;
if (SimOpt_LogErrors) Gl_ErrorString += Gl_SymbolRankList[i].SymbolName + "Profit Target Rule is NaN; changed to zero to continue.\r
";
}
If I leave the above out, performance is about the same as in QS script. This is only the section of my code for the profit target. There are entry/exit rules that are also parsed that do not result in lower performance. Thoughts on how I can fix this?
|
|
|
|
QuantShare
2014-10-25 11:35:32
0
|
|
Try putting "Data.ParseFormula" outside the loop.
|
|
|
|
Dave Walton
2014-10-25 13:17:36
0
|
|
I have to do it in a loop because I need to run the code for each symbol that has an entry signal.
But are you saying that if I put "Data.ParseFormula" outside the loop that the time series will be kept in memory and is not in the way I am currently doing it?
|
|
|
|
QuantShare
2014-10-27 02:37:44
0
|
|
It is more complicated than that. Optimization are not triggered in many situations. But you can try putting "Data.ParseFormula" outside the loop (The code is just parsed here, not executed) and keep "GetTimeSeries" inside the loop. Let me know how it goes.
|
|
|
|
Dave Walton
2014-10-29 01:42:46
0
|
|
Hi QS,
I tried many things. Ultimately what works for performance is to declare a "MMParser" global variable and then only call "Data.ParseFormula" for the first bar. Do you see any issues doing this? it seems to work fine.
|
|
|
|
QuantShare
2014-10-29 02:31:37
0
|
|
Best Answer
Not at all. This will probably consume more memory but will prevent QS from parsing the formula on each new bar and most importantly will cache the data.
|
|
|
|
Dave Walton
2014-10-29 11:09:21
0
|
|
Thanks QS! This is helpful.
One last question...
Can I always count on "Data.GetPriceSeries" being cached in memory?
|
|
|
|
QuantShare
2014-10-30 01:54:50
0
|
|
Yes, that function would always cache data if the following option is enabled:
"Accounts -> Application Settings -> Memory Management -> Load quotes in memory ..."
|
|
|
|