Skip to main content

graphics - How to compute the Multifractal Spectrum of a Financial Series with WTMM


I would like to know if someone knows how to compute the Multifractal Spectrum of a Financial Time Series (Currency) througth the Wavelet Transformation Modulus Maxima (WTMM).


I would highly appreciate any hint in order to calculate Dq, Tau(q), alpha, f(alpha).


I am pasting here the code I am using to get the Multifractal Spectrum (Ref: Gerd Baumann - Mathematica for Theoretical Physics (Mathematica 6.0), Springer Second Edition (2005), page 892) Comments: The following code helps to get the MultiFractal Spectrum, with Mathematica 6.0. I have updated the function ListPlot to ListLinePlot and PlotJoined to Joined as suggested in the Help of Mathematica 8.0.


The code seems to work when the input are the probabilities pi ={p1,p2,....pn} and when the values of each subset of the probability space one is seeking to characterize.


The code doesn't work 100% and I still don't know why (I am new to Mathematica).


The thing is, that the package provided by Mr. Baumann works when you give the input of the probabilities - yet I need that such process should be automated by the WTMM so I can see (analyze) the Whole Multifractal Spectrum.


----------------- ## ----------------------------



BeginPackage["MultiFractal`"];
Clear[Dq, Tau, Alpha, MultiFractal];
MultiFractal::usage = "MultiFractal[p_List,r_List] calculates the
multifractal spectrum D_q for a model based on the probabilities
p and the scaling factors r. This function plots five functions
Tau(q), D_q(q), Alpha(q), f(q) and f(Alpha).";
Begin["Private`"];

(*---calculate the multifractal dimensions---*)
Dq[p_List, r_List] := Block[{l1, l2, listrg = {}},

(*---length of the lists---*)
l1 = Length[p]; l2 = Length[r];
If[l1 == l2,
(*---variation of q and determination of D_q---*)
Do[gl1 = Sum[p[[j]]^q r[[j]]^((q - 1) Dfractal), {j, 1, l1}] - 1;
result = FindRoot[gl1 == 0, {Dfractal, -3, 3}];
result = -Dfractal /. result;
(*---collect the result in a list----*)
AppendTo[listrg, {q, result}], {q, -10, 10, .101}]
,

Print[" "];
Print[" Lengths of lists are different!"];
listrg = {}];
listrg];

(*----calculate Tau---*)
Tau[result_list] := Block[{l1, listtau = {}},
(*----lengths of the lists---*)
l1 = Length[result];
(*---calcultate Tau---*)

Do[AppendTo[
listtau, {result[[k, 1]],
result[[k, 2]] (1 - result[[k, 1]])}], {k, 1, l1}];
listtau];

(*---Legendre transform---*)
Alpha[result_List] :=
Block[{l1, dq, listalpha = {}, listf = {}, listleg = {}, mlist = {},
pl1, pl2},
(*---lengths of the lists---*)

l1 = Length[result];
(*---determine the differential dq---*)
dq = (result[[2, 1]] - result[[1, 1]]) 2;
(*---calculate Alpha by numerical differentiation---*)
Do[AppendTo[
listalpha, {result[[k,
1]], (result[[k + 1, 2]] - result[[k - 1, 2]])/dq}], {k, 2,
l1 - 1}];
l1 = Length[listalpha];
(*---calculate f and collect the result in a list---*)

Do[AppendTo[
listf, {result[[k,
1]], -(result[[k, 1]] listalpha[[k, 2]] - result[[k, 2]])}];
listalpha[[k, 2]] = -listalpha[[k, 2]], {k, 1, 12}];
(*---list of the Legendre transforms---*)
Do[AppendTo[listleg, {listalpha[[k, 2]], listf[[k, 2]]}];
AppendTo[mlist, listf[[k, 2]]], {k, 1, l2}];
(*---plot f and alpha versus q---*)
pl1 = ListLinePlot[listalpha, Joined -> {True, False},
AxesLabel -> {"q", "\[Alpha]"}, Prolog -> Thickness[0.001]];

pl2 = ListLinePlot[listf, Joined -> {True, False},
AxesLabel -> {"q", "f"}, Prolog -> Thickness[0.001]];
Show[{pl1, pl2}, AxesLabel -> {"q", "\[Alpha],f"}];
(*---plot the Legendre transform f versus alpha---*)
ListLinePlot[listleg, AxesLabel -> {"\[Alpha]", "f"}];
(*---print the maximum of f=D_ 0---*)
maxi = Max[mlist];
Print[" "];
Print[" D_0 = ", maxi]];


(*---calcultate the multifractal properties---*)
MultiFractal[p_List, r_List] := Block[{listDq, listTau},
(*---determine D_q---*)
listDq = Dq[p, r];
ListLinePlot[listDq, Joined -> {True, False},
AxesLabel -> {"q", "Dq"}, Prolog -> Thickness[0.001]]
(*---calculate Tau---*)
listTau = Tau[listDq];
ListLinePlot[listTau, Joined -> {True, False},
AxesLabel -> {"q", "\[Tau]"}, Prolog -> Thickness[0.001]]

(*---determine the Hoelder exponent---*)
Alpha[listTau]];

