# Compares time series growth rate
# Steps:
# 1. Divide the whole series with the first value
# 2. Then multiply the whole series with 100. Now you see the growth rate from initial point to some other point in percentage
# 3. Do the same for another series
# 4. Stack the series together
# 5. Drop any missing values in the new dataframe
# 6. Visualize the dataframe to see comparative performance
# 7. Create new dataframe by subtracting benchmark series (eg : SP500) from the existing dataframe
# 8. Visualize the dataframe to see only the comparative performance relative to the benchmark
# Compare multiple time series with each other
google_df = pd.read_csv('google.csv', parse_dates=['date'], index_col='date')
first_price = google_df.price.iloc[0]
normalized_google = google_df.price.div(first_price).mul(100)
stacked_df = pd.concat([normalized_google,normalized_msft], axis=1)
stacked_df = stacked_df.dropna()
stacked_df.plot()
# Compare multiple time series with each other using a benchmark
benchmark = pd.read_csv('sp500.csv', parse_dates=['date'], index_col='date')
Performance_df = stacked_df.sub(benchmark, axis=0)
Performance_df.plot()