Monday, 6 December 2010

Stock Sequence

The number of up trends of given length in the data set, e.g. there were 1631 days when the stock only went up for one day and then down the next. On the random walk model the up probability is unaffected by the length of sequence, and vice-versa the length of sequence is not affected by any factor other than randomness. The probability of a sequence of two is the probability of a single sequence squared, and so on. The jth root was taken for each percentage where j was the length. The Cum_Root column assumes that the probability of the previous up moves is given by the rows above and so calculated the probability of adding an extra day to the sequence. This is the most important statistic as it shows, on average, the probability of the current (local) up trend from continuing. Obviously the next down may only be a single day before the trend continues. A better analysis is required for what becomes Elliot waves/Fractals etc - to come as soon as I work out how!


Data for FTSE


Length

Count

%

root

cum_root

1

1631

0.484839

0.484839

0.484839

2

853

0.253567

0.503555

0.522992

3

477

0.141795

0.52146

0.559203

4

203

0.060345

0.495633

0.425577

5

109

0.032402

0.503633

0.536946

6

52

0.015458

0.499104

0.477064

7

24

0.007134

0.493556

0.461538

8

9

0.002675

0.476896

0.375

9

2

0.000595

0.438102

0.222222

Data for BP (NYSE)

Length

Count

%

root

cum_root

1

1464

0.462998

0.462998

0.462998

2

783

0.247628

0.497622

0.534836

3

447

0.141366

0.520933

0.570881

4

231

0.073055

0.519891

0.516779

5

103

0.032574

0.504168

0.445887

6

71

0.022454

0.531149

0.68932

7

32

0.01012

0.518832

0.450704

8

19

0.006009

0.527654

0.59375

9

7

0.002214

0.507008

0.368421

10

3

0.000949

0.498558

0.428571



The first graph plots the average root, the second graph plots the cumulative root. The data becomes less reliable as the length increases as there are less such events but the general trend seems to be that after ... need to think about this + is it a percentage of the number of sequences, or the percentage of up days in each type of sequence?... think!




































Log Actual counts (y) of sequences of up and down of length x from FTSE (1984 to 2010) in blue. The monte-carlo simulation seems to contain an error but is nearly correct.

In a binary sequence a "pair" means 11 following a 0 and preceeding a codon starting in 0. The probability of a 011 sequence is 1/8 and the probabilility that the next codon starts with 0 is 1/2 so 1/16. Thus the probability of sequences of length l is 2^-(l+2)

[check the length of sequences! an error]

Assuming the rare sequences have more error so ignoring the deviance of graph, this suggests that indeed the stock market is random in that ups and downs don't seem to stick together any more than at random.


That said here is a plot of a walk based on the up/down data from the FTSE ignoring the size of the move. It very clearly shows a periodicity in the stock movements. This means the periodicity lies in the up/down data not the distance data. So it is random on the daily level but patterns show up on the macro level.

Finally the need to examine the charts with the extra factor of scale. Not sure yet how to proceed.

Saturday, 4 December 2010

UK Money Supply: M4/GNP


The UK M4 money supply looks like this. Q.E. is a feature of monetary policy not some new buzz word of the recession. Obviously in a static economy if you double the amount of money in circulation then each transaction will use twice the money it did before and so the cost of everything doubles and the power of the currency halves. This is inflation.

The assumption behind increasing the money supply (Q.E.) is that the economy grows and so there are more transactions. If the economy doubled but the money stayed the same it would be the opposite of the above. Twice the transactions and so half the money would be used in each which would cause prices to halve and the power of the currency to double. This would be deflation.

Of course just having loads of cash in a bank vault doesn't make up M4. It must be in circulation which I understand is the money velocity (not being an economist - and I must stress this blog is a search for truth not an exposition of it!). The faster it moves the more transactions it can be used in and so it is more effective than money in a vault (which isn't being used as collateral against a debt that is being traded and so increases money flow by proxy obviously).

So why is inflation favoured over deflation? One argument you will hear is that an efficient pound puts pressure on other currencies so exports grind to a halt as other economies can't afford produce priced in pounds. Exports are important because they stimulate jobs, but they also stimulate the value of the currency. Take the example of the UK selling services to France. I assume this means that the French have to buy pounds on the currency markets to execute the transactions. Pound demand goes up which pushes the value higher in addition to even more transactions being executed. Imports conversely destroy local jobs and require the buyer to purchase the currency of the supplier putting the home currency into the market place and lowering its value. So to keep exports up in an economy with growing demand, the currency must be devalued by Q.E. I think this gets lost on the gold-standard fraternity.

