I am new to programming, and I have been exposed to the basic of R and Python. I have been trying to implement the volatility smile function using a unit root function(a traditional procedure) but I am running into problems. Here is the code I am writing:

BlackScholesFormulaBach  <- function (spot,timetomat,strike,r, q=0, sigma)

BlackScholesImpVol  <- function (obsprice,spot,timetomat,strike,r, q=0)
{ difference<- function(sigBS, obsprice,spot,timetomat,strike,r,q)

uniroot(difference, c(-1,1),obsprice=obsprice,spot=spot,timetomat=timetomat,strike=strike,r=r,q=q)$root




Every time I run the code I get:

Error in c(-1, 1) : unused argument (1)

If I change the interval I get the same error. I have been checking the code but it seems right. I have consulted other people and none finds the problem. According to R the problem is on the unitroot function, but I fail to see where.


Can someone help me solve this implementation problem?

Thanks in Advnace


The problem is not in the code you posted, but somewhere before: you have apparently defined a function called c, with only one argument.

Try to run the code in a new session.

  • 1
    $\begingroup$ Or try rm(c). $\endgroup$ – Bob Jansen Mar 15 at 5:38
  • 1
    $\begingroup$ You should be crystal clear removing any default function like c. Given the widespread usage of this function removing it with rm is really bad idea. Why not use some other name? $\endgroup$ – Brian Smith Mar 15 at 9:39
  • $\begingroup$ The function "c" is the list function, in order to build a vector. How should I have defined the function? Is that what you are referring to? $\endgroup$ – Pedro Gomes Mar 15 at 9:53
  • 1
    $\begingroup$ As pointed out by VDZ, you have c defined somewhere yourself, probably as a one argument function. It's not possible to delete the builtin c, in a fresh session rm(c) yields Warning message: In rm("c") : object 'c' not found. If you overwrite c it does work, for example: c <- list; rm(c) doesn't give a warning. $\endgroup$ – Bob Jansen Mar 15 at 10:05
  • $\begingroup$ @BobJansen Thanks for your comment. That was indeed the problem. I have just used "rm" and it is working now. $\endgroup$ – Pedro Gomes Mar 15 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.