# R code to calculate implied vol of a European put. # For the class Mathematics in Finance # http://www.math.nyu.edu/faculty/goodman/teaching/MathFin/index.html # Author: Jonathan Goodman rm(list=ls()) # Parameters of the option T_e = .5 # Expiration time, in years K = 2000 # option strike price r = .01 # risk free rate S0 = 2 # spot price P_m = 8 # market price of the put sig_a = .05 # lower bound for implied vol sig_b = 10 # upper bound for implied vol # Find the value of sigma so that P(sig) = P_m source("OptionPricer.R") # Where the function that evaluates P(sig) is defined source("BisectionSearch.R") # Where the nonlinear equation solver is defined eps = 10^(-5) sig_i = solver( PutPrice, P_m, sig_a, sig_b, eps) cat("The implied vol is ", sig_i, "\n") objectList = ls() for (objectName in objectList) { object = get0( objectName) cat("Object ", objectName, " has type ", typeof(object), "\n") }