{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Irrational Exuberance? S&P vs Bitcoin...\nWhilst reading the magnificent book [\"*Irrational Exuberance*\"](https://press.princeton.edu/books/paperback/9780691173122/irrational-exuberance) by Nobel Prize winning economist [Robert J. Shiller](https://www.nobelprize.org/prizes/economic-sciences/2013/shiller/facts/) I was struck by the the very first figure (Figure 1.1) in his book, and decided to plot it alongside the current Bitcoin data. The inflation-corrected S&P data was obtained from a [dataset](http://www.econ.yale.edu/~shiller/data.htm) that Robert Shiller kindly provides on his web site.","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\nplt.rcParams.update({'font.size': 18})\nplt.style.use('fivethirtyeight')\nfrom datetime import date\n\n# for the excel spreadsheet\n!pip install -q xlrd\n\n# install the Yahoo! Finance market data downloader\n# see: https://github.com/ranaroussi/yfinance\n!pip -q install yfinance\nimport yfinance as yf\n\n# read in the S&P data\n!wget --quiet www.econ.yale.edu/~shiller/data/ie_data.xls\nie_data = pd.read_excel(\"ie_data.xls\", sheet_name=\"Data\", skiprows=7, parse_dates=['Date'], index_col=0)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-11-22T13:39:45.558173Z","iopub.execute_input":"2021-11-22T13:39:45.558707Z","iopub.status.idle":"2021-11-22T13:40:14.285718Z","shell.execute_reply.started":"2021-11-22T13:39:45.558602Z","shell.execute_reply":"2021-11-22T13:40:14.284562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"date_range = ie_data.loc['1871-01-01':'2010-01-01']\nfig, ax = plt.subplots(figsize=(15, 6))\nS_and_P = pd.Series(date_range.Price)\nax.set_xlabel (\"Date\", fontsize=18)\nax.set_ylabel (\"S&P price (USD)\", fontsize=18);\nS_and_P.plot(lw=1)\nax.set_title (\"Inflation-corrected S&P Composite Stock Price Index: 1871 to 2010\", fontsize=18)\nplt.show();","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-11-22T13:40:14.287479Z","iopub.execute_input":"2021-11-22T13:40:14.287927Z","iopub.status.idle":"2021-11-22T13:40:14.649150Z","shell.execute_reply.started":"2021-11-22T13:40:14.287851Z","shell.execute_reply":"2021-11-22T13:40:14.647942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# obtain the Bitcoin ticker in USD\nbitCoinUSD = yf.Ticker(\"BTC-USD\")\n# save the historical market data to a pandas dataframe\nbitCoinUSD_values = bitCoinUSD.history(start=\"2015-01-01\")\n# plot the 'High' value\nfig, ax = plt.subplots(figsize=(15, 6))\nbitcoin = pd.Series(bitCoinUSD_values['High'])\nax.set_xlabel (\"Date\", fontsize=18)\nax.set_ylabel (\"Bitcoin price (USD)\", fontsize=18);\nbitcoin.plot(lw=1)\nax.set_title (\"Daily Bitcoin prices from 2015 up to today\", fontsize=18)\nplt.show();","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-11-22T13:40:14.651285Z","iopub.execute_input":"2021-11-22T13:40:14.651909Z","iopub.status.idle":"2021-11-22T13:40:16.160068Z","shell.execute_reply.started":"2021-11-22T13:40:14.651857Z","shell.execute_reply":"2021-11-22T13:40:16.158087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Related reading\n* [Robert J. Shiller \"*Irrational Exuberance*\" Revised and Expanded Third Edition, Princeton University Press (2016)](https://press.princeton.edu/books/paperback/9780691173122/irrational-exuberance)\n* [Robert J. Shiller \"*Speculative Asset Prices*\", Nobel Prize Lecture (2013)](https://www.nobelprize.org/uploads/2018/06/shiller-lecture.pdf)","metadata":{}}]}