Another argument you don't hear is that when the central bank prints money is makes money also. It buys things with the money it has printed. This is illegal for non-central banks for very obvious reasons ;-) But central banks can make money for just the cost of printing while everyone else has to do real "work" or own real "risk" to make money. I'm sure the temptation is to make a bit more than they need especially with the government pushing them to reduce the debt.

A NOTE here as I think this through: I have criticised Fractional Reserve banking before but see a bit more now. To buy a house I need some money that I haven't got. When I go to a money lender I am able to produce cash that I haven't got. The seller can actually go and get a suitcase with the £200k in it if they wish. Now in reality only a fraction of that money exists since banks lend out some 30times what they have in store, and assume that not everyone on simple probability is going to go and get a suitcase of their money at once. Pounds only represent the value in an exchange transaction not the actual value of things. The M4 is only the money in circulation not the value of the country. This is why things that aren't traded have no price - it doesn't mean they have no value! So the process of money lending is not the process of handing over the value of a house but rather entering into a complex exchange process whereby I can execute it instantly at one end and slowly at the other end through a mortgage. But the bank doesn't execute it instantly either since, in most cases, it doesn't have to produce a suitcase of cash. So it is false to think the banks are making money out of nothing by fractional reserve banking, they are simply setting up complex exchange processes that are a bit more subtle than handing things over a single counter. And anyway someone with a mortgage has just spent money they don't have and has just made money out of nothing - how else are they sitting in a house they haven't paid for yet? What this process does do is create huge inflation as argued a long time back in the blog.

Back to the point above. Rather than support inflation savers argue in favour of deflation because it means that the money they got paid yesterday is worth more today. There is less incentive to spend and so the number of transactions reduces naturally as they save which returns the value of the currency to some stable level. The built in negative-feedback device of deflation thus naturally balances that of inflation. However reducing the number of transactions reduces the amount of work in the economy which (as things are set up in current economies) will reduce the pay and so circulation of money; this might cause a downward spiral. The answer as this blog has analysed endlessly is to rethink the distribution of wealth and intelligently uncouple it from work - but that requires a re-conception of life and work (which this blog is desiring to do).

If there is a growing population then the number of transactions is going to increase naturally. With a limited money supply this will mean that less money is used in each transaction and so will lead to natural deflation. The single case where population growth leads to wealth (for a few). The deflation will lead to pressure to save, which will reduce the flow of money and cause another deflationary spiral.

There are thus very good reasons to increase the money supply to ensure that saving doesn't become too attractive. This means however that savings get hurt. To compensate, savers get an interest which is paid by borrowers. The amount that borrowers are prepared to pay depends upon their expected returns and competition between banks for lending credit. A growing economy favours lending and so interest payments. In theory the devaluation due to increase in money supply ought to be offset for savers by the increasing interest payments. However in Keynesian reality, growth is created by reducing interest payments to make credit cheap to drive borrowing and spending (the Ponzi Scheme that is the model for modern economics). Savers get little interest and then get hit by the stealth inflation in the market place, and the devaluation of their currency due to Q.E. The emphasis is on spending and debt which means we have not only today's money in our pocket but tomorrow's and the money from the day after. Massive Q.E. driving inflation. As prices go up we need to borrow more (e.g. house prices) and an inflationary spiral is entered. I imagine that eventually economist will learn to balance these forces of inflation and deflation, but at the moment, for whatever reasons, they are amateurish and incompetent.

Anyway now the point of this long foray into monetarism. The M4 money supply in the UK has increased from about £125 bill in1984 to £1400 billion in 2010. That is an increase of about 11 times. In a static economy this would result in prices increasing about 11 times. The average house price in 1984 was £75k and recently peaked at £200k so in reality an increase of only 2.6. Assuming that pressure for housing hasn't changed (not unreasonable as the population is basically the same and there has been a lot of house building in the last 26years which ought if anything to reduce prices) then house prices should have remained static which means that the economy must have expanded to take up the extra money. But still 2.6 times too much money was printed and the real economy only grew by 11.2/2.6=4.3.

A more reliable measure would be the GNP which has increased in the period from $629PPP bill to $2350PPP bill an increase of only 3.74 times. That means that 11.2/3.74=3 times too much money has been printed meaning that everything costs 3x what it should and savings are a 1/3 less powerful then they should be! This agrees with the rough measure above and supports the assumption that pressure for housing hasn't actually increased. The economy has actually only increased by a factor of 3.74 instead of 11.2 while the pound has actually weakened to a third and prices are 3 times what they were. That was the basis of the "apparent" booms that Brown and others have resided over.

