1

This is a trading problem:

Let's say I have an automated trading system with a probability of success of $70\%$ on any individual trade. I run $100$ trades a year. What is the probability of getting $5$ or more consecutive failed trades?

More generally, for a probability of success $p$ on the individual trade, and a total of $n$ trades per annum, what is the probability of a series of $m$ or more consecutive failures, where $m \leq n$ and $0 \leq p \leq 1$?

I realize this can be converted into a problem about getting a run of heads with a biased coin, but I looked around and could not find a response matching my exact needs. By the way, this is a real-world problem, not schoolwork.

draconis
  • 113
  • If the number of trades would have been $\leq10=2\times5$ then I would have an answer for you included in this question. Maybe you are interested anyhow. – drhab May 28 '16 at 10:00

2 Answers2

3

You could model this using a Markov chain with 6 states, labelled 0, 1, 2, 3, 4 and 5, where state $i$ represents that exactly the past $i$ tosses have been a failure, for $i=0,\dots,4$, and state 5 represents that a string of 5 consecutive failures have occurred at some point in the past.

Given that we are in state $i$, for $i=0,\dots,4$, with probability $1-p$ we transition to state $i+1$ (i.e., if another failure occurs), while with probability $p$ we transition to state 0 (i.e., if success occurs). Once we reach state 5, we stay there regardless of what happens; i.e., it is an absorbing state. The transition matrix then is $$A = \begin{pmatrix} p & 1-p & 0 & \dots & 0 \\ p & 0 & 1-p & \dots & 0 \\ & &\vdots \\ p & 0 & 0 & \dots & 1-p \\ 0 & 0 & 0 & \dots & 1\end{pmatrix}$$

Starting in state 0, we are looking for the probability that after 100 transitions we end up in state 5. This probability is $e_0^TA^{100}e_5$, where $e_0,\dots,e_5$ are the standard basis vectors.

For example, here is R code to calculate what you are looking for:

library(expm)
n=100
k=5
p=.7
A=matrix(0,k+1,k+1);
for(i in 0:(k-1)){
  A[i+1,1]=p
  A[i+1,i+2]=1-p;
}
A[k+1,k+1]=1
(A %^% n)[1,k+1]

It outputs 0.1525622 as the probability in this case.

Brent Kerby
  • 5,539
0

Let your trades be $t_1\cdots t_n$, with $t_i\in \{0,1\}$. What is the probability that this sequence contains $k$ consequtives zeroes, if the probability of zero is $p$? Well, the sequence could start at $t_1$, or $t_2,\ldots, t_{n-k+1}$. The probability that a sequence of $k$ zeroes starts at $t_i$ is $p^k$, and there are $n-k+1$ points where the sequence might start, so the first instinct is to add up these probabilities as $(n-k+1)p^k$. But that wouldn't be correct, because you haven't accounted for the fact that these sequences might overlap: you can only add probabilities if they represent disjoint events.

If you were looking for two consequtive fails, then that probability is

$$ P = (n-1)p^2 - (n-2)p^3 $$

The second term subtracts the times you counted two scenarios double. If you are looking for three consecutive fails, then

$$ P = (n-2)p^3 - (n-3)p^4 + (n-4)p^5 $$

You add the term (n-4)p^5 to compensate for the length-$5$ sequences you subtracted double (once too many) in the $(n-3)p^4$ term. See a Venn diagram if you want to know in more detail why exactly.

In general, the probability that $k$ tosses come up tails in $n$ trials (if $n\geq k$) is:

$$ P = \sum_{u=0}^{k-1}(-1)^{u}(n-k-u+1)p^{k+u} $$