Skip to content

Instantly share code, notes, and snippets.

Created January 28, 2022 09:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Share Value Post-IPO
This script will tell you the stock price of a stock following its ipo, normalized for value
import quandl
import matplotlib.pyplot as plt
import pandas
import yfinance as yf
quandl.ApiConfig.api_key = '' #put your key here
lowestPointFromDay ={}
def normalize_data(currStock, df):
# df on input should contain only one column with the price data (plus dataframe index)
min = df.min()
max = df.max()
x = df
# time series normalization part
# y will be a column in a dataframe
y = (x - min) / (max - min)
return y
def createChart(currStock):
msft = yf.Ticker(currStock)
# get historical market data
Apple_EOD = msft.history(period="max")
aapl = Apple_EOD[["Close"]]
aapl = aapl.reset_index()
aapl = aapl.iloc[1:]
#number of days after start to prune
aapl = aapl.drop(aapl.index[720:aapl.size])
#normalize the first chunk of days since ipo
aapl["Norm"] = normalize_data(currStock, aapl['Close'])
#find smallest day
appl_smallest = aapl.nsmallest(1, 'Norm')
lowestPointFromDay[currStock] = appl_smallest
plt.plot( aapl["Norm"], label=currStock)
stocks = ['AAPL', 'MSFT', 'UBER', 'TWTR', 'TEAM', 'WORK', 'PINS', 'DRII', 'BKNG','EXPE', 'FB']
for stock in stocks:
for key,value in lowestPointFromDay.items():
print(key + ":" + str(value))
plt.legend(loc="upper right")
plt.xlabel('Days Since IPO')
plt.axvspan(90, 180, color='red', alpha=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment