Australian (ASX) Stock Market Forum

AmiBroker to TradeSim & Monte Carlo testing

Monte Carlo is a pretty basic process being easier than actual backtesting. It's some math learned by kids in elementary school applied on data after backtest is done (shuffling trades generated by backtest).

Simple custom Monte Carlo AFL in AmiBroker http://i.imgur.com/EGbQfMo.gif

Thanks Trash,

Unfortunately the link would not work for me.

I have looked at the Library at the AFL functions. It does not appear to be SetCustomBacktestProc. Could you advise what AFL function it would be use Monte Carlo in Amibroker?

With thanks,

Regards,

Tradezy
 
Hi Howard,
Bearing in mind I still have wet feet, I believe Amibroker is limited in regards to:
- No Monte Carlo testing, unless there is a random function/ code that I have not understood yet. This would be helpful in regards to profit, draw down, position size analysis.
- Optimization slowness (I can live with this)
- Unable to pyramid in with "Applystop" stop loss (maybe I need to use Looping - I am not there yet)

Hi Tradezy --

I am of the very strong opinion that the model -- logic, rules, and parameters -- has no purpose other than identifying patterns in the data series that precede profitable trades and issuing Buy and Sell orders. Position sizing, even compounding, in the model causes several problems.
1. It introduces a bias that rewards trade sequences that got lucky during testing. The development process should not take advantage of any sequence dependent information.
2. It is impossible to determine what the correct position size is from within the model. To begin with, each person has a level of risk tolerance. Position size is not stationary, but must be evaluated continuously and managed with respect to the trader's risk tolerance.
3. During development, the model is rules and parameters and the data it processes is OHLCV. During trading, trade management requires another -- different -- model. Its data is trades. Even if position sizing could be done in the trading model, that removes the only knob available for trading management.

Monte Carlo methods can be used in several different ways. Be aware of the purpose of each, where in the development process it is appropriate to use. Within the model, Monte Carlo methods can be used to test robustness of parameters. At least those that are like continuous variables. But it has no place in trade selection. And trade reordering is part of risk assessment which must be done external to the model.

I recommend developing one system. One model that trades one issue long and flat. Get that one working and completely through validation before beginning another.

If optimization seems slow, use non-exhaustive search. I recommend cmae.

I recommend not pyramiding. Entering a second position is a separate system that should be evaluated on its own.

This is hard enough as it is. Trying to do everything you have listed will make it impossible. All in my opinion, of course.

I have some material that can be downloaded free.
If you are interested, read the Introduction Chapter to my forthcoming book:
http://www.quantitativetechnicalanalysis.com/book.html
And the Analysis Chapter of this very popular book:
http://www.meanreversiontradingsystems.com/book.html
And a list of videos and presentations:
http://www.blueowlpress.com/WordPress/grid/

Best regards,
Howard
 
Thanks Trash,

Unfortunately the link would not work for me.

I don't understand. The link shows a video.

As for Monte Carlo ... basically it is just shuffling through your trades. There is no rocket science about it contrary to what is made out to be by whoever trade simulation vendor. You may look at the AB forum.
 
Bearing in mind I still have wet feet, I believe Amibroker is limited in regards to:
- No Monte Carlo testing, unless there is a random function/ code that I have not understood yet. This would be helpful in regards to profit, draw down, position size analysis.
- Optimization slowness (I can live with this)
- Unable to pyramid in with "Applystop" stop loss (maybe I need to use Looping - I am not there yet)

1. As for Monte Carlo .. you can code Monte Carlo in Amibroker. It is a very basic process.
2. Optimization isn't slow. Slow compared to what? A comprehensive optimization is slower than a less comprehensive optimization. Or comparing to outer space ... it takes approximately 90 minutes for the space shuttle to go around the Earth one time. So if you have an optimization process taking more than 90 minutes then the space shuttle will be faster obviously. Fill in any other comparison.
3. Unable to pyramid? See here https://www.amibroker.com/guide/h_pyramid.html
 
