.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples\savings\plot_ex1_rand.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_savings_plot_ex1_rand.py: Account value distribution =========================================== 10,000 random numbers drawn from the standard normal distribution are generated for each time step. The graph shows how well the 10,000 random numbers for ``t=0`` fit the PDF of the standard normal distribution. .. GENERATED FROM PYTHON SOURCE LINES 11-30 .. code-block:: default import modelx as mx import pandas as pd import matplotlib.pyplot as plt from scipy.stats import norm, lognorm import numpy as np model = mx.read_model("CashValue_ME_EX1") rand_nums = model.Projection.std_norm_rand() pv_avs = model.Projection.pv_claims_from_av('MATURITY') num_bins = 100 S0 = 45000000 sigma = 0.03 T = 10 fig, ax = plt.subplots() n, bins, patches = ax.hist(rand_nums[:, 0], bins=num_bins, density=True) ax.plot(bins, norm.pdf(bins), '-') fig.suptitle('Standard normal distribution for t=0') .. image-sg:: /generated_examples/savings/images/sphx_glr_plot_ex1_rand_001.png :alt: Standard normal distribution for t=0 :srcset: /generated_examples/savings/images/sphx_glr_plot_ex1_rand_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 31-47 The distibution of the account value at ``t=120`` follows a log normal distribution. In the expression below, :math:`S_{T}` and :math:`S_{0}` denote the account value at ``t=T=120`` and ``t=0`` respectively. .. math:: \ln\frac{S_{T}}{S_{0}}\sim\phi\left[\left(r-\frac{\sigma^{2}}{2}\right)T, \sigma\sqrt{T}\right] The graph shows how well the distribution of :math:`e^{-rT}S_{T}`, the present values of the account value at `t=0`, fits the PDF of a log normal ditribution. Reference: *Options, Futures, and Other Derivatives* by John C.Hull .. seealso:: * :doc:`/libraries/savings/savings_example1` notebook in the :mod:`~savings` library .. GENERATED FROM PYTHON SOURCE LINES 47-56 .. code-block:: default fig, ax = plt.subplots() n, bins, patches = ax.hist(pv_avs, bins=num_bins, density=True) ax.plot(bins, lognorm.pdf(bins, sigma * T**0.5, scale=S0), '-') fig.suptitle('PV of account value at t=120') .. image-sg:: /generated_examples/savings/images/sphx_glr_plot_ex1_rand_002.png :alt: PV of account value at t=120 :srcset: /generated_examples/savings/images/sphx_glr_plot_ex1_rand_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.304 seconds) .. _sphx_glr_download_generated_examples_savings_plot_ex1_rand.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ex1_rand.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ex1_rand.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_