Criando um gráfico de movimento browniano com muitas trajetórias, incluindo o valor esperado

Criando um gráfico de movimento browniano com muitas trajetórias, incluindo o valor esperado

Estou tentando replicar o enredo do movimento browniano encontrado na capa do livro de Bernt ØksendalEquações Diferenciais Estocásticasusando LaTeX.

insira a descrição da imagem aqui

Estou um pouco perdido na codificação. Nenhuma matemática é necessária. Procurei um tópico semelhante (Movimento browniano - duplicado), mas nenhum deles tinha uma linha E[X_t] no gráfico. Além disso, eu não tinha certeza de como corrigir as trajetórias do movimento browniano (já que algumas delas ficam negativas, ao contrário do gráfico da capa do livro) e a rotulagem dos eixos x e y.

Minha tentativa

insira a descrição da imagem aqui

    \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}

Responder1

O problema é que randin pgfgera um valor aleatório uniformemente distribuído [-1,1], e não um valor aleatório normal. Portanto, o código a seguir não plota um GBM, estritamente falando. Mas é semelhante a um gráfico GBM. Você pode ver que também adicionei algum desvio 0.003no expoente para tornar as trajetórias mais prováveis ​​de aumentar de forma semelhante à figura original. E como randé uniforme, calculei E(exp(0.003+0.1*rand))=exp(0.003)*5*(exp(0.1)-exp(-0.1))e usei esta expressão para representar graficamente a expectativa.

\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}

insira a descrição da imagem aqui

informação relacionada