Australian (ASX) Stock Market Forum

Amibroker Monte Carlo Question

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
Hi All,

I am a newbie playing around with Amibroker and running some Monte Carlo Tests, but but my results look nothing like what I have seen other people post. I am using the latest 64bit version 6.10 .

I am not sure if its me doing something wrong or simply a terrible AFL.

For example, if you look at the equity graph posted : https://www.amibroker.com/guide/h_montecarlo.html you will see Green/Red and a number of Grey lines:

mc1.png

When I run a monte carlo I get no grey lines at all see the attached... I am not sure if the issue is with my coding or my monte carlo settings etc....
thanks
JJZ
 

Attachments

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
Ok found it, just incase anyone has the same issue its under

Straw broom chart plots....

ScreenShot002.jpg
 
Joined
Jun 30, 2007
Posts
6,175
Reactions
615
Here you go, let us know what you think. It just looks like squiggly lines to me lol.

This is based on a Backtest of ASX stocks starting with $30K from 2005-2015
Great first effort. Trend is up and worst run is basically break even. You'll be able to improve on that.

How many variables did you optimize? Did you try a walk forward yet?
 

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
Great first effort. Trend is up and worst run is basically break even. You'll be able to improve on that.



How many variables did you optimize? Did you try a walk forward yet?

Thanks :)

Optimize is still running just plucked the best result so far for the backtest, currently optimizing 3 variables.

Just doing a broad scan now, will then focus more on entry/exit/stoploss and an index filter individually.

Then a walk forward and maybe some paper trading, still have a long way to go. But I am learning more everyday ;)


JJZ

ScreenShot004.jpg
 
Joined
Jun 30, 2007
Posts
6,175
Reactions
615
Thanks :)

Optimize is still running just plucked the best result so far for the backtest, currently optimizing 3 variables.

Just doing a broad scan now, will then focus more on entry/exit/stoploss and an index filter individually.

Then a walk forward and maybe some paper trading, still have a long way to go. But I am learning more everyday ;)
In general, index filters seem worthwhile to some degree. I like ones based on ROC(C,40) for the Aus index.

WF analysis can be an eye opener if your optimized parameters are of a certain type. So before you spend too much time on exits and stops, maybe try that. Just a suggestion.
 

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
In general, index filters seem worthwhile to some degree. I like ones based on ROC(C,40) for the Aus index.

WF analysis can be an eye opener if your optimized parameters are of a certain type. So before you spend too much time on exits and stops, maybe try that. Just a suggestion.
Thanks for all your help Gringotts Bank, will move the WF further up my to do list and give ROC() a shot.

JJZ
 

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
In general, index filters seem worthwhile to some degree. I like ones based on ROC(C,40) for the Aus index.

WF analysis can be an eye opener if your optimized parameters are of a certain type. So before you spend too much time on exits and stops, maybe try that. Just a suggestion.
WF analysis was a great help, glad I did it sooner rather than later :xyxthumbs Should help me put together a more robust system in the long term.

I tried playing around with the ROC() function but things went backwards fast for me, searching for ROC doesnt seem to help. Is there an article, afl or thread you can recommend?

Thanks
JJZ
 
Joined
Jun 30, 2007
Posts
6,175
Reactions
615
WF analysis was a great help, glad I did it sooner rather than later :xyxthumbs Should help me put together a more robust system in the long term.

I tried playing around with the ROC() function but things went backwards fast for me, searching for ROC doesnt seem to help. Is there an article, afl or thread you can recommend?

Thanks
JJZ
You can try something like this:

SetForeign("^AORD"); // reference the All Ords ticker
z = ROC(C,40)>-10; //40 day rate of change > -10
RestorePriceArrays();

Buy = z AND.... your Buy conditions.


But also, it might just be that your particular system does better without an index filter.
 
Joined
Mar 28, 2006
Posts
3,300
Reactions
669
Hi JJZ

I may be on the wrong track but for me I look at what is happening at the 25 percentile, in particular the Annual Return and the Drawdown.

