Option Pricing
Models uses pydantic to create a data model for option inputs. Refer the following implementation of the Black Scholes amd Monte Carlo option pricing methods.
import numpy as np
from tabulate import tabulate
from quantmod.models import OptionInputs, BlackScholesOptionPricing, MonteCarloOptionPricing
# Get the option inputs parameters
inputs=OptionInputs(
spot=100,
strike=100,
ttm=1,
rate=0.05,
volatility=0.2,
callprice=8.0
)
# 1. Black Scholes Option Pricing
# Initialize the BS Option Pricing Engine
option = BlackScholesOptionPricing(inputs=inputs)
# Print the BS option price
header = ['Option Price', 'Delta', 'Gamma', 'Theta', 'Vega', 'Rho', 'IV']
table = [[option.call_price, option.call_delta, option.gamma, option.call_theta, option.vega, option.call_rho, option.impvol],]
print(tabulate(np.around(table, 4), headers=header))
# 2. Monte Carlo Option Pricing
# Initialize the MC Option Pricing Engine
mcoption = MonteCarloOptionPricing(
inputs=inputs,
initialspot=100,
nsims=100000,
timestep=252,
barrier=150,
rebate=10
)
print(f"Vanilla Option: CallPrice > {mcoption.call_vanilla:0.4f}, PutPrice > {mcoption.put_vanilla:0.4f}")
print(f"Asian Option: CallPrice > {mcoption.call_asian:0.4f}, PutPrice > {mcoption.put_asian:0.4f}")
print(f"Up and out Option: CallPrice > {mcoption.upandoutcall:0.4f}")