
Bernt Øksendal의 교과서 표지에 있는 브라운 운동 플롯을 복제하려고 합니다.확률적 미분 방정식LaTeX를 사용합니다.
나는 코딩에서 약간 길을 잃었습니다. 수학은 필요하지 않습니다. 비슷한 주제를 찾아봤습니다(브라운 운동 - 중복), 그러나 이들 중 어느 것도 플롯에 E[X_t] 선이 없었습니다. 또한 브라운 운동 궤적(교과서 표지 플롯과 달리 일부는 음수로 들어가기 때문에)과 x 및 y축 라벨링을 수정하는 방법을 확신하지 못했습니다.
나의 시도
\documentclass[12pt, a4paper]{article} %uploading the libraries
\usepackage{pgfplots, pgfplotstable}
\usepackage[font=small,labelfont=bf,labelsep=colon]{caption}
\begin{document}
\pgfmathsetseed{5}
% creating the Brownian motion trajectories
\pgfplotstablenew[
create on use/randwalk1/.style={
create col/expr accum={\pgfmathaccuma + 0.1*rand}{0}
},
create on use/randwalk2/.style={
create col/expr accum={\pgfmathaccuma + 0.1*rand}{0}
},
create on use/randwalk3/.style={
create col/expr accum={\pgfmathaccuma + 0.1*rand}{0}
},
create on use/randwalk4/.style={
create col/expr accum={\pgfmathaccuma + 0.1*rand}{0}
},
create on use/randwalk5/.style={
create col/expr accum={\pgfmathaccuma + 0.1*rand}{0}
},
columns={randwalk1,randwalk2,randwalk3,randwalk4,randwalk5}
]
{700}
% adjusting the plot axes and titles
\loadedtable
\begin{figure}[H]
\caption{Brownian Motion}
\centering
\begin{tikzpicture}
\begin{axis}[
legend pos=outer north east,
axis y line=left,
axis x line=middle,
xlabel= {\scriptsize $t$},
ylabel = {\scriptsize $X_{t}$},
ylabel style = {yshift=-12pt},
xticklabels={,,},
yticklabels={,,},
tick style={draw=none},
line join=bevel,
no markers,
table/x expr={\coordindex/100},
xmin=0,
ymin=-0.5, ymax=3,
enlarge x limits=false
% now, putting it all together
]
\addplot table [y expr={max(\thisrow{randwalk1},-5.0)}] {\loadedtable};
\addplot table [y expr={min(\thisrow{randwalk2},5.0)}] {\loadedtable};
\addplot table [y expr={min(\thisrow{randwalk3},5.0)}] {\loadedtable};
\addplot table [y expr={min(\thisrow{randwalk4},5.0)}] {\loadedtable};
\addplot table [y expr=\thisrow{randwalk5}] {\loadedtable};
\draw (axis cs:5,5) (axis cs:5,-5);
\legend {{\footnotesize $X_t(\omega_1)$}, {\footnotesize $X_t(\omega_2)$}, {\footnotesize $X_t(\omega_3)$},{\footnotesize $X_t(\omega_4)$},{\footnotesize $X_t(\omega_5)$}};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
답변1
문제는 rand
에서 일반적인 무작위 값이 아닌 pgf
균일하게 분포된 무작위 값을 생성한다는 것입니다. [-1,1]
따라서 다음 코드는 엄밀히 말하면 GBM을 표시하지 않습니다. 그러나 이는 GBM 플롯과 유사해 보입니다. 0.003
궤도가 원래 그림과 유사하게 증가할 가능성을 높이기 위해 지수에 약간의 드리프트도 추가했음을 알 수 있습니다 . 그리고 rand
는 균일하기 때문에 저는 E(exp(0.003+0.1*rand))=exp(0.003)*5*(exp(0.1)-exp(-0.1))
이 표현식을 계산하고 사용하여 기대치를 표시했습니다.
\documentclass[12pt, a4paper]{article} %uploading the libraries
\usepackage{pgfplots, pgfplotstable}
\usepackage[font=small,labelfont=bf,labelsep=colon]{caption}
\begin{document}
\pgfmathsetseed{5}
% creating the Brownian motion trajectories
\pgfplotstablenew[
create on use/randwalk1/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003+0.1*rand)}{1}
},
create on use/randwalk2/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003+0.1*rand)}{1}
},
create on use/randwalk3/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003+0.1*rand)}{1}
},
create on use/randwalk4/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003+0.1*rand)}{1}
},
create on use/randwalk5/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003+0.1*rand)}{1}
},
create on use/expectation/.style={
create col/expr accum={\pgfmathaccuma * exp(0.003)*5*(exp(0.1)-exp(-0.1))}{1}
},
columns={randwalk1,randwalk2,randwalk3,randwalk4,randwalk5,expectation}
]
{700}
% adjusting the plot axes and titles
\loadedtable
\begin{figure}[h]
\caption{Brownian Motion}
\centering
\begin{tikzpicture}
\begin{axis}[
legend pos=outer north east,
axis y line=left,
axis x line=middle,
xlabel={\scriptsize $t$},
ylabel={\scriptsize $X_{t}$},
ylabel style={yshift=-12pt},
xticklabels={,,},
yticklabels={,,},
tick style={draw=none},
line join=bevel,
no markers,
table/x expr={\coordindex/100},
xmin=0,
ymin=0,
enlarge x limits=false
]
\addplot table [y expr=\thisrow{randwalk1}] {\loadedtable};
\addplot table [y expr=\thisrow{randwalk2}] {\loadedtable};
\addplot table [y expr=\thisrow{randwalk3}] {\loadedtable};
\addplot table [y expr=\thisrow{randwalk4}] {\loadedtable};
\addplot table [y expr=\thisrow{randwalk5}] {\loadedtable};
\addplot table [y expr=\thisrow{expectation}] {\loadedtable};
\draw (axis cs:5,5) (axis cs:5,-5);
\legend {{\footnotesize $X_t(\omega_1)$},
{\footnotesize $X_t(\omega_2)$},
{\footnotesize $X_t(\omega_3)$},
{\footnotesize $X_t(\omega_4)$},
{\footnotesize $X_t(\omega_5)$},
{\footnotesize $E[X_t]$}};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}