Friday, 12 November 2010

Random market variance

Investment Maths and Random Walk looked at mean returns in a random market and stock movements in a random market. Next up is variance.

Let p=probability of stock going up, q=(1-p)=probability of stock going down, and 'i' is the percentage change so that I = Ln(i). After a single period of time the stock may rise with probability p or fall with probability q.

Ln[s(1)] = Ln[s(0)] + pI - qI

After n periods the possible outcomes will produce the usual binary tree with probabilities:

(p+q)^n = Sum(w=0 to n) [ E(n,w) ] = 1

with each term of the expansion being:

E(n,w) = C(n,w) * p^w * q^(n-w)

Where w is the number of wins (up movements) and C(n, w) the binomial coefficient. Each outcome will produce a stock movement of (wins-losses), equivalent to (2*wins - n), which when multiplied by its
probability from above gives its average contribution to the average stock movement. Each term is thus:

Return due to path w, R(n,w) = wins - losses = I(2*w-n)

Average return R = Sum(w=0 to n) [ E(n,w) * R(n,w) ] = n I (2p-1)

Variance, S.D.^2 = Sum (w=0 to n) [ E(n,w) * (R(n,w) - R)^2 ] = 4 * n * I^2 * p * q

S.D. = 2 * I * Sqrt(n * p * q)

For p=0.5 the distribution of outcomes follows the Normal Distribution (continuous version of the binomial expansion) so in general we can approximately calculate (better for large n) the probability of a particular return using N(R, SD). For an example the probability of getting a deviation of 2I with n=4:

z = 2I / 2I = 1 standard deviation

Which occurs with probability = 34% (using z table).

A deviation of 2I corresponds to 2*Log(i) which if i=1.05 means a deviation of 0.04 in Log space. This corresponds to an actual stock market deviation of:

Upper deviation = 10^(Log(s) + 0.04) = s*10^0.04 = s*1.103
Lower deviation = 10^(Log(s) - 0.04) = s*10^-0.04 = s*0.907

This is calculated for an investment in a single stock. Now what happens if we invest in two stocks.

Variance in portfolio of 2 Stocks

The combined portfolio (S) results from the addition of stock 1 (s1) and stock 2 (s2):

S(n+1) = s1(n+1) + s2(n+1)

Each stock follows the model above:

Log[s1(n+1)] = Log[s1(n)] + I*(
2 * wins1 - n
)
Log[s2(n+1)] = Log[s2(n)] + I*(
2 * wins2 - n
)

So these cannot be expressed in Log space. Instead they need to be expresse
d in real stock price space.

s1(n+1) = s1(n) * i^(
2 * wins1 - n
)
s2(n+1) = s2(n) * i^(
2 * wins2 - n
)

So that,

S(n+1) =
s1(n) * i^(
2 * wins1 - n
) +
s2(n) * i^(
2 * wins2 - n
)

Assume the portfolio is evenly split then s1(n) = S(n)/2

S(n+1) = S(n) * [
i^(
2 * wins1 - n
) +
i^(
2 * wins2 - n
)]

The distribution of outcomes from each stock is as above and obeys the Binomial expansion above. For each outcome in stock 1, stock 2 obeys the Binomial expansion also. If n is the number of trading periods then there are (n+1) terms in the binomial expansion of both stocks so there are a total of (n+1)^2 combined terms. In general that is total paths:

TP = (n+1)^sigma, where sigma is the number of stocks in the portfolio.

So for any particular outcome of wins and losses we multiply the coefficients:

Number path with this combination of wins NP(wins1, wins2) = C(n,wins in stock 1) * C(n, wins in stock 2)

In general for sigma stocks:
NP(wins1, wins2,...,wins_sigma) =
C(n,wins in stock 1) * C(n, wins in stock 2) * ... *
C(n, wins in stock sigma)

Thus, assuming that wins and losses are equally probable, the probability of a particul
ar outcome is NP/TP

The value of that outcome is calculated from the equation above for S(n+1).

Mean and Variance for 2 Stocks

These values can't be meaningfully calculated in price space since the distribution is skewed. The mean and variance need to be calculated from the Log(price) values. There is no simple way (that I know) to simplify these calculations so I
switch to a program to do the job of calculating.

Interesting to note what a massive calculation this is. A portfolio of 20 stocks taken over just 10 trading periods will take almost the entire age of the universe for my dual-core computer running an interpreted basic program to calculate!

This graph shows the standard deviations in terms of Log(i) in the y, for various portfolio sizes (x axis) and over increasing trading sessions (z axis).
It seems to settle down very fast as portfolio size increases which suggests at first look that portfolios don't need to be very diversified to reduce risk in the random market.



By inspection of values it can be seen that this follows an exact pattern:

standard deviation = Sqrt(number trading sessions/no of stock) * Ln(i)

This crude measure can be used as the basis of measuring risk in a portfolio. The larger the S.D. the greater the chance of big gains, but also the greater the chance of big losses. However if we reduce risk we don't make any gains or losses.

Below is the distribution of all outcomes in a 6 stock portfolio over only 4 trading periods, in a random market with equal chances of a step up as a step down. X axis is Log(return)%, Y axis the number of outcomes. While it is a very complex irregular pattern it "seems" to fit within a broad normal distribution. The gaps are due to certain paths being impossible given that the system is very restrained only allowing up or down moves which excludes the possibility of staying the same. One possibility is to examine the multinomial version of this model with (win + lose + same)^n. The graph following that is the same but with the normal distribution roughly fitted and unadjusted log(return) values in the x direction.







The Model
So the exact distribution in natural log space of a stock chart following a random walk will approximate to the binomial distribution with:

mean = 0
S.D. = Sqrt(n/sigma) * Ln(i)

Where n is the number of trading sessions, sigma the number of stocks in the portfolio, i the average percentage increase/decrease of the stock in trading sessions.

Let us take an example:

Closing prices for the FTSE from 1/7/2010 until 12/11/10 downloaded from Yahoo. An up trend that looks like a rising wedge to me and so a reversal pattern. At the same time the DJI is breaking resistance and possibly pushing higher.

Calculated from the whole FTSE data starting 1984 the average daily factor of increase/decrease
is i=1.0079829. That is if
stock price s1 > s2 then i = s1/s2
otherwise i=s2/s1.

The number of trading periods (days) in this graph is n=89. The gap up is r=992 so LN(r) = 6.9

S.D. = Sqrt(89/1) * 6.9 = 0.65

z = 10.6 and the probability of a random walk going this far is p=3E-25!!!!

In other words it is impossible that this is random! Rejecting H0 we must accept that this is an actual up trend! Now the great question how long will it last? 2Do

I need to check all this working and logic but this is the first outline of a crude method. 14/11/2010


No comments:

"The Jewish Fallacy" OR "The Inauthenticity of the West"

I initially thought to start up a discussion to formalise what I was going to name the "Jewish Fallacy" and I'm sure there is ...