Quantcast

Expected lengths of streaks

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Expected lengths of streaks

BBands
About 1,000 years ago I calculated the expected length of a losing
streak by iterative simulation using rle

    trades <- sample(c("W", "L"), 1000, replace = TRUE, prob =
c("0.66", "0.33"))
    trades.rle <- rle(trades)
    tapply(trades.rle$lengths, trades.rle$values, max)

There must be other, better ways today...

    jab
--
John Bollinger, CFA, CMT
www.BollingerBands.com

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

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Expected lengths of streaks

mark leeds
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.


On Tue, May 3, 2011 at 8:05 PM, BBands <[hidden email]> wrote:

> About 1,000 years ago I calculated the expected length of a losing
> streak by iterative simulation using rle
>
>    trades <- sample(c("W", "L"), 1000, replace = TRUE, prob =
> c("0.66", "0.33"))
>    trades.rle <- rle(trades)
>    tapply(trades.rle$lengths, trades.rle$values, max)
>
> There must be other, better ways today...
>
>    jab
> --
> John Bollinger, CFA, CMT
> www.BollingerBands.com
>
> If you advance far enough, you arrive at the beginning.
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Expected lengths of streaks

BBands
On Tue, May 3, 2011 at 5:39 PM, Mark Leeds <[hidden email]> 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.

   jab
--
John Bollinger, CFA, CMT
www.BollingerBands.com

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

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Loading...