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, 11, 30, 12, 7, 9, 750308)
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 | xlv | xlf | xlb | xle | xli | xlu | xlp | xlre | xlk | xly | xlc |
---|---|---|---|---|---|---|---|---|---|---|---|
name | |||||||||||
previous_close | 129.68 | 35.50 | 81.60 | 84.02 | 105.89 | 62.49 | 69.96 | 36.93 | 184.89 | 169.02 | 70.18 |
current_price | 130.57 | 35.70 | 81.94 | 84.36 | 106.28 | 62.69 | 70.11 | 36.94 | 183.90 | 167.96 | 69.28 |
percent change | 0.69 | 0.56 | 0.42 | 0.40 | 0.37 | 0.33 | 0.21 | 0.04 | -0.54 | -0.63 | -1.28 |
today_volume | 4.33 | 14.99 | 2.13 | 19.84 | 8.64 | 7.37 | 4.89 | 3.42 | 2.75 | 2.64 | 2.48 |
previous_volume | 6.98 | 36.65 | 3.12 | 22.63 | 9.10 | 17.90 | 9.87 | 7.94 | 5.38 | 3.83 | 4.09 |
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