Hello,

How do I export the table of Monte Carlo results in Amibroker version 6.3? I can run a Monte Carlo and see the report, but can't get a list of the individual tests.

I have seen the tests exported to Excel so a scatter plot can be drawn, but I cant find a way to populate the Analysis window.

Has V6.3 changed how this is done?

It is possible to return MC values via CBT.

```
function CBT_MCTable( mc ) {
/// Returning Monte Carlo table of Report
/// @link https://forum.amibroker.com/t/monte-carlo-export/13512/2
/// by fxshrat@gmail.com
local i, j, mat, mat_perc, rownum, colnum, perc_val, mc_val;
mat = Matrix(9, 6);
mat_perc = MxFromString("[1;5;10;25;50;75;90;95;99]");
mc_fields = "FinalEquity,CAR,MaxDrawdown,MaxPercDrawdown,LowestEquity";
rownum = MxGetSize( mat, 0 );
colnum = MxGetSize( mat, 1 );
for ( i = 0; i < rownum; i++ ) {
perc_val = mat_perc[i][0];
mat[i][0] = perc_val;
for ( j = 1; j < colnum; j++ ) {
mc_val = mc.GetValue(StrExtract(mc_fields, j-1), perc_val);
mat[i][j] = mc_val;
}
}
return mat;
}
SetOption( "MCEnable", True );
SetOption( "MCRuns", 1000 );
SetPositionSize( 100, spsShares );
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio ) {
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
mc = bo.GetMonteCarloSim();
if ( mc ) {
mat = CBT_MCTable( mc );
_TRACE(MxToString(mat));
StaticVarSet("MC_Table", mat);
}
}
m = MA( Close, 20 );
Buy = Cross( Close, m );
Sell = Cross( m, Close );
Short = Cover = 0;
```

Retrieving MC table elsewhere

```
// Retrieving MC table after backtest ...
MC_table = StaticVarGet("MC_Table");
if ( typeof(MC_table ) == "matrix" ) {
printf( MxToString(MC_table) );
}
```

For further information consult user guide.

**Individual trades** are shown in the "Trades" tab of backtest report. They can be copied and exported as explained here: http://www.amibroker.com/kb/2014/09/18/how-to-print-result-list-from-analysis-window/

The same way "Monte carlo" tab fro the report can be exported.

The Monte Carlo process just uses randomly picks and shuffles those trades thousands of times as explained in the process http://www.amibroker.com/guide/h_montecarlo.html

Thanks for the replies...I am probably not explaining myself very well.

I have seen videos where the analysis returns a list of all the portfolio outcomes performed by monte carlo. I.e it is a list of say 1000 portfolios. This can be exported to Excel for analysis. The rows int he data are the individual portfolio tests in the monte carlo analysis.

see...http://www.asxmarketwatch.com/2015/11/amibroker-q-a-visualising-monte-carlo-data-with-histograms-and-scatter-plots/

About the 1 minute mark in the video...

You may ask the author of the video, but quite obviously these results were not produced using Monte Carlo option but using optimization (slower) to randomly pick trades on different symbols - the result table is just the output from optimizer.

He uses just random score to randomize stock selection: https://www.youtube.com/watch?v=lIXtTV3Rau4

This is obviously **NOT the same as Monte Carlo** built-in AmiBroker. It is random selection of symbols, not Monte Carlo bootstrap process. He also uses old version of AmiBroker (and old Automatic Analysis).

The randomization of stock selection using PositionScore is described **at the very end of this page** (in *"How about Monte Carlo randomization instead of bootstrap test?"* paragraph): http://www.amibroker.com/guide/h_montecarlo.html

Built-in Monte Carlo is orders of magnitude faster (something like 100x faster) because it produces only subset of all stats (basically only equity and drawdowns derived from that equity). It also is different than random stock selection that author of video that you mentioned used.

Built-in Monte Carlo has all charts automatically generated in a super tiny fraction of time required normally to produce the same in Excel.

Thanks, I understand....FYI he uses this code in the editor..

PS = Optimize("Tests", 1,1,1000,1);

PositionScore = Random() * PS;

I tried it and each instance in the Analysis is identical...so not useful at all. Does not seem to randomise...maybe my system code is the problem.

Anyway thanks for the feedback...I will use monte carlo in the latest version...

It works, but only if:

- you are running portfolio backtest on LARGE number of stocks
- you don't use PositionScore in your formula for your own ranking

**You are probably using single-symbol backtest.**

Correct...I commented out the PositionScore line and the optimisation is now working....thanks a million

Hi

I am new to Amibroker and found this thread very useful. I am trying to do the monte Carlo testing for a single symbol as well to see how the risk to reward is distributed on a scatter plot.

I am getting the same result for each iteration. From @Tomasz answer, I gather it is not possible to pick randomly selected trade within a single-symbol.

@stevecar144 - do you mind telling me how you fixed the issue, please?

Very much appreciated.