So now back to stock markets. If you invested £1000 in the stock market in 1984 with economic growth of 3.74 it should be worth £3740 today (assuming your companies expand in accordance with the general economic growth). However M4 money printing has been going on. If it was in line with the 3.74 growth then the pound would remain stable and you would have £3640 today. But we know that 11.2 times as much has been printed (3 times too much) so actually the buying power of the pound has reduced to a 1/3. So the £3740 we see on the balance sheet is really only worth 1247 (in 1984 pounds). That is an actual increase of 125% in 26 years that is just 0.86% per year. Put that another way we need to make 26root(3)= 4.3% a year to keep up with the excessive money printing.

The relevance of this to the stock modelling is that an upward trend of 4.3% a year is present not because of anything in the stock market but because of the devaluation of the currency. This is maybe enough to turn a lot of down moves into up moves and bias what is perhaps a random pattern. Removing this up-trend might also make modelling the distributions easier. A new dataset removing the M4/GNP data is required.



Since 1987 the value of the pound based on the RPI has dropped to 44%. Extrapolate backwards to 1984 and that is 35% similar to the 33% above.

===

Here is the UK treasury data on GDP and also inflation.


£100 in 2009 is the equivalent of £42 in 1984. That is substantially higher than the 33% above but will do to begin with.

Friday, 3 December 2010

Stock Direction Correlation & Distance Correlation

Comparing Up/Down movements of successive days in the FTSE gives us this unexpected result. Given today's close relative to yesterdays as Up/Down what what the previous move?

Yesterday was Down: Today was:
Up 1673 25.0% 52.5%
Down 1513 22.6% 47.5%
Total 3168 (of total) (of down)

Yesterday was Up: Today was:
Down 1673 25.0% 47.6%
Up 1839 27.5% 52.4%
Total 3512 (of total) (of up)

There are only 18 days when the two days close the same i.e. 0.3% so I'm ignoring this event.

I don't need to do stats on this: there are 6698 events! and unbelievably the Up/Down and Down/Up counts are the same really suggesting that it makes no difference whether yesterday was an up or a down to signal a change in direction: it happens 25% of the time i.e. the Expected value based upon a random assumption.

However if yesterday was Up then there is a more than average chance that today will be up also! 27.5%.

Conversely if yesterday was down there is a less than average chance that tomorrow will be down!

In the stock walk then, the stock has a 52% chance of going up again and 48% chance of falling. Does this explain the trend of the stock market up or is distance a feature also, that is, are moves down bigger than moves up or vice versa.

The total log distance moved in the period is from 7.010402 on the 4th Feb 1984 to 8.642715 on 26th Nov 2010 which is +1.63231. There are 3522 up events (52.4%) in total and 3194 down events (47.6%) i.e. an excess of 328 up events to account for the up shift, if up and down are the same size. So we would expect each event to be on average a shift of 0.5%.

We can calculate that exactly from the data. The average move irrespective of direction is 0.7922% much bigger. This breaks down to:

Average move Up is: 0.7805% against an average move down of -0.81%.

So to summarise the probability of up moves is 10.3% more likely than down moves, but the size of down moves is 3.7% larger than up events. The average daily swing is also larger at 0.8% than the minimum expected at random of 0.5%.

A Model
N = number days -1. Pu/Pd is probability of up/dow
n. Du/Dd is average distance up/down.

Total distance Up = N.Pu.Du
Total distance Down = N.Pd.Dd = N.(1-Pu).Dd

Net distance D = Total distance Up - Total distance Down = N [Pu.(Du+Dd) - Dd)]

Our data set has N=6735 interday events. Pu = 0.524. Du = 0.0078. Dd= 0.0081

D = 1.56

Data for BP dataset.

Yesterday was Down. Today is:
Up 1640 25.5
Down 1486 23.1

Yesterday was Up. Today is:
Down 1585 24.7
Up 1717 26.7

There are 4.5% events when the stock closed the same. Probably a feature of the lower stock value and therefore less significant figures and then rounding errors. Ignored.

There is a similar pattern to the FTSE. Noticeably the probability of an Up is higher if yesterday was a Down than the other way around. I need to think about this in relation to the extraordinary result from the FTSE.

Average distance Up is: 0.012396
Average distance Down is: -0.0124
Total average distance: 0.011868 (including days when stock same)

Interestingly unlike the FTSE the average moves up and down are the same. This means the trend over time is because of the probability of up/down rather than the size!!! Very interesting from a trading point of view!! (Maybe individual stocks work like this while the FTSE is a conglomeration of different sectors each with different performances each day and so has changing behaviour.)

The Model is a bit simpler here:

N = 6428, Pu = 0.514, Du = 0.012

D = N [Du(2.Pu - 1)] = 2.16 (Actual value of : 2.28)

Next up is there a correlation between distances?


Not Obviously but stats tests show otherwise. A two tailed on the complete data of today's price change against tomorrow's was less conclusive with the Pearson not even being significant.

Correlations

Today

Tomorrow

Today

Pearson Correlation

1

.008

Sig. (2-tailed)