I think I read somewhere in (Bandy's books ?) about looking at the 25 percentile, will try to find it.

Rather than using an index filter I use a MACD 47,50,12 as an individual stock filter.

That Drawdown in your post #7 above would concern me (maybe that's just me though).

Note the Drawdown on mine below - click to expand.
 

Attachments

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
Hi JJZ

I may be on the wrong track but for me I look at what is happening at the 25 percentile, in particular the Annual Return and the Drawdown.

I think I read somewhere in (Bandy's books ?) about looking at the 25 percentile, will try to find it.

Rather than using an index filter I use a MACD 47,50,12 as an individual stock filter.

That Drawdown in your post #7 above would concern me (maybe that's just me though).

Note the Drawdown on mine below - click to expand.
Thanks for chiming in Boggo. That drawdown sure looks a lot easier to live. If you can let me know which of Bandy's books your referring to that would be great.

I am still plugging away for a better outcome. It really helps to see what others are producing, posts like yours give newbies benchmarks to strive for.

What equity, max positions, position sizing etc are you using?

I am trying to keep mine conservative, I would imagine that will also have an impact on things like Monte Carlos.

BuyPrice = Open;
SellPrice = Open;
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 30000 );
SetOption( "MaxOpenPositions", 10 );
SetPositionSize( 9, spsPercentOfEquity );
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 29.95 );

Thanks JJZ
 
Joined
Jun 30, 2007
Posts
6,175
Reactions
615
BuyPrice = Open;
SellPrice = Open;
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 30000 );
SetOption( "MaxOpenPositions", 10 );
SetPositionSize( 9, spsPercentOfEquity );
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 29.95 );

Thanks JJZ
I would change some of these.

Looks like your entry signal is given at close. Try to enter on the close of the same day. That's quite possible, and you're more likely to get better fills in real trading at close as opposed to open.

I would use a fixed position size. If your initial equity is 30k, just go with say 5k. How many triggers do you get per day (average)?

Commission amount of 30$ is high. Try $10.
 
Joined
Mar 28, 2006
Posts
3,300
Reactions
669
JJZ, will try to find the reference over the weekend.

I use 20 positions max with 5% on each (but with a larger capital base).
 

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
I would change some of these.

Looks like your entry signal is given at close. Try to enter on the close of the same day. That's quite possible, and you're more likely to get better fills in real trading at close as opposed to open.

I would use a fixed position size. If your initial equity is 30k, just go with say 5k. How many triggers do you get per day (average)?

Commission amount of 30$ is high. Try $10.
If I am trading EOD, putting in my orders the night before isnt this correct?

If I run a scan using the AFL I get about 40 "BUY"'s a day, is that what you mean by triggers?

Your right maxopenpositions is too high, I am yet to learn about the portfolio management side , too many books not enough time!

JJZ
 
Joined
Jun 30, 2007
Posts
6,175
Reactions
615
If I am trading EOD, putting in my orders the night before isnt this correct?

If I run a scan using the AFL I get about 40 "BUY"'s a day, is that what you mean by triggers?

Your right maxopenpositions is too high, I am yet to learn about the portfolio management side , too many books not enough time!

JJZ
Your system buys the next open because of the SetTradeDelays( 1, 1, 1, 1 );. Removing the trade delay may improve performance. Then when it comes to actual implementation, you will have to run an exploration and enter on close. That can be tricky but it's certainly do-able.

If you're getting 40 triggers per day, you need to know how each of those triggers will play out if actually bought. Just increase your initial equity to cover 40*positionsize. If your positionsize = 5k, then 5k*40 = 200k. Then run the backtest again.

If you don't like the curve, try adding more conditions to reduce the number of triggers per day. Or add a positionscore to choose which of the 40 triggers you prefer. Or add positionscore = Random().
 
Joined
Jun 13, 2007
Posts
838
Reactions
107
Greetings --

I see my name mentioned in the postings. There are several sources of information and techniques about risk, trading system development, and Monte Carlo analysis that you might find valuable:

Specific to risk -- Watch a recording of a webinar I presented at the request of the IFTA. The title is "The Four Faces of Risk."
https://www.youtube.com/watch?v=Vw7mseQ_Tmc&feature=youtu.be

