This notebook is updated three times daily. Cheers.
import pandas as pd
import numpy as np
import yfinance as yf
import mplfinance as mpf
from datetime import datetime
from wallstreet import get_moving_averages, get_sp500_sector_components, get_daily_returns
n=50
# Parameters
n = 50
n=n*-1
sectors = get_sp500_sector_components()
datetime.now()
datetime.datetime(2024, 9, 6, 15, 7, 5, 839648)
s = [i['symbol'] for i in sectors]
daily_returns = get_daily_returns(s)
pd.options.display.float_format = '{:.2f}'.format
daily_returns.sort_values(by='percent change',ascending=False).set_index('ticker').transpose()
ticker | xlre | xlp | xlv | xlu | xli | xle | xlb | xlf | xlc | xly | xlk |
---|---|---|---|---|---|---|---|---|---|---|---|
name | |||||||||||
previous_close | 43.63 | 83.16 | 154.48 | 76.64 | 127.18 | 87.10 | 91.04 | 44.95 | 85.56 | 187.13 | 209.35 |
current_price | 43.63 | 82.98 | 153.99 | 75.94 | 125.91 | 86.02 | 89.89 | 44.31 | 83.76 | 182.40 | 203.99 |
percent change | 0.00 | -0.22 | -0.32 | -0.91 | -1.00 | -1.24 | -1.26 | -1.43 | -2.10 | -2.53 | -2.56 |
today_volume | 6.65 | 11.87 | 7.57 | 9.63 | 9.47 | 17.76 | 5.22 | 50.71 | 4.37 | 3.84 | 6.10 |
previous_volume | 5.54 | 12.78 | 7.25 | 7.77 | 8.04 | 12.50 | 3.79 | 39.52 | 3.56 | 3.63 | 4.44 |
pd.options.display.float_format = '{:.2f}%'.format
for sector in sectors:
df = yf.download(sector['symbol'])
mav = get_moving_averages(sector['symbol'])
mas = [mpf.make_addplot(mav[n:]['SMA8'], color='green', linestyle='dashed', width=1),
mpf.make_addplot(mav[n:]['SMA21'], color='blue', linestyle='dashed', width=1),
mpf.make_addplot(mav[n:]['SMA30'], color='orange', linestyle='dashed', width=1),
mpf.make_addplot(mav[n:]['SMA200'], color='red', linestyle='dashed', width=1),
]
current_price = mav[-1:]['Close'][0]
current_sector = daily_returns[daily_returns['ticker']==sector['symbol']]
current_percent_change = current_sector['percent change'].iloc[0]
# print(current_percent_change)
mpf.plot(df[n:],type='candle',style='yahoo',title='\n{} - {:.2f} ({:.2f}%)\n'.format(sector['name'], current_price, current_percent_change),addplot=mas,volume=True)
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed [*********************100%***********************] 1 of 1 completed