0

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 
} 
camille
  • 16,432
  • 18
  • 38
  • 60
  • 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)/sigma*sqrt(Time) d2 <- d1 - sigma * sqrt(Time) if(CallPutFlag == 'c') { P <- S*pnorm(d1) - X*exp(-r*Time)*pnorm(d2) } else { P <- -S*pnorm(-d1) + X*exp(-r*Time)*pnorm(-d2) } P } – li rebecca Aug 21 '19 at 15:54
  • You can (and should) [edit] your question to include this code, where it can be formatted and read more easily. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Aug 21 '19 at 20:27
  • I've edited your question to include a formatted version of the code from your comment – camille Aug 21 '19 at 20:31

0 Answers0