Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created September 9, 2021 00:27
Show Gist options
  • Select an option

  • Save marcosan93/ffed07f9c73984ed96ef515f03d91f0e to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/ffed07f9c73984ed96ef515f03d91f0e to your computer and use it in GitHub Desktop.
def getStockPrices(ticker, start, end):
"""
Gets the historical daily prices between two dates. Scaling the prices based on a
given sentiment dataframe.
"""
# Setting the stock
stock = yf.Ticker(ticker)
# Getting historical prices
stock_df = stock.history(start=end, end=start, interval="1d")[['Close']]
# Getting the daily percent returns
stock_df = stock_df.pct_change(1).dropna()
# Some reformatting
stock_df = stock_df.reset_index().rename(
columns={
"Date": "date",
"Close": "returns"
}
)
return stock_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment