The Black--Scholes call option formula can be written as a function in S-Plus as
bsform <- function(sig, r, t, xt, k) {
d1 <- (log(xt/k) + (r + sig^2/2)*(t))/(sig*sqrt(t))
d2 <- d1 - sig*sqrt(t)
return(xt*pnorm(d1)-k*exp(-r*t)*pnorm(d2))
}
When the observed price of the option is taken as the value of the Black-Scholes formula and the volatility is taken as a variable in the resulting equation, the solution for the volatility is called the "implied volatility".
S-Plus does not have a nonlinear "solve", but Newton steps can be programmed directly to solve the nonlinear equation. The derivative is
bsformp <- function(sig, r, t, xt, k) {
d1 <- (log(xt/k) + (r + sig^2/2)*(t))/(sig*sqrt(t))
d2 <- d1 - sig*sqrt(t)
d1p <- (sig^2*t - log(xt/k) - (r + sig^2/2)*(t))/(sig^2*sqrt(t))
d2p <- d1p - sqrt(t)
return(xt*pnorm(d1)*d1p-k*exp(-r*t)*pnorm(d2)*d2p)
}
So, after initializing sigk, for the observed price cobs, a step is
sigkp1 <- sigk - (bsform(sigk, r, t, xt, k)-cobs)/bsformp(sigk, r, t, xt, k)If the starting value is anywhere close, this is a fairly well-behaved function, so programming it directly with a convergence criterion based on the absolute difference (4 decimal places) and a limit on the number of iterations (around 50) should work reasonably well.
An alternative in packages like S-Plus that may have a nonlinear minimization function is to write an objective function as the square of the difference in the function and the specified value, that is
(bsform(sigk, r, t, xt, k)-cobs)^2in the expression above.
In S-Plus the minimization function requires a double to be returned by the objective function, and that function must be a function of the decision variable(s) alone. Therefore, we could write
bssig <- function(sig) {
r <- params[1]
t <- params[2]
xt <- params[3]
k <- params[4]
cobs <- params[5]
d1 <- (log(xt/k) + (r + sig^2/2)*(t))/(sig*sqrt(t))
d2 <- d1 - sig*sqrt(t)
return(as.double((xt*pnorm(d1)-k*exp(-r*t)*pnorm(d2)-cobs)^2))
}
and then
params <- c(r,t,xt,k,cobs)
assign("params", params, frame=1)
sig <- .05 ## (some reasonable guess)
nlmin(bssig,sig)
2. Go to
E*Trade options quotes
and look at prices for Intel (INTC). Make note of the date.
Based on "last" prices for April 25, 27 1/2, 30, 32 1/2, and 35 calls,
compute the implied volatility.
3. Compute (and annualize) the average volatility of INTC for the past 30 days. (Get those data from Yahoo .) How do the implied volatilities compare with each other and with the observed volatility?
4. Plot a volatility smile for the S&P 500 index. (This is the symbol SPX on E*Trade .)
5. Use Ito's formula to derive the formula for integration by parts for a stochastic integral.