TheDailyCalls.com Notebook¶

In [1]:
import mplfinance as mpf
import yfinance as yf
from wallstreet import get_daily_returns, get_ytd_growth_percentage, get_moving_averages, get_relative_strength
import pandas as pd
from datetime import datetime
import warnings
warnings.filterwarnings('ignore')

Date¶

In [2]:
datetime.now()
Out[2]:
datetime.datetime(2022, 11, 29, 20, 1, 34, 880701)
In [3]:
pd.options.display.float_format = '{:.2f}'.format
In [4]:
symbol = 'ptlo'
week = '2022-03-18'
n = 10
In [5]:
# Parameters
symbol = "xle"
week = "2022-03-18"
n = 50
In [6]:
symbol = symbol.upper()
n = n * -1

Performance¶

Daily Returns¶

In [7]:
get_daily_returns([symbol]).set_index('ticker').transpose()
Out[7]:
ticker XLE
name Energy Select Sector SPDR Fund
previous_close 89.35
current_price 90.70
percent change 1.51
today_volume 19.01
previous_volume 29.13

Year to date returns¶

In [8]:
get_ytd_growth_percentage([symbol]).set_index('ticker').transpose()
Out[8]:
ticker XLE
name Energy Select Sector SPDR Fund
growth 68.66

Moving Averages¶

In [9]:
mav = get_moving_averages(symbol)
mav[-5:]
[*********************100%***********************]  1 of 1 completed
Out[9]:
Open High Low Close Adj Close Volume SMA8 SMA21 SMA30 SMA200 RSI
Date
2022-11-22 91.52 93.43 91.10 93.22 93.22 26877500 92.51 90.99 88.70 78.64 60.59
2022-11-23 91.53 92.80 91.19 92.21 92.21 20598700 92.39 91.21 89.10 78.76 58.53
2022-11-25 92.27 92.92 91.71 91.87 91.87 7591300 92.24 91.37 89.38 78.88 57.83
2022-11-28 89.62 90.75 89.05 89.35 89.35 29131200 91.65 91.39 89.69 78.98 52.92
2022-11-29 90.34 91.23 90.01 90.70 90.70 19005500 91.47 91.46 90.00 79.08 55.07
In [10]:
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),
       ]
if ('SMA200' in mav.keys()):
       mas.append(mpf.make_addplot(mav[n:]['SMA200'], color='red', linestyle='dashed', width=1))

mpf.plot(mav[n:], type='candle',style='charles',title='\n{}'.format(symbol),volume=True,addplot=mas,figscale=1.1,figratio=(3,2))

Graph¶

In [11]:
e = yf.Ticker(symbol)
hist = e.history(period='60d', interval='1d')
# Valid intervals: [1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo]

# expiration weeks
exp_weeks = pd.DataFrame(e.options, columns=['weeks'])
# exp_weeks

hlines=None

if week in exp_weeks.weeks.values:
  opt = e.option_chain(week)
  c_asset = pd.DataFrame(opt.calls, columns=['strike', 'volume','openInterest', 'impliedVolatility'])
  call_strike = c_asset[c_asset.openInterest == c_asset.openInterest.max()].set_index('strike').index[0]
  p_asset = pd.DataFrame(opt.puts, columns=['strike', 'volume','openInterest', 'impliedVolatility'])
  put_strike = p_asset[p_asset.openInterest == p_asset.openInterest.max()].set_index('strike').index[0]
  hlines = dict(hlines=(put_strike, call_strike), colors=('r','g','b','b'), linewidths=(1,1),linestyle='dashed')

# Settings
kwargs = dict(figscale=1.1,figratio=(8,4),
         volume=True,volume_panel=2,panel_ratios=(7,2,2) , mav=(8,21,30))

exp12 = hist['Close'].ewm(span=12, adjust=False).mean()
exp26 = hist['Close'].ewm(span=26, adjust=False).mean()
macd = exp12 - exp26
signal    = macd.ewm(span=9, adjust=False).mean()
histogram = macd - signal

currentPrice = hist[-1:].set_index('Close').index[0]

apds = [#mpf.make_addplot(exp12,color='lime'),
        #mpf.make_addplot(exp26,color='c'),
        mpf.make_addplot(histogram,type='bar',width=0.4,panel=1,
                         color='blue',alpha=1,secondary_y=False),
        mpf.make_addplot(macd,panel=1,color='green',secondary_y=True),
        mpf.make_addplot(signal,panel=1,color='purple',secondary_y=True),
       ]
In [12]:
# mpf.plot(hist,type='candle',style='yahoo',addplot=apds,**kwargs,hlines=hlines)


if hlines:
  title = '\n{} {:.2f} \nOptions Open Interest Walls\n Exp Date: {} Call: {:.2f} Put: {:.2f}'.format(symbol, currentPrice, week, call_strike, put_strike)
  mpf.plot(hist,type='candle',style='default',addplot=apds,**kwargs,hlines=hlines,title=title)
else:
  title = '\n{} {:.2f} \n'.format(symbol, currentPrice)
  mpf.plot(hist,type='candle',style='default',addplot=apds,**kwargs,title=title)

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.