I tried using the INTRADAY information but it does not go back far enough in time to be useful. So I wrapped up my options script by adding command line arguments. Now you can use it for your own stock symbol and create your own bins. For my next post I will move on to something else.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 7 07:11:46 2019
@author: Tom
Obtain the last 100 days of stock market data on the ticker symbol SPY
and compute the change in price from close to close. Then eliminate the
days that are not options expiration days and build a 7 bin histogram
"""
import argparse
import pandas as pd # Series objects
import numpy as np # Numerical recipes
import matplotlib.pyplot as plt # To display plots
import seaborn as sns # Sweet plotting package
import alphavantage as av # My personal alphavantage library
from scipy.stats import norm # Just me drawing a superimposed normal curve
parser = argparse.ArgumentParser()
parser.add_argument( "symbol" )
args = parser.parse_args()
# A little warning here, this is just to prove that indeed the data is not
# normal. I do not expect it to behave as a normal distribution over the period
# in question. I only go back 100 days because that is what the compact size
# gets you but also anything before that is unlikely to mean much.
# Get your own API KEY from the website
full = av.getSeries( args.symbol, 'GETYOUROWN' )
# Convert the json data into a pandas dataframe
s = av.getDailyClosingPrices( full.json() )
# Compute the change in price from previous close to this close.
day_to_day = pd.Series( [s[n] - s[n-1] for n in range(1,len(s) )], s.index[1:len(s)] )