.534

Sum of Squares and Cross-products

1.927

.015

Covariance

.000

.000

N

6733

6733


The Spearman and Kendal-tau measures show a significant correlation between todays and tomorrows stock moves.

Correlations

Today

Tomorrow

Kendall's tau_b

Today

Correlation Coefficient

1.000

.022**

Sig. (2-tailed)

.

.008

N

6733

6733

Tomorrow

Correlation Coefficient

.022**

1.000

Sig. (2-tailed)

.008

.

N

6733

6733

Spearman's rho

Today

Correlation Coefficient

1.000

.031*

Sig. (2-tailed)

.

.010

N

6733

6733

Tomorrow

Correlation Coefficient

.031*

1.000

Sig. (2-tailed)

.010

.

N

6733

6733

**. Correlation is significant at the 0.01 level (2-tailed).

*. Correlation is significant at the 0.05 level (2-tailed).

However taking absolute values and so only looking at the size of the change the correlations are not surprisingly extremely significant.

Today_pos

Tomorrow_pos

Today_pos

Pearson Correlation

1

.210**

Sig. (1-tailed)

.000

Sum of Squares and Cross-products

.979

.205

Covariance

.000

.000

N

6733

6733


Correlations

Today_pos

Tomorrow_pos

Kendall's tau_b

Today_pos

Correlation Coefficient

1.000

.067**

Sig. (1-tailed)

.

.000

N

6733

6733

Tomorrow_pos

Correlation Coefficient

.067**

1.000

Sig. (1-tailed)

.000

.

N

6733

6733

Spearman's rho

Today_pos

Correlation Coefficient

1.000

.101**

Sig. (1-tailed)

.

.000

N

6733

6733

Tomorrow_pos

Correlation Coefficient

.101**

1.000

Sig. (1-tailed)

.000

.

N

6733

6733

**. Correlation is significant at the 0.01 level (1-tailed).

I'm assuming 1-tailed because values are only positive. This comes as little surprise however because we would expect big moves to be followed by big moves. A technical ought to be available then (maybe Bollinger) which determines the size of moves to expect. Then rough trend to confirm this belief by linear regression is:


Coefficientsa

Model

Unstandardized Coefficients

Standardized Coefficients

t

Sig.

B

Std. Error

Beta

1

(Constant)

.009

.000

46.520

.000

Today_pos

.210

.012

.210

17.586

.000

a. Dependent Variable: Tomorrow_pos



Coefficientsa

Model

Unstandardized Coefficients

Standardized Coefficients

t

Sig.

B

Std. Error

Beta

1

(Constant)

.009

.000

46.520

.000

Today_pos

.210

.012

.210

17.586

.000

a. Dependent Variable: Tomorrow_pos

So indeed the size of tomorrows price move is a positive function of todays price move (significantly).

[Stats courtesy of SPSS.]

Summary


to be summarised and expanded...



===
Adjusting the figures for inflation (which approximated to GNP/M4) the distribution of up/down was only slightly affected.

Yesterday was Up. Today was:
Up 26.9%
Down 25.0%

Yesterday was Down. Today was:
Up 25.0%
Down 23.0%

Total Up=52% versus down=48% so same as before.

Removing the upward bias hasn't changed many of the ups into down but it seems to have operated selectively. It has either turned UUs into UDs or DUs into DDs or taken UUs and made them DD (less likely). Suggesting that these were weak relationships.

For the BP data the effect is more obvious with only UU standing out as a feature of the data now.

UU 26.5%
UD 24.5%
DU 24.6%
DD 24.3%

Correlations

VAR00001

VAR00002

VAR00001

Pearson Correlation

1

.210**

Sig. (1-tailed)

.000

N

6733

6733

VAR00002

Pearson Correlation

.210**

1

Sig. (1-tailed)

.000

N

6733

6733

**. Correlation is significant at the 0.01 level (1-tailed).


Correlations

VAR00001

VAR00002

Kendall's tau_b

VAR00001

Correlation Coefficient

1.000

.067**

Sig. (1-tailed)

.

.000

N

6733

6733

VAR00002

Correlation Coefficient

.067**

1.000

Sig. (1-tailed)

.000

.

N

6733

6733

Spearman's rho

VAR00001

Correlation Coefficient

1.000

.100**

Sig. (1-tailed)

.

.000

N

6733

6733

VAR00002

Correlation Coefficient

.100**

1.000

Sig. (1-tailed)

.000

.

N

6733

6733

**. Correlation is significant at the 0.01 level (1-tailed).


OK the trends are still there after removing inflation.


US displaying its Imperialist credentials... yet again

Wanted to know the pattern of UN votes over Venezuela and then got into seeing if ChatGPT could see the obvious pattern of Imperialism here....