.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/simulation/plot_brownian.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_simulation_plot_brownian.py: Simulation of Brownian motion ============================= .. GENERATED FROM PYTHON SOURCE LINES 6-16 .. code-block:: Python # Author: Steven Golovkine # License: MIT # Load packages import numpy as np from FDApy.simulation import Brownian from FDApy.visualization import plot .. GENERATED FROM PYTHON SOURCE LINES 17-18 The package provides a class to simulate different types of Brownian motion using the following classe: :class:`~FDApy.simulation.Brownian`. The type of Brownian motion can be standard, geometric or fractional. .. GENERATED FROM PYTHON SOURCE LINES 18-31 .. code-block:: Python # Set general parameters rng = 42 n_obs = 10 argvals = np.arange(0, 1.01, 0.01) # Set Brownian parameters init_point = 1.0 mu = 1.0 sigma = 0.5 hurst = 0.8 .. GENERATED FROM PYTHON SOURCE LINES 32-45 Standard Brownian motion ------------------------ A standard Brownian motion is a stochastic process define as :math:`\{X_t\}_{t \geq 0}`. The process has the following properties: * :math:`\{X_t\}_{t \geq 0}` is a Gaussian process. * For :math:`s, t \geq 0`, :math:`\mathbb{E}(X_t) = 0` and :math:`\mathbb{E}(X_sX_t) = \min(s, t)`. * The function :math:`t \rightarrow X_t` is continuous with probablity :math:`1`. To simulate a standard Brownian motion, you can use the following code: .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python br = Brownian(name="standard", random_state=rng) br.new(n_obs=n_obs, argvals=argvals, init_point=init_point) _ = plot(br.data) .. image-sg:: /auto_examples/simulation/images/sphx_glr_plot_brownian_001.png :alt: plot brownian :srcset: /auto_examples/simulation/images/sphx_glr_plot_brownian_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-69 Geometric Brownian motion ------------------------- A geometric Brownian motion is a stochastic process :math:`\{X_t\}_{t \geq 0}` in which the logarithm of the randomly varying quantity is a Brownian motion with drift. The process :math:`\{X_t\}_{t \geq 0}` satisfies the following stochastic differential equation: .. math:: dX_t = \mu X_t dt + \sigma X_t dW_t where :math:`\{W_t\}_{t \geq 0}` is a Brownian motion, :math:`\mu` is the percentage drift and :math:`\sigma` is the percentage volatility. To simulate a geometric Brownian motion, you can use the following code: .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: Python br = Brownian(name="geometric", random_state=rng) br.new(n_obs=n_obs, argvals=argvals, init_point=init_point, mu=mu, sigma=sigma) _ = plot(br.data) .. image-sg:: /auto_examples/simulation/images/sphx_glr_plot_brownian_002.png :alt: plot brownian :srcset: /auto_examples/simulation/images/sphx_glr_plot_brownian_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 76-96 Fractional Brownian motion -------------------------- A fractional Brownian motion is a stochastic process :math:`\{X_t\}_{t \geq 0}` that generalize Brownian motion. Let :math:`H \in (0, 1)` be the Hurst parameter. The process has the following properties: * :math:`\{X_t\}_{t \geq 0}` is a Gaussian process. * For :math:`s, t \geq 0`, :math:`\mathbb{E}(X_t) = 0` and :math:`\mathbb{E}(X_sX_t) = \frac{1}{2}\left(|s|^{2H} + |t|^{2H} - |s - t|^{2H}\right)`. * The function :math:`t \rightarrow X_t` is continuous with probablity :math:`1`. The value of :math:`H` defines the process. If :math:`H = 1/2`, :math:`\{X_t\} _{t \geq 0}` is a Brownian motion. If :math:`H > 1/2`, the increments of :math:`\{X_t\}_{t \geq 0}` are positively correlated. If :math:`H < 1/2`, the increments of :math:`\{X_t\}_{t \geq 0}` are negatively correlated. To simulate a fractional Brownian motion, you can use the following code: .. GENERATED FROM PYTHON SOURCE LINES 96-100 .. code-block:: Python br = Brownian(name="fractional", random_state=rng) br.new(n_obs=n_obs, argvals=argvals, hurst=hurst) _ = plot(br.data) .. image-sg:: /auto_examples/simulation/images/sphx_glr_plot_brownian_003.png :alt: plot brownian :srcset: /auto_examples/simulation/images/sphx_glr_plot_brownian_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.279 seconds) .. _sphx_glr_download_auto_examples_simulation_plot_brownian.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_brownian.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_brownian.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_brownian.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_