Click here to Login





                                                   Access MAE In AMM Script?

  1

0
Dave W.
2015-01-15 13:40:16


Hi. I'm working through how to accomplish certain things in an AMM script. What I'm trying to do is calculate an Average MAE. To do that, I think I need to:

1. Create an array to hold the MAE of each individual position. Do this on the On Close Position event.
2. Use the array created in the On Close Position event and average the results. Do this on the On End Simulation event.

Is that correct? If so, I think I'm appropriately capturing the MAE in the On Close Position event with this code:

// Get the MAE for each closed position, then add to the global tracking array.
double PositionMae = Functions.GetPositionDetails().MAE;
GlPositionMaeArray.Add( (double)PositionMae);

//Add 1 to the count of closed positions.
GlPositionCount =+ 1;

Is there an easy way to average the results? Any help or suggestions would be appreciated.



QuantShare
2015-01-16 02:12:51

  0

Best Answer
Hi Dave,

You don't need to store MAE on the OnClosePosition event since that information is stored in "MMPosition" .

All you have to do is loop through all positions in the OnEndSimulation event and average the result.

MMPosition[] pos = Portfolio.GetAllPositions();
double avgMAE = 0;
for(int i=0;i < pos.Length;i++)
{
avgMAE += pos[i].MAE;
}
avgMAE = avgMAE / pos.Length;



Dave W.
2015-01-16 08:12:52

  0

Excellent. Greatly appreciate your help.


Dave W.
2015-01-16 08:45:27

  0

Is there a similarly simple solution to calculate Standard Deviation in the on OnEndSimulation event code?

I found the function below that takes an an array as input and calculates the standard deviation PL, but if there is as simpler solution, I'd rather use it.

Suggestions are welcome and appreciated...

private double getStandardDeviation(List<double> doubleList)
{
double average = doubleList.Average();
double sumOfDerivation = 0;
foreach (double value in doubleList)
{
sumOfDerivation += (value) * (value);
}
double sumOfDerivationAverage = sumOfDerivation / (doubleList.Count - 1);
return Math.Sqrt(sumOfDerivationAverage - (average*average));
}



QuantShare
2015-01-17 02:34:29

  0

For each position, you will need to read close price series, get prices starting from the entry date then pass the array to the "getStandardDeviation" function.


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
Minimum Variance Optimization with Solver V1.1- AMM
Sector Surfer AMM Model
MAE and MFE of a Trading System
System Metrics v2.0

How-to Lessons
How to create a real-time watchlist
How to download and use U.S. stocks earnings data
What is the Bookmark Panel?
How to add custom position-based metrics to your trading system
How to get fundamental data for U.S. Stocks

Related Forum Threads
Access Point Value in strategy script?
Equity to Symbol - AMM / Script
System MAE Metric
AMM ATS script
AMM script global variables do not appear to be thread safe

Blog Posts
Introduction to the trading rules analyzer
Backtesting trading strategies using intraday data
Fundamental Screen based on Stock price, ROI and Market capitaliz...
Charting & Scripts - Manage stock charts using the global script
QS Trading Software: Database Optimization









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.