TheDailyCalls.com Notebook¶

SPY Sectors Charts¶

This notebook is updated three times daily. Cheers.

In [1]:
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
In [2]:
n=50
In [3]:
# Parameters
n = 50
In [4]:
n=n*-1
sectors = get_sp500_sector_components()
In [5]:
datetime.now()
Out[5]:
datetime.datetime(2023, 2, 3, 15, 7, 8, 998964)
In [6]:
s = [i['symbol'] for i in sectors]
daily_returns = get_daily_returns(s)
In [7]:
pd.options.display.float_format = '{:.2f}'.format
daily_returns.sort_values(by='percent change',ascending=False).set_index('ticker').transpose()
Out[7]:
ticker xlf xle xlv xlp xli xlk xlb xlc xlre xlu xly
name
previous_close 36.66 86.15 133.08 73.69 103.39 142.96 84.94 59.39 41.83 69.36 156.16
current_price 36.62 85.98 132.71 73.42 102.87 141.78 83.42 58.17 40.96 67.89 151.34
percent change -0.12 -0.20 -0.28 -0.37 -0.50 -0.83 -1.79 -2.05 -2.08 -2.12 -3.09
today_volume 42.52 22.68 10.02 12.86 13.49 8.01 5.93 7.83 7.46 12.67 6.79
previous_volume 42.11 24.90 11.27 12.24 13.46 9.41 6.16 9.44 7.01 12.50 7.02
In [8]:
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