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(2023, 6, 6, 15, 7, 6, 34369)
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 | xlf | xly | xle | xlre | xlb | xli | xlc | xlk | xlu | xlp | xlv |
---|---|---|---|---|---|---|---|---|---|---|---|
name | |||||||||||
previous_close | 32.63 | 157.47 | 79.37 | 36.64 | 78.51 | 100.24 | 63.32 | 165.94 | 65.43 | 73.34 | 130.79 |
current_price | 33.05 | 159.11 | 80.00 | 36.87 | 79.00 | 100.86 | 63.57 | 165.88 | 65.37 | 72.97 | 129.69 |
percent change | 1.29 | 1.04 | 0.79 | 0.63 | 0.62 | 0.62 | 0.39 | -0.04 | -0.09 | -0.50 | -0.84 |
today_volume | 46.07 | 4.46 | 17.35 | 3.26 | 7.60 | 10.49 | 4.41 | 4.91 | 12.85 | 10.79 | 9.21 |
previous_volume | 53.59 | 3.93 | 18.91 | 3.97 | 7.16 | 9.66 | 7.26 | 5.45 | 12.04 | 9.63 | 7.88 |
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