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')
datetime.now()
datetime.datetime(2022, 2, 23, 16, 59, 56, 435328)
pd.options.display.float_format = '{:.2f}'.format
symbol = 'ptlo'
week = '2022-03-18'
n = 10
# Parameters
symbol = "coin"
week = "2022-03-18"
n = 20
symbol = symbol.upper()
n = n * -1
get_daily_returns([symbol]).set_index('ticker').transpose()
ticker | COIN |
---|---|
name | Coinbase Global, Inc. |
previous_close | 176.76 |
current_price | 172.74 |
percent change | -2.27 |
today_volume | 3.86 |
previous_volume | 4.47 |
get_ytd_growth_percentage([symbol]).set_index('ticker').transpose()
ticker | COIN |
---|---|
name | Coinbase Global, Inc. |
growth | -31.55 |
mav = get_moving_averages(symbol)
mav[-5:]
[*********************100%***********************] 1 of 1 completed
Open | High | Low | Close | Adj Close | Volume | SMA8 | SMA21 | SMA30 | SMA200 | RSI | |
---|---|---|---|---|---|---|---|---|---|---|---|
Date | |||||||||||
2022-02-16 | 205.38 | 214.02 | 203.83 | 207.96 | 207.96 | 3593600 | 205.05 | 196.57 | 206.86 | 253.66 | 46.24 |
2022-02-17 | 202.10 | 206.31 | 188.93 | 191.92 | 191.92 | 4740600 | 203.33 | 195.26 | 205.45 | 253.26 | 41.90 |
2022-02-18 | 191.08 | 192.72 | 180.54 | 189.16 | 189.16 | 4494100 | 200.88 | 193.71 | 203.96 | 252.92 | 41.20 |
2022-02-22 | 180.87 | 185.75 | 173.16 | 176.76 | 176.76 | 4472800 | 196.16 | 192.99 | 202.10 | 252.49 | 38.20 |
2022-02-23 | 180.69 | 183.34 | 171.77 | 172.74 | 172.74 | 3855275 | 192.16 | 192.10 | 200.36 | 251.88 | 37.27 |
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))
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),
]
# 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.