Forex Factory (https://www.forexfactory.com/)
-   Trading Discussion (https://www.forexfactory.com/forum/11-trading-discussion)
-   -   Random walk and Pascals triangle (https://www.forexfactory.com/thread/248249-random-walk-and-pascals-triangle)

Scotty2Cues Jul 31, 2010 7:46am | Post# 1

Random walk and Pascals triangle
 
Hi,

Im trying to do a bit of theory using a 1 dimensional random walk. Im trying to count the number of paths on Pascals triangle to a node, if I eliminate some of the paths (stop loss). I know without restrictions its n!/(n-r)!r! but I cant workout the formula with resrictions on the number of paths. Im basically trying to work out the probability of getting to a node...
any ideas appreciated

thanks

Craig Jul 31, 2010 3:28pm | Post# 2

http://mathworld.wolfram.com/RandomW...mensional.html

Scotty2Cues Aug 1, 2010 2:52am | Post# 3

thanks. (love wolfram)

Think I need a modification though. Looking for proability of getting to a specifice node (or two) to simulate stop loss and take profit. So I can only visit that node once (provided the other has not been visited) and I cant travel past the nodes (enpoints/boundaries)

I was going to find the probability of reaching it in exactly N steps, N+1 steps, N+2 steps...... and then sum the probabilities using infinite series. I assign a probability to either direction. So Im really looking for the number of ways of getting to a node in exactly N steps with the restriction that I can only visit that node on the last step. I can do it using Pasacals triangle using a simple method but havent been able to get a formula....

medici Aug 1, 2010 4:37am | Post# 4

Hi Scotty,

maybe I can help, but I am not sure what you are actually trying to achieve. Are you trying to calculate probabilities of hitting SL/TP levels or is it something else? If the answer is yes, then counting paths in Pascal's triangle might not be the most efficient method.

Scotty2Cues Aug 1, 2010 6:35am | Post# 5

Hi Scotty,

maybe I can help, but I am not sure what you are actually trying to achieve. Are you trying to calculate probabilities of hitting SL/TP levels or is it something else? If the answer is yes, then counting paths in Pascal's triangle might not be the most efficient method.

Hi,
Yes trying to calculate probabilities of hitting SL/TP. I was looking at a 1 dimensional lattice with the end points being the SL/TP given the probabilities for 'left' and 'right'

Scotty2Cues Aug 1, 2010 6:37am | Post# 6

and then use those probabilities to work out EV calculations.....

Adding the restriction that the end points can be touched only once is making it extremely difficult (for me anyway)

medici Aug 1, 2010 3:15pm | Post# 7

Yes, it's a bit tricky. In the academic literature this problem goes under the names of The Classical Ruin Problem and Random Walk With Absorbing Barriers.

The two standard methods of solving it are by homogeneous difference equations and moment-generating functions.

You can find a complete treatment of the problem in William Feller's An Introduction to Probability Theory and its Applications, 3rd Edition, pp. 344.

If p = probability of 'right' and q = 1- p, then the probability of being stopped out (if starting at i and the SL is a and TP is b) is

1 - (i - a)/(b - a) if p = 0.5

[e^(tb) - e^(ti)]/[e^(tb) - e^(ta)] if p <> 0.5

where t = ln(q/p)

Hope that helps.

Scotty2Cues Aug 2, 2010 4:19am | Post# 8

Yes, it's a bit tricky. In the academic literature this problem goes under the names of The Classical Ruin Problem and Random Walk With Absorbing Barriers.

The two standard methods of solving it is by homogeneous difference equations and moment-generating functions.

You can find a complete treatment of the problem in William Feller's An Introduction to Probability Theory and its Applications, 3rd Edition, pp. 344.

If p = probability of 'right' and q = 1- p, then the probability of being stopped out (if starting...
Thank you!

I will take a look (been a few years since I hit the books) aalthought was thinking about buying Fellers book a couple of days ago. Downloaded Grinstead and Snell's Intro to probability last week and it has moment-generating functions. Never heard of m-gfs them before (generating functions I have).

Would Wiener processes be the next area to look at?

Can I ask if you're professional in this area or is it from education?

Thanks again.

medici Aug 2, 2010 4:42am | Post# 9

Thank you!
You're welcome.

I will take a look (been a few years since I hit the books) aalthought was thinking about buying Fellers book a couple of days ago. Downloaded Grinstead and Snell's Intro to probability last week and it has moment-generating functions. Never heard of m-gfs them before (generating functions I have).
Grinstead and Snell solve the Ruin Problem too. See pp. 486. Feller's book can be heavy going, in spite of being called "Introduction". Just so you know.

Would Wiener processes be the next area to look at?
Depends entirely on your motivation. For intellectual amusement? Then, yes of course. For trading? Then, maybe not.

Can I ask if you're professional in this area or is it from education?
Depends on what you mean by "professional" and "this area". I've got the degrees and I've been paid to do research in both maths and finance, even though I now specialise in staring at screens.

Craig Aug 2, 2010 5:23am | Post# 10

I don't know if this is of any help, but this is the sort of thing which would be easy to do Monte-Carlo simulations on, this will not give you a closed form answer however.

sqrt(-1) Aug 3, 2010 6:27pm | Post# 11

My view of this conundrum is from graph theory, so please intervene if what I say doesn't relate to what you may be getting at.


Assuming "randomness", the probabilities of a position hitting a SL or TP should be exactly the same barring they are exactly k steps from the entry. However, because there would be no reason to even consider this trading method otherwise, there must be some prior knowledge you're basing this on.

So you plan to integrate historical data to generate previous probabilities of walks given a vertex in a path has been hit?

Compiling data for when price n (-/+) is hit, for n equal to the number of pips deviated from the entry may be hard because of the infinite amount of data. However, focusing more vaguely on certain entry levels and let's say n=+/-25x when x is a positive integer over a certain pair over a period of 5 years or so may be very achievable.

@SL@-----@price -25@-----@entry@-----@price +25 @-----@TP@

Is this anyone near what you're trying to do?

ForexQuant Aug 3, 2010 11:11pm | Post# 12

1 Attachment(s)
With fixed TP and SL and assuming random walk, the winning probability is easy to calculate by using pascal triangle. The real challenge is trailing stop if it is taking into consideration.

Here is my excel sheet. Have a look!

Btw if anyone have an idea how to calculate the probability by taking trailing stop into consideration then pls let me.
Random walk and Pascals triangle.xls

sqrt(-1) Aug 3, 2010 11:55pm | Post# 13

ForexQuant, extend your 'triangle' to include probabilities of -2R through to -6R, both sides should have the same probabilities.

Let's say that you enter a position at 1.000.

Think of the Excel cells with given probabilities as vertices and the edges which connect them complete the path in which your position may take. You now should have an idea of probability that your position will land on a certain vertex (+/- #R) and all of the possible paths it may take to reach that point.

To include a trailing stop you should focus on how much you want to dump when the price hits a certain vertex and at which step. If you think about it, when the position reaches that point, it realistically should restart the process all over and from there a new 'triangle' (and hence graph) should begin. Why? Because if you disregard the spread, it is basically like closing the position and opening a new one of smaller size. From that point the open position (now smaller in size and negative in value) has the same probability to move to any vertex away from it as if you were to enter a position where you were stopped out.

For this open position to move back to a positive value, it now has a farther way to go if we consider where it was actually opened at 1.000, and thus the probability is diminished.

What does this mean? If you use a trailing TP with equal preference to the SL, as n trades approach infinity, it should run against you as much as it runs with you, and should hit both you TP and SL equally.

And if you don't use a trailing TP, you'll close less positive positions, yet they will be valued more when you do close them, just enough to offset the cost of your trailing stops.

So, although it may appear that trailing stops would produce larger gains...it's because there are so few that it wouldn't matter. No profits and no loss (except spread) because random walks, after all, are random.

ForexQuant Aug 4, 2010 12:33am | Post# 14

1 Attachment(s)
ForexQuant, extend your 'triangle' to include probabilities of -2R through to -6R, both sides should have the same probabilities.
I'm not sure whether I understand this. Did you mean the P(win) not equal to P(loss) when you extend the SL to -6R?

Thank you for your trailing stop idea. The new 'triangle' is a smart idea and i think that should work! I'll try to figure out the detail when i got time.
Click to Enlarge

Name: wrong calculation.PNG
Size: 4 KB

Scotty2Cues Aug 4, 2010 2:55am | Post# 15

I don't know if this is of any help, but this is the sort of thing which would be easy to do Monte-Carlo simulations on, this will not give you a closed form answer however.
thanks, Ill take a look. Im not bothered wheteher its a closed form answer or not.

Scotty2Cues Aug 4, 2010 3:06am | Post# 16

My view of this conundrum is from graph theory, so please intervene if what I say doesn't relate to what you may be getting at.


Assuming "randomness", the probabilities of a position hitting a SL or TP should be exactly the same barring they are exactly k steps from the entry. However, because there would be no reason to even consider this trading method otherwise, there must be some prior knowledge you're basing this on.

So you plan to integrate historical data to generate previous probabilities of walks given a vertex in a path has been...
I am not basing the probabilities of a step to the 'left' or 'right' on historical data. Im making an assumption that if I get a signal to sell, eg because of a pinbar at a swing high, then Im assuming the probability of a step right is greater than a step left.

I wanted to do EV calculations so EV = -risk*P(stopped out) + reward*P(take profit) and wanted to see how SL and TP affected the EV calculations. I then wanted to see if/how including a move of the SL to breakeven affected the EV calculation. If I had the formula (thanks Medici) I can write an array formula with a range of probabilities, SLs and TP.

The problem is assuming each step to the right has the same probability but Im only using it over a relatively small number of steps.

Started out as a curiosity......

ForexQuant Aug 4, 2010 12:08pm | Post# 17

2 Attachment(s)
hi 1i (Guess who!),

The previous excel sheet is for that particular case (6R to -2R) because I only calculate the probability of 100 steps since the probability of every single node above 100 steps is too small for that case and can be ignored.

In fact the correct calculation should take infinite steps if you want to consider all kind of cases. Anyway I have revised my excel sheet for 2000 steps. I believe it is good enough to handle most cases that happened in forex trading.
Click to Enlarge

Name: 2000steps.PNG
Size: 3 KB
Random walk and Pascals triangle R1.xls

Scotty2Cues Aug 4, 2010 4:53pm | Post# 18

hi 1i (Guess who!),

The previous excel sheet is for that particular case (6R to -2R) because I only calculate the probability of 100 steps since the probability of every single node above 100 steps is too small for that case and can be ignored.

In fact the correct calculation should take infinite steps if you want to consider all kind of cases. Anyway I have revised my excel sheet for 2000 steps. I believe it is good enough to handle most cases that happened in forex trading.
can you give some theory plz?

sqrt(-1) Aug 4, 2010 5:07pm | Post# 19

I'm not sure whether I understand this. Did you mean the P(win) not equal to P(loss) when you extend the SL to -6R?

Thank you for your trailing stop idea. The new 'triangle' is a smart idea and i think that should work! I'll try to figure out the detail when i got time.
Check your sig figs. You may have lost some data in digits.

EDIT>You got it.

sqrt(-1) Aug 4, 2010 5:25pm | Post# 20

I am not basing the probabilities of a step to the 'left' or 'right' on historical data. Im making an assumption that if I get a signal to sell, eg because of a pinbar at a swing high, then Im assuming the probability of a step right is greater than a step left.

I wanted to do EV calculations so EV = -risk*P(stopped out) + reward*P(take profit) and wanted to see how SL and TP affected the EV calculations. I then wanted to see if/how including a move of the SL to breakeven affected the EV calculation. If I had the formula (thanks Medici) I can...
How will you be able to obtain P(stopped out) or P(take profit) without using historical data of walks for pinbars at a swing high? Mere deviation from a central price based on probabilities of random walks? I like the idea, but forex isn't random, it isn't like flipping a coin. GBP/USD has run up ~1500 pips from the low a few months ago. We can examine the random probability of it doing this, and the odds are very small by random (given p,q=50%), but as you know, historically the pair has moved this much and more in the past. This is how we know forex pairs aren't correlated by random patterns -there are forces which move them.


© Forex Factory