How to use nls with this function and my data to fit a curve? I expect the output gives the estimated parameters involved in the black-scholes pricing function.
m.1 <- nls(MVBV ~ BSOption(EBV,K),
data = df_treated[df_treated$FYear==1997 & df_treated$EBV > 0 ,],
start = list( K = 0.1), trace = T)
BSOption <- function(CallPutFlag, S, X, Time, r, sigma) {
d1 <- (log(S/X)+(r+sigma^2/2)*Time)/sigmasqrt(Time)
d2 <- d1 - sigma * sqrt(Time)
if(CallPutFlag == 'c') {
P <- Spnorm(d1) - Xexp(-rTime)*pnorm(d2)
} else {
P <- -Spnorm(-d1) + Xexp(-r*Time)*pnorm(-d2)
}
P
}