Last active
October 17, 2024 17:39
-
-
Save scubamut/0db58aafc737ec8bed5c81855bb0f24b 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
| import pandas as pd | |
| import yfinance as yf | |
| etf = 'SPY' | |
| # etf = 'QQQ | |
| trend = "downtrend" | |
| # trend = "uptrend" | |
| window = 30 | |
| year = 2024 | |
| start_date = '2019-01-01' | |
| end_date = '2024-10-01' | |
| data = yf.download(etf, start=start_date, end=end_date) | |
| filtered_data = data['Adj Close'].to_frame('close_price') | |
| filtered_data.index.names = ['period'] | |
| # print(filtered_data) | |
| trends_detected = pytrendseries.detecttrend(filtered_data, trend=trend, window=window) | |
| pytrendseries.vizplot.plot_trend(filtered_data, trends_detected, trend, year) |
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
| # for a specific year | |
| yr = 2019 | |
| df = trends_detected | |
| trends = pd.DataFrame([df.iloc[i] for i in range(len(df)) if df.iloc[i]['from'].year==yr ]) | |
| trends | |
| trends_detected = pytrendseries.detecttrend(filtered_data, trend=trend, window=window) | |
| pytrendseries.vizplot.plot_trend(filtered_data, trends_detected, trend, year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment