Click here to Login





                                                   Performance of parsing a QS language function in AMM

  0

0
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 ..."



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Adaptive Asset Allocation Butler V1.3 AMM
Sector Surfer AMM Model
Relative Performance Chart - Dynamic assets and index
Relative Performance against a Group of Stocks
Choose function

How-to Lessons
How to improve the performance of QuantShare databases?
How to plot the relative performance of several stocks/indices
How to draw an horizontal segment line using QS language
How to screen for stocks having a high correlation with the Dow J...
How to create a custom trading indicator

Related Forum Threads
Comp() in QS language and AMM if no Market Data
Problem with performance calculation in custom function
Optimization and fitness function for robustness vs for performan...
AMM scripting - error and some questions
AMM script global variables do not appear to be thread safe

Blog Posts
More about QuantShare Programming Language
Rules performance for different volatility regimes
A vector-based language
QuantShare Programming Language Tutorial
Compare stocks and securities by creating a relative performance ...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.