End[];

EndPackage[];

Answer



The code (Importation de la série)


ClearAll["Global`*"]
d = Import[SystemDialogInput["FileOpen"]];

ima = Flatten[d];
ima = ima + 0.000001;
n1 = Length[d];
n2 = Log[2, Length[ima]];
ny = Table[2^i, {i, 3, n2}];

(*Calcul des valeurs Dq pour chaque sous série*)

f[n_] := Module[{xx = ima, d2, stot, freqpuis, somfreqpuis, pq},
d2 = Partition[xx, n];

fmaxmin[x_List] := Mean[x];
stot = Map[fmaxmin, d2] // N;
stot = stot/Total[Flatten[stot]];
freqpuis = Table[stot^j, {j, -7, 7, 0.5}];
somfreqpuis = Total[Transpose[freqpuis]];
pq = Log[2, somfreqpuis]
]

logmuql = Flatten[Table[f[i], {i, ny}]] // N;
logmuqlt = Partition[logmuql, 29];

pqpart = logmuqlt;
logtaille = Log[2, ny] // N;

f2[nn_] :=
Module[{a = logtaille, b = logmuqlt, essai, line, linen, fa1},
essai = Partition[Riffle[logtaille, logmuqlt[[All, nn]]], 2];
line = LinearModelFit[essai, x, x];
linen = Normal[line];
fa1 = linen[[2, 1]] // N
]


Dq = Table[f2[i], {i, 1, 29}];
qq = Table[i, {i, -7, 7, 0.5}];
q = 1/(qq - 1.000001);
Dqq = q*Dq;
kq = 2 - Dqq;
cq = kq*q;
qmoin = qq - 1;
rq = qmoin*Dq;
ecartDq = Dqq[[1]] - Dqq[[29]] // N;

Print["ecart Dq = ", ecartDq]
ListPlot[{pqpart[[All, 1]], pqpart[[All, 5]], pqpart[[All, 10]],
pqpart[[All, 15]], pqpart[[All, 20]], pqpart[[All, 29]]},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"log_tailleboite", "SomPiQ"}, PlotRange -> All,
PlotStyle -> PointSize[Medium]]

dqrel = Dqq - 1;
d3 = Riffle[qq, Dqq];
d6 = Partition[d3, 2];

d6 = Drop[d6, {17}];

ListPlot[{d6},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "Dq"}, PlotRange -> All, PlotStyle -> {Black}]

d3 = Riffle[qq, kq];
d6 = Partition[d3, 2];
d6 = Drop[d6, {17}];


ListPlot[{d6}, ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "Kq"}, PlotRange -> All, PlotStyle -> {Black}]

d3 = Riffle[qq, cq];
d6 = Partition[d3, 2];
d6 = Drop[d6, {17}];
ListPlot[{d6},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "Cq"}, PlotRange -> All, PlotStyle -> {Black}]


d3 = Riffle[qmoin, rq];
d6 = Partition[d3, 2];
d6 = Drop[d6, {17}];
ListPlot[{d6},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "Tauq"}, PlotRange -> All, PlotStyle -> {Black}]

d3 = Riffle[qq, dqrel];
d6 = Partition[d3, 2];
d6 = Drop[d6, {17}];

ListPlot[{d6},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "Dq_Relatif"}, PlotRange -> All,
PlotStyle -> {Black}]

fo[n_] :=
Module[{xx = ima, d2, stot, tfreqpuis, freqpuis, logfreqpuis,
produitfreq, somfproduit4},
d2 = Partition[xx, n];
fmaxmin[x_List] := Mean[x];

stot = Map[fmaxmin, d2] // N;
freqpuis = Table[stot^j, {j, -7, 7, 0.5}];
tfreqpuis = Total[Transpose[freqpuis]];
freqpuis = freqpuis/tfreqpuis;
logfreqpuis = Log[10, freqpuis];
produitfreq = freqpuis*logfreqpuis;
somfproduit4 = Map[Total, produitfreq] // N
]

totlogmuql = Flatten[Table[fo[i], {i, ny}]];

logmuqlt = Partition[totlogmuql, 29];
pqpart = logmuqlt;
logtaille = Log[10, ny] // N;

fo2[nn_] :=
Module[{a = logtaille, b = logmuqlt, essai, line, linen, fa1},
essai = Partition[Riffle[logtaille, logmuqlt[[All, nn]]], 2];
line = LinearModelFit[essai, x, x];
linen = Normal[line];
fa1 = ToExpression[linen[[2, 1]]] // N

]

fqr = Table[fo2[i], {i, 1, 29}];
qq = Table[i, {i, -7, 7, 0.5}];
fq2 = Riffle[qq, fqr];
fq2 = Partition[fq2, 2];

ListPlot[{fq2},
ImageSize -> {300, 200}, Joined -> True,
AxesLabel -> {"q", "f(alpha)q"}, PlotRange -> All,

PlotStyle -> {Black}]
ecartFq = fqr[[29]] - fqr[[1]] // N;
Print["ecart Fq = ", ecartFq]

Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.