Created
January 28, 2022 09:23
-
-
Save EdbertChan/1b98b75b03db83b10a2955f2d4ccb543 to your computer and use it in GitHub Desktop.
Share Value Post-IPO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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: | |
createChart(stock) | |
for key,value in lowestPointFromDay.items(): | |
print(key + ":" + str(value)) | |
plt.legend(loc="upper right") | |
plt.xlabel('Days Since IPO') | |
plt.ylabel('Normalized') | |
plt.axvspan(90, 180, color='red', alpha=0.5) | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment