Skip to content
Prev 169775 / 398506 Next

uniroot() problem

Megh,

The problem is due to jump discontinuity in your function at x=0.  It is
always good practice to plot the function over the range of interest.

x <- seq(-20, 20, by=0.01)

plot(x, th.price(x), type="l")
 
This will reveal the problem.  The function value jumps from -384.4 to 36.29
at x=0.

If the singularity at x=0 is not an essential one, you may be able to
anayticallty remove this singularity.  

Ravi.


----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of megh
Sent: Monday, February 09, 2009 4:27 AM
To: r-help at r-project.org
Subject: Re: [R] uniroot() problem


Thanks for this reply. Here I was trying to calculate implied volatility
using BS formula. This is my code :

oo = 384.40 # traded option price
    uu = 1563.25 # underlying price
    tt = 0.656 # time to maturity in year
    ii = 2.309/100 # interest rate, annualized
    th.price = function(x)
       {
        d1 = (log(uu/K) + (ii + x^2/2)*tt) / (x*sqrt(tt)); d2 = d1 -
x*sqrt(tt)
        option.price = uu * pnorm(d1) - K * exp(-ii*tt) * pnorm(d2)
        return(option.price - oo)
       }

uniroot(th.price, c(-20, 20), tol=1/10^12)

I got following result :
$root
[1] 6.331672e-13

$f.root
[1] 36.28816

$iter
[1] 55

$estim.prec
[1] 7.385592e-13

Hence using implied volatility, difference between traded price and
theoretical price is coming as high as 36.28816, even I increse the
precision level. Any idea how to crack this problem?
Albyn Jones wrote:
--
View this message in context:
http://www.nabble.com/uniroot%28%29-problem-tp21227702p21909423.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.