General Topics
Technical Topics
Brokerage Firms
Community Lounge
Site Support

# Acrary's monte carlo program

Discussion in 'Strategy Development' started by codemnky, Dec 12, 2008.

1. ### codemnky

I'd like to write my own monte carlo program that works like Acrary's where you can input a different mean and standard deviations for both winning and losing trades. The problem is I don't know how to randomly generate all positive or all negative trades and still maintain the same mean and standard deviation. Mean and standard deviation will change if you try to do this with a normal distribution curve and limit your samples to all positive for winning trades or all negative for losing trades.

Anyone know how he did this?

Here is a link to his post the shows off his program. Excellent read by the way.

2. ### codemnky

I found that a lognormal distribution works pretty well. In excel you just take the exponent of the output from NORMINV:

This will generate all positive returns, which you can use to simulate a distribution of positive winning returns or negative losing returns, similar to what Acrary does in in his MC program.

The tricky part is figuring out what to put in for mean and standard deviation, in order to get the mean and standard deviation you want out. The formula is this:

Where DM = Desired Mean, and DS = Desired Standard Deviation.

The results I got were close to Acuary's in all cases except for 1 case when standard deviation was twice as big as the average. He posted an example where (in theory) he let winners run and cut short losses. The winning standard deviation was twice the winning average in his example, and the results I got were vastly different from his. His program reported improved results with a increased standard deviation for winning trades, that was twice the average win amount. My program showed you would do worse, as it lowered the over all average win amount because winning trades were dispersed more on both sides of the average. At any rate if you let winners run, I would think you would increase both the winning average amount along with the standard deviation, and not Std dev. alone.

File size:
197.5 KB
Views:
293
3. ### happytime

I also want to know how to do it

5. ### acrary

The formula I used for including std dev was sample = mean + (z* std dev) where z is the z score randomized and randomly positive or negative. Hope this helps, Alan

6. ### Random.Capital

Assuming a distribution for which something like "standard deviation" even makes sense is going to eliminate most of the benefit of doing Monte Carlo.

7. ### Indrionas

The confusion is probably due to winning trades becoming negative and losing trades becoming positive. If you have average winning trade of 100 with stdev of 200, then you will get negative values too when generating trades for monte carlo.

The question of thread starter was probably this:
What to do with negative values? If you generate winning trades with above example, then, for instance, with a z-score of -1 you get 100 + (-1 * 200) = -100 - winning trade no more. If you include these, then it affects percentage of winning trades. So if you discard these negative values, the overall mean and stdev of generated trades change and the distribution of trades become non-normal.

8. ### bozwood

not sure if this is correct but possibly get the mean and SD for winning trades and the same for losing trades then generate lognormal random trades for both and combine.

9. ### codemnky

Then you must limit your range of z values for winning/losing trades? Otherwise you can get a negative return when trying to pick a winning trade. (If z is -1 and std dev is greater than the mean, for example).

I spent quite a bit of time reproducing the result from your factor's in consistency thread, and learned a lot by doing so. One subtle thing I found is that profit factor (total profits/ total losses ) Has win percentage built in to it.

(# Wins / #Losses) * (Avg Win / Avg Loss). You called this "expected profit factor." At first I rejected this in my mind because wins/losses cancels out, and you just end up with total profits/ total losses.

It took me a while to realize that there is more information in the formula as you posted it. (Wins/Losses) is a more important factor if you have a small # of trades in a series and you are trying to achieve consistency. Wins/Losses becomes less important, and AW/AL takes over as you get more and more trades in a series.

An interesting thing to try is to graph a 3D plot in excel with (Total Wins/Total Loss) on X axis, (AW/AL) on the Z axis, and a win percentage value on the Y axis for say 30 trades in a series.

ET IS FREE BECAUSE OF THE FINANCIAL SUPPORT FROM THESE COMPANIES: