An Exception was encountered at 'In [7]'.

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(2026, 3, 9, 15, 7, 6, 254857)
In [6]:
s = [i['symbol'] for i in sectors]
daily_returns = get_daily_returns(s)
- XLV: No data found for this date range, symbol may be delisted

Execution using papermill encountered an exception here and stopped:

In [7]:
pd.options.display.float_format = '{:.2f}'.format
daily_returns.sort_values(by='percent change',ascending=False).set_index('ticker').transpose()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[7], line 2
      1 pd.options.display.float_format = '{:.2f}'.format
----> 2 daily_returns.sort_values(by='percent change',ascending=False).set_index('ticker').transpose()

File ~/.local/share/virtualenvs/reports-_ZceJivp/lib/python3.8/site-packages/pandas/util/_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    325 if len(args) > num_allow_args:
    326     warnings.warn(
    327         msg.format(arguments=_format_argument_list(allow_args)),
    328         FutureWarning,
    329         stacklevel=find_stack_level(),
    330     )
--> 331 return func(*args, **kwargs)

File ~/.local/share/virtualenvs/reports-_ZceJivp/lib/python3.8/site-packages/pandas/core/frame.py:6909, in DataFrame.sort_values(self, by, axis, ascending, inplace, kind, na_position, ignore_index, key)
   6905 elif len(by):
   6906     # len(by) == 1
   6908     by = by[0]
-> 6909     k = self._get_label_or_level_values(by, axis=axis)
   6911     # need to rewrap column in Series to apply key function
   6912     if key is not None:
   6913         # error: Incompatible types in assignment (expression has type
   6914         # "Series", variable has type "ndarray")

File ~/.local/share/virtualenvs/reports-_ZceJivp/lib/python3.8/site-packages/pandas/core/generic.py:1850, in NDFrame._get_label_or_level_values(self, key, axis)
   1844     values = (
   1845         self.axes[axis]
   1846         .get_level_values(key)  # type: ignore[assignment]
   1847         ._values
   1848     )
   1849 else:
-> 1850     raise KeyError(key)
   1852 # Check for duplicates
   1853 if values.ndim > 1:

KeyError: 'percent change'
In [ ]:
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)

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.