<jupyter_start><jupyter_text>Check IPOs Check a list of IPOs (or any list of symbols) against wood's algorigthm.This will calculate the last 6 months, 3 months, 1 month and 2 weeks average returns on the stock.I'm looking for down for 6 and 3 months and up for 1 to two weeks.<jupyter_code>import csv
import datetime
import pandas as pd
import yfinance as yf


#some constants
days_in_year = 365
six_months_days = int(days_in_year / 2)
thirty_day = 30
two_weeks_day = 14
# open the list of ipo symbols
filename = "202008_yearipos.csv"
ipos = []
with open(filename, newline='') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        ipos.append(row)
# just use the last one as a test if needed. Otherwise keep it commented out
#ipos = [ipos[-1]]
ipos
# for each symbol, get the history, calculate the first six months of perf, the last six months, 30 and 14 days
ipo_performance = []
for stock in ipos:
    sym = stock['symbol']
    print(f"checking sym: {sym}")
    info = yf.Ticker(sym)
    df_history = info.history(period="max")
    
    first_trade = df_history.index[0]
    open_price = df_history.iloc[0]['Open']
    
    # prepend the opening prices as the previous day's close...
    all_prices = df_history['Close']
    all_prices = pd.concat([pd.Series([open_price]),all_prices])

    first_six = all_prices.head(six_months_days)
    last_six = all_prices.tail(six_months_days)
    
    start_price = first_six.iloc[0]
    end_price = first_six.iloc[-1]
    f6_gain_loss = (end_price - start_price) / start_price
    
    start_price = last_six.iloc[0]
    end_price = last_six.iloc[-1]
    l6_gain_loss = (end_price - start_price) / start_price
    
    last_30 = all_prices.tail(thirty_day)
    start_price = last_30.iloc[0]
    end_price = last_30.iloc[-1]
    l30_gain_loss = (end_price - start_price) / start_price
    
    last_14 = all_prices.tail(thirty_day)
    start_price = last_30.iloc[0]
    end_price = last_30.iloc[-1]
    l14_gain_loss = (end_price - start_price) / start_price
    
    ipo_performance.append({"symbol":sym,
                            "name":stock['name'],
                            "ipo_date":first_trade,
                            "open_price":open_price, 
                            "First Six Perf":f6_gain_loss,
                            "Last Six Perf":l6_gain_loss,
                            "Last 30 Perf": l30_gain_loss,
                            "Last 14 Perf": l14_gain_loss})



# need a year/month string for the file name output
now = datetime.date.today()
filename = "{}_ipo_perf.csv".format(now.strftime("%Y%m"))

# save as a csv 
with open(filename, 'w',newline="") as csvfile:
    writer = csv.DictWriter(csvfile, fieldnames=ipo_performance[0].keys())
    writer.writeheader()
    for data in ipo_performance:
        writer.writerow(data)<jupyter_output><empty_output><jupyter_text>scratch pad below this<jupyter_code>df_history = info.history(period="max")
all_prices = df_history['Close']
# prepend the opening price as the previous "close" price
all_prices = pd.concat([pd.Series([first_price]),all_prices])
all_prices
# calculate the difference between the starting price and ending price
start_price = first_six.iloc[0]
end_price = first_six.iloc[-1]
gain_loss = (end_price - start_price) / start_price
gain_loss
type(df_history)
df_history
df_history.iloc[0]
type(df_history.iloc[0])
df_history.iloc[0].index
df_history.index[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10280103956107421, 'fraction_numerical': 0.020502454519203003, 'mean_word_length': 3.3245942571785267, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '421693', 'license': 'Apache-2.0', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1176, 'n_words': 293, 'path': 'Check IPO List.ipynb', 'repo_name': 'Dannyaffleck/stock', 'size': '3463'}