That video describes how to:
A. Define your own personal risk tolerance. My risk tolerance statement is:
I am trading a $100,000 account and forecasting two years into the future. I want to hold the risk of a drawdown greater than 20%, measured from highest equity to date, to a chance of 5% or less.
B. Determine the risk associated with any set of trades.
C. Determine the maximum position size (fraction of the account used for each trade) that can be used to take trades without risk exceeding your personal risk tolerance. Call this "risk normalization."
D. Determine how to compare the profit potential of any set of trades. When each of the alternative sets of trades has been risk-normalized, the distributions of the profit potential of each can be compared to choose the best profit for a given level of risk. The metric I use to do this is CAR25 -- the Compound Annual rate of Return at the 25th percentile.

Some background --

When a trading system is in a drawdown, holding through that drawdown expecting the account to recover is an act of faith. What we need is measurable confidence. The techniques I describe are intended to provide measurable confidence and associated management techniques.

In order for the trades to return to profitability, the system must return to identifying the signals that precede profitable trades. The implication is that the signals must still exist and the model that identifies them must still be synchronized to those signals. The condition that defines this relationship is "stationarity." There is another video worth watching entitled "The Importance of Being Stationary":
https://www.youtube.com/watch?v=iBhrZKErJ6A&feature=youtu.be

When in a drawdown, we must each decide what level of loss indicates that the system is broken and should be taken offline. The statement of personal risk tolerance defines that.

One technique for risk avoidance is a binary switch -- ON: trade the system or OFF: take it completely offline.

Another is "dynamic position sizing" which adjusts position size in response to recent performance. When the trades are profitable, the system is healthy, and larger positions (in terms of the fraction of the account used for each trade) can and should be taken. When recent trades are unprofitable, there is no way to know whether this is a minor drawdown or the beginning of a complete failure. By reducing the position size in response to losing trades the trader continues to trade, but at a lower fraction. If the losses continue, the dynamic position sizing technique will set the safe position size -- call it "safe-f" -- to zero, taking the system offline. Note the importance of having position sizing be a component of the trading management system rather than the trading system.

Two of my books describe risk analysis and dynamic position sizing:
"Modeling Trading System Performance" and "Quantitative Technical Analysis"
http://www.blueowlpress.com/123-2
Before buying either, read the free chapters on the webpage of each book. And read the material available on each book's Amazon site using the "look inside" feature.

The other trading system development videos and interviews on my website might also be helpful:
http://www.blueowlpress.com/video-presentations

The Modeling book is independent of platform. It uses any set of trades -- real, paper, out-of-sample, in-sample, or hypothetical. The analysis is done using an add-in for Excel, which is provided free.

The QTA book has a description of the dynamic position sizing technique and implementation of it in Python -- also free and fully disclosed. Again, the data comes as a set of trades and is platform independent.

All of that said, Monte Carlo analysis is used to estimate risk and profit potential. If you are interested in estimating the risk and profit potential of future trades, the set of trades used as input to the MC analysis must be as unbiased an estimate of future performance as possible. In order of preference, this list is:
1. Real trades taken with real money.
2. Paper trades.
3. Out-of-sample results from an unbiased validation of the trading system -- such as a walk forward run.

In-sample trades have no value in estimating future performance. None. The straw broom charts look great, but they have no value. And beware of trades that result from any validation where the system was adjusted as a result of examination of previous validation runs. Multiple validation runs contaminate the "out-of-sampleness" of the results and makes them in-sample.

The Blue Owl Press site is beginning an exchange of questions and discussions related to development of trading systems. If you wish to post a question or make a statement, register as a user (no spam will result) and make a Comment on the page that seems most appropriate.
http://www.blueowlpress.com/trading-system-development

I hope this helps,
Best regards,
Howard
 

JJZ

Joined
Dec 17, 2015
Posts
47
Reactions
0
Thanks everyone for responding, just working through everything. I dont want to be one of those people who expect to be spoofed everything.

I'm making some progress, drawdowns are improving (10-20% better off). ;)

I think my exit strategy is the weak link at the moment, will keep working on it.

Going to also start paper trading on stator, I feel like I am a victim of analysis paralyses at the moment.....

ScreenShot013.jpg
 
Top