If you don't wanna code monte carlo in AmiBroker then there is a free tool available doing Monte Carlo. It is called Equity Monaco by Tickquest. http://www.tickquest.com/?page_id=70

Here is a code exporting P/L to file being imported by Equity Monaco.

Code:
// set output folder of file
folder = "C:\\EquityMonaco\\";
filename = "AB_ProfitLossData_" + StrFormat( "%6.0f_%6.0f", Now( 3 ) + 19000000, Now( 4 ) ) + ".txt";
destination = folder + filename;

// custom backtest procedure
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
    //Creates export folder
    fmkdir( folder );

    bo = GetBacktesterObject();
    bo.Backtest();  
    
    fh = fopen( destination, "w" );  
    for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
    { // iterate through closed trades
        getprofit = trade.GetProfit();
        StrFmt = StrFormat( "%g\n", getprofit );
        fputs( StrFmt, fh );
    } 
    fclose( fh );
}
 
If you don't wanna code monte carlo in AmiBroker then there is a free tool available doing Monte Carlo. It is called Equity Monaco by Tickquest. http://www.tickquest.com/?page_id=70

Hi Trash --

Right!

Equity Monaco does trade reordering as part of assessment of risk and profit. That must be done outside the model.

For another, similar, excellent but not free, analysis program, look at Market System Analyzer.
http://www.adaptrade.com/MSA/
While you are at that site, read everything Michael Bryant has written.

For still another, particularly if you want to expand the analysis beyond what either Equity Monaco or Market System Analyzer can do, read my "Modeling" book and use the free Monte Carlo addin for Excel.
http://www.modelingtradingsystemperformance.com/

The discussion in this thread is based on development using a tradition trading system development platform (TSDP), such as AmiBroker. TSDPs are very good at working with indicator-based and impulse-based trading systems. Compute an indicator, then see what happens after. Their strong suit is the built-in capabilities for indicator calculation and native functions for handling trades.

Compare to pattern recognition based trading system development done in a general purpose language, such as Python, change to machine learning and state-based signals, and everything discussed can be coded into a single program. I demonstrated that in a presentation I made in Melbourne May 2014, and describe it in detail in my forthcoming book. In my opinion, this is the future direction of trading system development. The big traders are already there. And every trade we small guys make is in competition with the big ones. Listen to my interview with Australian TV. See the links in my previous post.

Best regards,
Howard
 
Hi Howard & Trash,

Thanks for all of your feedback and information.... I will be trying all the links and looking at the information provided .... Great information!

With thanks,

Tradezy
 
Hi Folks,

This thread is very inactive, so I am not sure if there are any Trade Sim, Monte Carlo experts still following this forum?

The question I have is as follows:

When you do a normal portfolio simulation, with random selections, you get a comprehensive Trade Loq, with very detailed information, which allows you to very closely follow the path of trades and scrutinise the results.

When you run a Monte Carlo simulation, you get a Simulation Log with the results of all the simulations in tabular format. Naturally there are some very good results, compared to very average results. My direct question is, is there a way of reviewing specific simulations, to enable you to see the composition and sequence of trades, which were used in selective simulations, which produced the more profitable results reported in the Simulation Log?

Thanks in advance for any help.

Cheers
Bruce
 
Hi Bruce

Only those details required to complete the MC report are recorded during the MC simulation (sim).

Having run an MC sim and you would like to see a single run sim with results near the higher end of the profit range, then choose the Random Walk button and run some single sims whilst watching the Total Capital line (just over half way down the sim progress window) until you see an acceptable value for the Total Capital based on the MC sim report.
Yes, your correct, the info moves very fast however if you concentrate on that area only you shouldn't have to wait too long.

Cheers
rnr
 
Hi rnr,

Thank-you for presenting your thoughts.

Surely, there has to be an easier way of capturing the "top-end" of the profit results? I just cannot figure out how?

Cheers
Bruce
 
Top