Continuous Double Auction Model,  Part II

Needs["Histograms`"];
<<Stable`StableM`
LogReturn[data_] := Differences[Log[N[data]]];
AutoCorrelationF[data_,lag_]:=Module[{dataf,dataf1,n},n=Length[data];dataf=Fourier[Join[data-((Plus@@data)/n),Table[0.`,{lag}]]];dataf1=Take[Chop[Fourier[dataf Conjugate[dataf]]],lag+1] N[(Sqrt[n+lag])];(dataf1/(dataf1[[1]]))];
absecf0=Compile[{t,{s,_Real,1}},Abs[Mean[Exp[I t s]]]-1/E];
ABSECF0[t_?NumericQ,s_]:=absecf0[t,s];
QkScale[s_]:= Module[{c0,cc},
c0 =QuartileDeviation[s] ;(*this is best for alpha>1,not a reliable starting point as alpha -> 0*)
(*Absolute value of result is taken in case negative root is found*)
Abs[cc/.FindRoot[ABSECF0[1/cc,s],{cc,c0}]]];
EmpiricCDFList[data_] := Block[{prob,sel,del},
					
					prob= Table[(i-0.5)/Length[data],{i,Length[data]}];
					Transpose[Join[{Sort[data]},{prob}]]];
Clear[DisplayLogStableFit];
scdf[x_?NumericQ,parm_,type_:1,opts___]:=SCDF[x,parm,type,opts];
DisplayLogStableFit[data_,parm_,type_Integer:1]:=Module[{clist,lt,rt,trt,lp1,lp2,lp3,lp4,lp5,nmn,nstd},
clist=EmpiricCDFList[data];
	lt = Select[clist,#[[1]]<0&];
	rt= Select[clist,#[[1]]>0&];
	trt=Transpose[rt];
lp1=ListLogLogPlot[Abs[lt],PlotStyle->Blue,PlotRange->All];
lp2=ListLogLogPlot[Transpose[{trt[[1]],1- trt[[2]]}],PlotStyle->Red,PlotRange->All];
lp3= LogLogPlot[scdf[-x,parm,type],{x,0.0001,-4 Min[data]},PlotStyle->Blue,PlotRange->All,PerformanceGoal->"Speed"];
lp4= LogLogPlot[1-scdf[x,parm,type],{x,0.0001,-4 Min[data]},PlotStyle->Red,PlotRange->All,PerformanceGoal->"Speed"];
nmn=Mean[data];
nstd=StandardDeviation[data];
lp5= LogLogPlot[1-scdf[x,{2,0,nstd /Sqrt[2],nmn},1],{x,0.0001,4 nstd},PlotStyle->Green,PlotRange->All];
Show[lp1,lp2,lp3,lp4,lp5,PlotLabel->"Log Log Left Tail Blue, Right Red, (Normal Green)",AspectRatio->Automatic,PlotRange->All]];

On another page we developed a model of a continuous double auction, using a Pareto distribution to get the heavy tails in the order books.  We now update this with a double Pareto - log normal distribution to develop the price structure in the limit order books.  This distribution has power tails; if the right power tail has a tail exponent less than two, it and its negative relative will generate a heavy tailed order book structure.

We do a demonstration of the price structure of order books, assuming a double Pareto - log normal random variable is responsible for logarithmic differences in prices.

sa=Exp[RandomReal[NormalDistribution[-Log[200.],1],100]+
RandomReal[ExponentialDistribution[1.8],100]-
RandomReal[ExponentialDistribution[2],100]];
prs=Round[Sort[50 Exp[sa]] 100]/100.;
sb=Exp[RandomReal[NormalDistribution[-Log[200.],1],100]+
RandomReal[ExponentialDistribution[1.8],100]-
RandomReal[ExponentialDistribution[2],100]];
prb=Round[Sort[50 Exp[-sb]] 100]/100.;
ListPlot[Join[prb,prs], PlotLabel-> "Distribution of Order Book Prices\nMarket Price = 50",Frame-> True,
 FrameLabel->{"Order Sequence", "Price"},AxesOrigin->{0,50}]

Just like the previous example we do a run of 10,000 matching intervals.  Only unmatched orders mktnet are considered in this version.  Matched orders don't change the price in the model.  lmtlen needs to be closely matched to the maximal expected absolute values of mktnet or the fat-tails won't occur.  The Mathematica algorithm is shown below.

lmtlen=50;
poissondist=PoissonDistribution[200];
mktnet:= RandomInteger[poissondist]-200;mktprice=50.;
pricelst={mktprice};
Do[lmtn=mktnet;
If[lmtn≠0,lmt =Sign[lmtn]Sort[Exp[RandomReal[NormalDistribution[-Log[500.],1],lmtlen]+
RandomReal[ExponentialDistribution[1.8],lmtlen]-
RandomReal[ExponentialDistribution[2.2],lmtlen]]];
pricelst=Flatten[{pricelst,Round[Exp[Take[lmt,Min[Abs[lmtn],Length[lmt]]]+Log[mktprice]] 100]/100.}]];
	mktprice=Last[pricelst],
		 {10000}];//AbsoluteTiming

A plot of all the prices.

ListPlot[pricelst,Joined->True,PlotRange->All]

Sum the log returns of prices at intervals of 50 prices then calculate stable parameters of summed log returns.

ret1=Plus@@Partition[LogReturn[pricelst],Floor[Length[pricelst]/50]];ListPlot[ret1,PlotRange->All,Joined->True,PlotLabel->"Log Returns"]

The system outputs true stable tails, as expected by the generalized central limit theorem.

parm=Quiet[SFit[ret1]];
CellPrint[TextCell["Stable parameters\n"<>ToString[parm],"Text"]];

Stable parameters
{1.83232, 0.0879309, 0.000718454, -0.0000494793}

Quiet[DisplayLogStableFit[ret1,parm]]

We have created a simple model of a continuous double auction.  It has heavy tails generated by a double Pareto - log normal distribution, sums of random variables from such a heavy tailed distribution converge to a stable distribution.

txcolor=RGBColor[181/255,18/255,27/255];
t1 = Graphics[Text[Hyperlink[Framed[Style["Financial Home", {txcolor, Bold, Larger}]], "../map/Overview.html"], {-5, 0}]];
t2 = Graphics[Text[Hyperlink[Framed[Style["Next", {txcolor, Bold, Larger}]], "../r06/MarketData.html"], {0, -0.5}]];
t3 = Graphics[Text[Hyperlink[Framed[Style["Download Notebook", {txcolor, Bold, Larger}]], "../s07d/CDA2.nb"], {5, 0}]];
t4 = Graphics[Text[Hyperlink[Framed[Style["Previous", {txcolor, Bold, Larger}]], "../s07c/DoubleParetoLogNormal.html"], {0, 0.5}]];
Show[ t1, t2, t3, t4, ImageSize -> 500]
CellPrint[TextCell["\n\n© Copyright " <> ToString[DateList[][[1]]] <> " mathestate    " <> DateString[DateList[], "DateShort"], "Text"]]

© Copyright 2008 mathestate    Mon 12 May 2008