Skip to content

Instantly share code, notes, and snippets.

@cordmaur
Last active January 18, 2021 22:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cordmaur/2ed352268a1a193bc62d7e661f0cb81a to your computer and use it in GitHub Desktop.
Save cordmaur/2ed352268a1a193bc62d7e661f0cb81a to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import yfinance as yf
# Load the forecasts
forecasts = pd.read_csv('sp500_forecasts_new.csv', header=None).rename(columns={0: 'Date', 1: 'Signal'})
forecasts.set_index('Date', inplace=True)
forecasts.index = pd.to_datetime(forecasts.index)
# load the SP500 df
df = yf.Ticker('^GSPC').history(period='max')
df = df[(df.index > '1952-01-03') & (df.index < '2020-12-30')]
# save the strategy signal
df['Signal'] = forecasts['Signal']
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment