<jupyter_start><jupyter_text>Black Scholes Stock Puts Inputs<jupyter_code>import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
import yfinance as yf
dfo = yf.Ticker("AAPL")
dfo.options
dfo_exp = dfo.option_chain('2020-05-28')
dfo_exp.puts
symbol = 'AAPL'
start = '2019-12-01'
end = '2020-04-02'
df = yf.download(symbol,start,end)
df.head()
df.tail()
returns = df['Adj Close'].pct_change().dropna()
from datetime import datetime
from dateutil import relativedelta

d1 = datetime.strptime(start, "%Y-%m-%d")
d2 = datetime.strptime('2020-05-28', "%Y-%m-%d")
delta = relativedelta.relativedelta(d2,d1)
print('How many years of investing?')
print('%s years' % delta.years)
maturity_days = (df.index[-1] - df.index[0]).days
print('%s days' % maturity_days)
S0 = df['Adj Close'][-1]
K = dfo_exp.puts['strike'][6]
r = 0.1
sigma = returns.std()
T = maturity_days/252
print("S0\tCurrent Stock Price:", S0)
print("K\tStrike Price:", K)
print("r\tContinuously compounded risk-free rate:", r)
print("sigma\tVolatility of the stock price per year:", sigma)
print("T\tTime to maturity in trading years:", T)
def d1(S0, K, r, sigma, T):
    d1 = (np.log(S0/K) + (r + sigma**2 / 2) * T)/(sigma * np.sqrt(T))
    return d1
def d2(S0, K, r, sigma, T):
    d2 = (np.log(S0 / K) + (r - sigma**2 / 2) * T) / (sigma * np.sqrt(T))
    return d2
def BlackScholesCall(S0, K, r, sigma, T):
    BSC = S0 * ss.norm.cdf(d1(S0, K, r, sigma, T)) - K * np.exp(-r * T) * ss.norm.cdf(d2(S0, K, r, sigma, T))
    return BSC       
def BlackScholesPut(S0, K, r, sigma, T):
    BSP = K * np.exp(-r * T) * ss.norm.cdf(-d2(S0, K, r, sigma, T)) - S0 * ss.norm.cdf(-d1(S0, K, r, sigma, T)) 
    return BSP
Put_BS = BlackScholesPut(S0, K, r, sigma, T)
Put_BS<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18552036199095023, 'fraction_numerical': 0.04242081447963801, 'mean_word_length': 4.0687679083094554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '129328', 'license': 'MIT', 'n_tokens_mistral': 803, 'n_tokens_neox': 759, 'n_words': 192, 'path': 'Python_Stock/Options_Strategies/Black_Scholes_Stock_Puts.ipynb', 'repo_name': 'eu90h/Stock_Analysis_For_Quant', 'size': '1768'}