.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_ch9\ch9_get_market_data.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_ch9_ch9_get_market_data.py: ==================================================================================================== 9.01 Free time series modeling ==================================================================================================== We reproduce here the figure 9.1 of the book, showcasing how to download data an plot the charts for the three selected stocks. .. GENERATED FROM PYTHON SOURCE LINES 9-11 Necessary Imports ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 11-34 .. code-block:: Python import os import sys import matplotlib.pyplot as plt import numpy as np try: CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) except NameError: CURRENT_DIR = os.getcwd() PARENT_DIR = os.path.abspath(os.path.join(CURRENT_DIR, "..")) sys.path.insert(0, PARENT_DIR) from utils.ch9.data_utils import df_summary from utils.ch9.market_data import retrieve_market_data try: current_dir = os.path.dirname(__file__) data_path = os.path.join(current_dir, "data") except NameError: current_dir = os.getcwd() data_path = os.path.join(current_dir, "data") .. GENERATED FROM PYTHON SOURCE LINES 35-37 Parameter definition ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 37-53 .. code-block:: Python def get_cdpres_param(): return { "rescale_kernel": {"max": 2000, "seed": None}, "rescale": True, "grid_projection": True, "reproductibility": False, "date_format": "%d/%m/%Y", "begin_date": "01/06/2020", "end_date": "01/06/2022", "today_date": "01/06/2022", "symbols": ["AAPL", "GOOGL", "AMZN"], } .. GENERATED FROM PYTHON SOURCE LINES 54-58 Getting the market data ------------------------------------------------ We call the graphic function created inside the parameters by the `retrieve_market_data` method. This displays the historical data for the selected stocks and date range. .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python params = retrieve_market_data() params["graphic"](params) plt.show() print(df_summary(np.log(params["data"] / params["data"].shift(1)).dropna())) .. image-sg:: /auto_ch9/images/sphx_glr_ch9_get_market_data_001.png :alt: ch9 get market data :srcset: /auto_ch9/images/sphx_glr_ch9_get_market_data_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Mean Variance Skewness Kurtosis AAPL 0.001241 -0.069257 0.000402 1.954392 AMZN -0.000030 -0.437657 0.000501 6.702824 GOOGL 0.000915 -0.090485 0.000326 1.393784 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.059 seconds) .. _sphx_glr_download_auto_ch9_ch9_get_market_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ch9_get_market_data.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ch9_get_market_data.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ch9_get_market_data.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_