Created
September 9, 2021 00:27
-
-
Save marcosan93/ffed07f9c73984ed96ef515f03d91f0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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