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, 4, 26, 15, 7, 7, 171088)
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 | xlc | xlk | xly | xlb | xli | xlre | xlv | xlf | xlp | xle | xlu |
---|---|---|---|---|---|---|---|---|---|---|---|
name | |||||||||||
previous_close | 77.96 | 197.60 | 174.34 | 88.97 | 122.46 | 36.43 | 139.92 | 40.88 | 75.75 | 96.63 | 66.92 |
current_price | 80.10 | 199.76 | 175.91 | 89.49 | 122.63 | 36.46 | 139.93 | 40.81 | 75.60 | 95.72 | 66.17 |
percent change | 2.74 | 1.09 | 0.90 | 0.58 | 0.14 | 0.08 | 0.01 | -0.18 | -0.20 | -0.94 | -1.12 |
today_volume | 12.20 | 5.02 | 3.30 | 3.12 | 6.82 | 6.88 | 6.01 | 35.54 | 13.29 | 15.85 | 12.22 |
previous_volume | 14.35 | 5.78 | 5.35 | 4.61 | 10.32 | 8.37 | 9.69 | 50.37 | 14.35 | 13.25 | 15.78 |
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
[*********************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
Disclaimer: I am not a professional investment adviser and my opinions are based on my own technical analysis. Please consult an investment professional before making investment decisions.