My New Udemy Class: Fundamental Market Analysis with Python

Fundamental Market Analysis with Python

Fundamental Market Analysis with Python - Find Your Own Answers On What Is Going on in the Financial Markets

Hot off the Press!

The Little Book of Fundamental Market Indicators

My New Book: "The Little Book of Fundamental Analysis: Hands-On Market Analysis with Python" is Out!

Grow Your Web Brand, Visibility & Traffic Organically

The Little Book of Fundamental Market Indicators

5 Years of amunategui.github.Io and the Lessons I Learned from Growing My Online Community from the Ground Up

Let's plot the VIX, The Fear Index, From Scratch!

Introduction

It's sitting right at the teens - that usually means the markets are calm and orderly. Let's roll up our sleeves, download some data and visualize this using Python. I'll briefly discuss what the Vix is after we get our plot up and running for those that are in a hurry.

Code

ViralML-Hands-On-Market-Analysis-The-VIX-From-Scratch
In [7]:
from IPython.display import Image
Image(filename='viralml-book.png')
Out[7]:
In [8]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import io, base64, os, json, re 
import pandas as pd
import numpy as np
import datetime
import warnings
warnings.filterwarnings('ignore')
In [18]:
path_to_market_data = '/Users/manuel/Documents/financial-research/market-report/2019-07-06/'
In [21]:
sp500_df = pd.read_csv(path_to_market_data + '^GSPC.csv')
sp500_df['Date'] = pd.to_datetime(sp500_df['Date'])
sp500_df = sp500_df[['Date', 'Adj Close']]
sp500_df.columns = ['Date', 'SP500_Close']
print(np.min(sp500_df['Date'] ),np.max(sp500_df['Date'] ))
sp500_df = sp500_df.sort_values('Date', ascending=True)
sp500_df.tail()
1950-01-03 00:00:00 2019-07-03 00:00:00
Out[21]:
Date SP500_Close
17483 2019-06-27 2924.919922
17484 2019-06-28 2941.760010
17485 2019-07-01 2964.330078
17486 2019-07-02 2973.010010
17487 2019-07-03 2995.820068
In [22]:
vix_df = pd.read_csv(path_to_market_data + '^VIX.csv')
vix_df['Date'] = pd.to_datetime(vix_df['Date'])
vix_df = vix_df[['Date', 'Adj Close']]
vix_df.columns = ['Date', 'VIX_Close']
print(np.min(vix_df['Date'] ),np.max(vix_df['Date'] ))
vix_df = vix_df.sort_values('Date', ascending=True)
vix_df.tail()
1990-01-02 00:00:00 2019-07-03 00:00:00
Out[22]:
Date VIX_Close
7429 2019-06-27 15.82
7430 2019-06-28 15.08
7431 2019-07-01 14.06
7432 2019-07-02 12.93
7433 2019-07-03 12.57
In [31]:
vix_df_tmp = vix_df.copy()
sp500_df_tmp = sp500_df.copy()

cut_off_date = '1990-01-01'
vix_df_tmp = vix_df_tmp[vix_df_tmp['Date'] > cut_off_date]
sp500_df_tmp = sp500_df_tmp[sp500_df_tmp['Date'] > cut_off_date]

fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(vix_df_tmp['Date'],vix_df_tmp['VIX_Close'], color='red', label='VIX')
plt.legend(loc='lower right')
plt.axhline(13, color='blue', linewidth=3, linestyle='-.' )
plt.title('VIX & SP500 - ' + str(np.max(vix_df_tmp['Date']))[0:10])
plt.grid()

ax2 = ax.twinx()
plt.plot(sp500_df_tmp['Date'],sp500_df_tmp['SP500_Close'], color='black', 
         label='SP500_Close')
plt.legend(loc='lower left')
plt.show()

Show Notes

(pardon typos and formatting -
these are the notes I use to make the videos)

It's sitting right at the teens - that usually means the markets are calm and orderly. Let's roll up our sleeves, download some data and visualize this using Python. I'll briefly discuss what the Vix is after we get our plot up and running for those that are in a hurry.