First we have to extract nifty data using tidyquant or Rquantlib.
Code
# Install necessary packages if not already installed# install.packages("quantmod")# install.packages("RQuantLib")# Load necessary packageslibrary(data.table)library(tidyquant)# Fetch the Nifty 50 index datanifty_data <-tq_get("^NSEI", from ="1980-01-01", to =Sys.Date())# Convert the data to a data.tablenifty_data <-data.table(nifty_data)
Get closing price
Code
# Extract the last closing price directly from nifty_dataclosing_price <-tail(nifty_data$close, 1)closing_price
[1] 24768.3
Implied Volatility calculation
Plugin the latest option price for a liquid strike price with a 4 month maturity to get a reasonably accurate implied volatility.
Code
library(quantmod)library(RQuantLib)# Define option parameters for a single observationnifty_price<-23290.5option_price <-105# Current market price of the optionstrike_price <-22500# Strike price of the optiontime_to_expiry <-19/365# Time to expiration in yearsrisk_free_rate <-0.071# Risk-free interest ratevolatility_guess <-0.2# Initial guess for the volatility# Calculate implied volatility for a put optionvol<-EuropeanOptionImpliedVolatility(type ="put",value =option_price ,underlying = nifty_price,strike = strike_price,dividendYield =0,riskFreeRate = risk_free_rate,maturity = time_to_expiry,volatility = .2)vol
Aim for a strike less than 10 delta. Plugin the implied volatility and other data.
Code
closing_price<-23389strike <- closing_price *0.85# Strike price of the optiontime_to_expiry <-210/365# Time to expiration in yearsrisk_free_rate <-0.071# Risk-free interest rateprice<-EuropeanOption(type ="put",underlying = closing_price,strike = strike,dividendYield =0,riskFreeRate = risk_free_rate,maturity = time_to_expiry,volatility = vol)cat("Closing price of nifty:\n")
Closing price of nifty:
Code
print(closing_price)
[1] 23389
Code
cat("Strike price:\n")
Strike price:
Code
strike
[1] 19880.65
Code
price
Concise summary of valuation for EuropeanOption
value delta gamma vega theta rho divRho
109.5493 -0.0693 0.0000 2363.9846 -268.4321 -995.5055 932.5147
Price of a 4 month 5 delta option is 110 for the given strike price
Take home message
Summary
Before buying hedge, plugin the market price, strike price, time to maturity, implied volatility and risk free rate to the BS formula and find out the fair value. Then only buy the hedge.
Code
closing<-21884.9strikerate <-20000# Strike price of the optiontime<-210/365# Time to expiration in yearsrisk_free_rate <-0.071# Risk-free interest ratevol<-vol # implied volatilityprice<-EuropeanOption(type ="put",underlying = closing,strike = strikerate,dividendYield =0,riskFreeRate = risk_free_rate,maturity = time,volatility = vol)price
Concise summary of valuation for EuropeanOption
value delta gamma vega theta rho divRho
293.1177 -0.1638 0.0001 4100.4435 -403.4529 -2230.1221 2061.5794
Code
strikerate
[1] 20000
Monetising the hedge
§a passive - at the time of expiry.
§b Empirical multiples of Initial cost.
§a is ideal for long time horizon with potential big drawdown happening once or twice. §b out performs §a if no such tail events occur. In such a situation, even no-hedge strategy performs better than one with a hedge.
For the hedging to outperform a pure buy and hold strategy with out hedging, it should be monitised at 8- 10 times the initial premium or a catastrophy should happen. In any case, the proceedings should be used to buy further far OTM puts and rest may be invested in the crashing asset.