[R-SIG-Finance] Expected lengths of streaks

BBands bbands at gmail.com
Wed May 4 16:56:51 CEST 2011

On Tue, May 3, 2011 at 5:39 PM, Mark Leeds <markleeds2 at gmail.com> wrote:
> hi john:
> I'm not clear on whether you want expected value of the max length or the
> expected value
> of the length. but, if you want the latter in closed form and you know , p,
> the probability of sucess ( in your case , the probability of winning
> trade), then the number of trials before you win ( so the length would be
> the number of losses )  can be thought as having a geometric distribution.
> this distribution has expected value of (1-p)/p. and no, I definitely had to
> look that up because I didn't remember the formula.
> I'm not sure how one would handle the expected value of the max length
> analytically. maybe
> simulation is the only way but you might be able to do it faster using the
> analytical result above.

Hi Mark, nice chatting with you at R/Finance.

The nice thing about doing this by simulation using rle is that it
lets you model "Pushes" as well. I define a Push as a win or loss so
small as to be noise. This lets me focus more clearly on the actual
wins and losses that are contributing to performance. I hinted at this
when I spoke about a three-state logic in my presentation.

> Trades <- sample(c("W", "P", "L"), 1000000, replace = TRUE, prob = c("0.60", "0.10", "0.30"))
> TradesRle <- rle(Trades)
> tapply(TradesRle$lengths, TradesRle$values, max)
 L  P  W
11  6 25

I accumulate those over a large number of trials and use the means as
my expected run lengths. If the account cannot withstand an expected
run of losses the system will fail eventually in the real world. I
wrote that simulation long ago and was wondering if there was a better
way today.

John Bollinger, CFA, CMT

If you advance far enough, you arrive at the beginning.

More information about the R-SIG-Finance mailing list