st101 » week-6 »

33.  Flash Crash Example

These are draft notes extracted from subtitles. Feel free to improve them. Contributions are most welcome. Thank you!
Please check the wiki guide for some tips on wiki editing.


01 Change Interval

So why don’t you in this unit look at a fieldexample, if we are applying statistical techniquesfor problems of important significance in stocktrading. So here is a stock price for a specificday in 2010 and the company we’re discussingis Apple, which on the day started trading justabove $250 but in the afternoon the stock wentall of a sudden down to $200, back to theoriginal price. As a statistician, we areconcerned about this, because if we make tradingdecisions based on what’s happening, we mightlose millions or billions of dollars.This is a one in a decade abnormal behaviorand as a statistician, we might care aboutwriting software that finds these kind ofbehaviors, so we stop trading and we don’tfall into the trap of selling our stock at aunfortunate rate just because something really,really strange is happening. And that’s a realexample, in which have lost millions if notbillions of dollars.So on a typical trading day, Apple stock tradedabout 70,000 times, giving us 70,000 data pointsof prices during the day. What we’d be lookingat is the percentage change between adjacenttrades, which we call Delta T and this definedas the difference between two consecutive tradingpoints, XT plus one minus XT normalized by XT.So normally if XT and XT plus one is the same,this will be zero. If there is a big differencethen this is a larger value and we know for theday in question what the mean and the standarddeviation is for this percentage change. Themean is as small as 0.00074 negative in percent,so if we leave off the percent it’s even ahundred times smaller and this is the valuefor the standard deviation, 0.01344 percent.My first question for you is, to compute theconfidence interval, assuming that we can usea confidence interval to detect outliers inthe data. If you assume a symmetrical confidenceinterval with five percent confidence, in ourmagic factor that percentile is 1.96; computefor me in percent the confidence intervalfor the variable Delta T.


02 Change Interval Solution

And the correct answer is minus 0.02708 and0.0256 and this is obtained by taking the meanover here and adding in the standard deviationplus minus up multiplied by 1.96.

There was some confusion regarding this quiz in the forums because a lot of people misunderstood the confidence interval formula:

CI = a \cdot \frac{\sigma}{\sqrt{N}}

Confidence interval was taught in a single and very exclusive scenario, so it is easy to forget the meaning of this formula. Remember that a (the magic number, which is equal to 1.96 for N \ge 30) is the stretch of your confidence interval in number of standard deviations (in the figure that would be x, i.e., the distance between (\mu+x) and \mu) that gives you the desired confidence (95% in the figure):


The actual distance (CI or x in the figure) is therefore equal to a \times \sigma. So why the formula is CI = a \cdot \frac{\sigma}{\sqrt{N}}? Remember the context where we were using this formula. We were calculating the confidence interval for an estimation of \mu given a sample of size N (mean over a sample of size N). The instructor spent a few lectures (24. Confidence Interval, from lecture 15 to lecture 19) showing that the standard deviation in this case is equal to \frac{\sigma}{\sqrt{N}} , where \sigma is the standard deviation of the original distribution (the distribution you are sampling from). In these confidence interval examples, we wanted to know how confident we were on the estimation of the true \mu obtained from calculating the mean over the sample.

The mean and the variance in the quiz do represent estimations of the true \mu and \sigma of our distribution from a sample of size 70.000 (these are MLE of the true \mu and \sigma). But what is being asked is not what is the confidence that we have in these estimations (as in previous confidence interval examples), e.g., "our estimation of the true mean obtained from calculating the mean over the sample should be inside the confidence interval \mu \pm CI with 95% confidence".

What is being asked in this quiz is what's the interval for which we can say with 95% confidence that a future value of \Delta t will fall inside this same interval (which is the same as saying that we have 5% confidence that a future value of \Delta t will fall outside this same interval). So we should use the standard deviation of the distribution itself (or better saying the MLE of \sigma obtained from 70,000 samples, since we don't know the true \mu and \sigma of this distribution) instead of the standard deviation of the mean over the sample (\frac{\sigma}{\sqrt{n}}).

The solution is therefore:

CI = a \times \sigma

CI = 1.96 \times 0.01344 = 0.026342400000000002

Resulting in the following confidence interval:

-0.00074 \pm 1.96 \cdot 0.01344

(-0.00074 - 1.96 \cdot 0.01344, -0.00074 + 1.96 \cdot 0.01344)

(-0.027082400000000003, 0.0256024)

03 Outlier Frequency

So here is the real question, suppose you usethis confidence interval to detect abnormalbehavior and abnormal behavior mean, you go toyour boss and you complain, he’ll stop tradingthen how often during a day would you expect todetect abnormal behavior in your trading, ordifferently how frequently does this confidenceinternal trigger on any given single day.

unnamed (6).jpg

04 Outlier Frequency Solution

And the answer is way too frequently, 3,500 on just asingle day you’d be taking your boss all the time andthe reason is very simple. You take the 70,000over here and you apply a five percent internalover here and if everything is normal youdistribute it what you believe it is, you get3,500 outliers in expectation every day.

05 New Interval

The trick is to change these numbers over hereto numbers that trigger once in a decade andthis is as simple as changing the 1.96 to 6.5which is really kind of a minor change, but thismakes all the difference. The percentage nowbecomes so small, you get one trigger per decade.So let’s quickly compute what the numbers looklike for 6.5.

unnamed (2).jpg

06 New Interval Solution

And these are the numbers I get: minus 0.0881,0.08662. And this is a wider confidence internvalthan before, that means we trigger lessfrequently and we find less frequently problems withour trading statistics.So let’s now dive in on May 6, 2010, when theApple stock crashed and see if we could havedetected that crash and saved ourselves from risky trades.

07 Calculate Change

So, let me give you examples for twoconsecutive prices. So, here’s one examplewhere the stock changed from 286.85, 286.83.First you calculate the Delta T, which toremind you was the difference of those twothings, Xt+1 - Xt, normalized by Xt. So, whydon’t you give me your calculation of Delta T,into this box over here.

unnamed (3).jpg

Note that a percent sign is missing from the quiz. The answer has to be in percent:

unnamed (6 a).jpeg

08 Calculate Change Solution

I get 0.00697 when I plug this in.

09 Abnormal 1

And now, here’s the important question,is this abnormal, yes or no?

unnamed (4).jpg

10 Abnormal 1 Solution

And I would say, no, because this value fallswell into – between this confidence intervalfrom here to here.

11 Abnormal 2

I give you three more examples from that day.Because at some point, we got from 247.6 to247.55, some other time 242.5 to 240.0 and thenwe got from 205.71 to 201: all within afraction of a second. I’m just going to askyou the same question as before, do youconsider these abnormal, relativeto this confidence interval over here?

unnamed (5).jpg

12 Abnormal 2 Solution

And it turns out, the first one is still okay,but the last two would have been abnormal.And the reason is when you work out the Delta Tin percent, you find that this one over here is a0.104% change, but it’s just too much for a singletrade. And this one is an amazing 2.3% changewithin a single trade. And those clearly triggerthe abnormality behavior. Let’s look at the data.

13 Summary

And this here is our Delta T,over time, for Apple’s stock on May 6, 2010.And you’ll find during the day it trades very normallyand all of a sudden you get this amazing oscillation hereof the stock first going down and then going up againand that is really indicative of something bizarre happening.And our statistic would have found itand might have saved you some money.So, that’s my example from financial data.In the next few minutes we’re going to pick a different example.

unnamed (1 a).jpeg