Ratio-Of-Uniforms Methode

AKVFM Numerische Methoden der Finanz- und Versicherungsmathematik

SS 2006, Reinhold Kainhofer, FAM, TU Wien

Ratio of uniforms, allgemeine Definition

<<Histograms`

Definition des Bereichs A:

matches[{x_,y_},f_]:=(0.0001<x&& x≤(Sqrt[f[(y/x)]]));
bnd[x_, f_]:={(Sqrt[f[x]]), x(Sqrt[f[x]])}

ROU fuer Normalverteilung

fNV01[x_]:=(1/(Sqrt[2π]))Exp[((-(x^2))/2)]
ParametricPlot[bnd[x, fNV01], {x, -10,10}, AspectRatio->1]

Mit 10000 Zufallszahlen:

selectedMC={};normalNrsMC={};
While[Length[selectedMC]<10000, 
{u,v}={0.7RandomReal[],1.2RandomReal[]-0.6};
If[matches[{u,v},fNV01], AppendTo[selectedMC, {u,v}];AppendTo[normalNrsMC, v/u]];
]

ListPlot[selectedMC, Frame->True, AspectRatio->1]

hist=Histogram[normalNrsMC,HistogramScale->1, DisplayFunction->Identity];
densplot=Plot[fNV01[x], {x, -5, 5}, DisplayFunction->Identity];
Show[{densplot,hist, densplot}, DisplayFunction->$DisplayFunction]

ROU fuer Exponentialverteilung

fExp[x_]:=Exp[-x]

ParametricPlot[bnd[x, fExp], {x, 0,5000}, PlotPoints->500, PlotRange->All]

selectedMC={}; nrsMC={};
While[Length[selectedMC]<5000, 
{u,v}={ RandomReal[],(2/E) RandomReal[]};
If[matches[{u,v},fExp], AppendTo[selectedMC, {u,v}];AppendTo[nrsMC, v/u]];
]

ListPlot[selectedMC, Frame->True]

hist=Histogram[nrsMC,HistogramScale->1, PlotRange->{{0,5},{0,1}} , DisplayFunction->Identity];
densplot=Plot[fExp[x], {x, 0, 5}, DisplayFunction->Identity];
Show[{hist, densplot}, DisplayFunction->$DisplayFunction]

ROU fuer IG

fIG[x_]:=δ ((Exp[δ γ])/(Sqrt[2π]))(x^(-3/2))Exp[((-1)/2)((δ^2)(1/x)+(γ^2)x)];

δ=1;γ=1;
ParametricPlot[bnd[x, fIG], {x, 0,50}, PlotPoints->500, PlotRange->All, AspectRatio->1]

δ=1;γ=1;
selectedMC={};nrsMC={};
While[Length[selectedMC]<10000, 
{u,v}={ 1.2 RandomReal[],0.8(RandomReal[])};
If[matches[{u,v},fIG], AppendTo[selectedMC, {u,v}];AppendTo[nrsMC, v/u]];
]

ListPlot[selectedMC, Frame->True, AspectRatio->1]

hist=Histogram[nrsMC,HistogramScale->1, PlotRange->{{0,5},{0,1}} , DisplayFunction->Identity];
densplot=Plot[fIG[x], {x, 0, 5}, DisplayFunction->Identity];
Show[{hist, densplot}, DisplayFunction->$DisplayFunction]