Skip to content
All library documents

Use the Full Trade Sequence in a Runs Test for Win–Loss Streaks

Article Quant Q&A · Author: Lyrk

Summary

The document explains how to use a runs test to assess whether winning and losing trades cluster in a sequence. Each trade is represented as a win or loss, and the test compares the observed number of runs—consecutive groups of the same outcome—with its expected value and variability under a randomness assumption. The response relates the referenced formula to the Wald–Wolfowitz runs test and describes it as a test statistic, even though it is commonly called a Z-score.

The key instruction is to retain the complete ordered sequence, including isolated outcomes, rather than filtering for streaks. Removing trades that do not appear to belong to a streak changes the statistic and invalidates the test. Implausible results may indicate a calculation error. The answer suggests a hidden Markov model as a more involved alternative for estimating how the probability of a win depends on the preceding outcome, but provides no fitting method or empirical comparison.

Key ideas

  • A runs test evaluates the number of consecutive same-outcome groups in the full sequence.
  • Do not remove trades outside apparent streaks, because filtering invalidates the test statistic.
  • The referenced statistic is conceptually related to the Wald–Wolfowitz runs test.
  • Unreasonable output may point to an error in the calculation.
  • A hidden Markov model can offer a more sophisticated way to model dependence on the prior outcome.

Tags

Full text
# Z-Score calculation for a win-loss streak


# Z-Score calculation for a win-loss streak












I am trying to find the correlation between wins and losses by applying Z-Score according to formula attached below. I put them in an array by assigning 1 to wins and -1s to losers. I am trying to determine if winners follow winners or losers follow losers. What I wanna ask is before applying Z-Score into this should I remove non-streaks from this array? (When I include non-streaks I find Z-Score -125 which is not a logical number)

my array=[1,1,-1,1,-1,1,1,1,1,1,-1,1,-1,1...]

The formula of the z-score is

```
Z=(N*(R-0.5)-P)/((P*(P-N))/(N-1))^(1/2)

N - total number of trades in a series 
R - total number of series of profitable and losing trades 
P = 2*W*L;
W - total number of profitable trades in the series;
L - total number of losing trades in the series.
```

Source: http://www.forextraders.com/forex-money-management/using-the-z-score-to-determine-trade-size.html

## Answer by John (score 2, accepted)

https://quant.stackexchange.com/a/17855

Your source is not particularly clear about why what they're doing is a Z-score. To give some background, what they're doing is calculating $$\frac{R-\mu_{R}}{\sigma_{R}}$$ where R is the number of runs and the mean and standard deviation are of the number of runs. It's really more of a test statistic than a Z-score per se. The denominator in their formula is actually the same standard deviation as is used in the Wald-Wolfowitz runs test but divided by $N$ (which cancels out from the mean). While I get a slightly different result if I calculate the Z-score solely using the Wald-Wolfowitz values for the mean of runs, it is conceptually the same thing.

So back to your question, you're asking if you should remove the streaks from your array before calculating the value. I would emphasize that you should not. The point of the runs test is to test the number of runs. If you remove everything that is not a run, then your test statistic is no longer valid. If you are not getting sensible numbers, there could be an issue with the calculation somewhere. I was getting perfectly sensible numbers when I was testing this.

The benefit of the original approach is that it is very easy to calculate. There are some other options that might be a little more sophisticated and could provide some interesting information. For instance, you could fit a Hidden Markov Model (HMM) that tries to estimate the probability of a win given whether the previous period was a win or not.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.