Dear R helpers I am calculating the 'Yield to Maturity' for the Bond with following characteristics. Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be calculated after solving the equation - 1010 = [100 / (1+ytm)] + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3] This can be solved by trial and error method s.t. ytm = 9.601%. My query is (1) if there is any R package which will calcualte ytm or (2) is there any method in 'R' which can solve the above equation. Thanking you all in advance Regards Madhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[alternative HTML version deleted]]
Madhavi Bhave wrote:> Dear R helpers > > I am calculating the 'Yield to Maturity' for the Bond with following characteristics. > > Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be calculated after solving the equation - > > 1010 = [100 / (1+ytm)] + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3] > > This can be solved by trial and error method s.t. ytm = 9.601%. >Why don't you use sage, for example: sage: var('ytm'); sage: eqn = 1010 == (100/(1+ytm) + 100/(1+ytm)^2 + 1100/(1+ytm)^3); sage: [solution.right().n() for solution in solve(eqn, ytm)][2] 0.0960070882662794 The third value is the only real solution. There may be an R package for doing that, but I don't know one. Best regards, Craig> > My query is (1) if there is any R package which will calcualte ytm or (2) is there any method in 'R' which can solve the above equation. > > Thanking you all in advance > > Regards > > Madhavi > > > > > > Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > 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. >
If you know the likely range, uniroot would do it. f.ytm<-function(ytm) 100 / (1+ytm) +100 / ((1+ytm)^2) + 1100 / ((1 + ytm)^3) -1010 uniroot(f.ytm, interval=c(0,25)) #$root has the answer>>> "Craig P. Pyrame" <crappyr at gmail.com> 01/02/2010 10:19 >>>Madhavi Bhave wrote:> Dear R helpers > > I am calculating the 'Yield to Maturity' for the Bond with followingcharacteristics.> > Its a $1000 face value, 3 year bond with 10% annual coupon and ispriced at 101. The yield to maturity can be calculated after solving the equation -> > 1010 = [100 / (1+ytm)] + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3] > > This can be solved by trial and error method s.t. ytm = 9.601%. >Why don't you use sage, for example: sage: var('ytm'); sage: eqn = 1010 == (100/(1+ytm) + 100/(1+ytm)^2 + 1100/(1+ytm)^3); sage: [solution.right().n() for solution in solve(eqn, ytm)][2] 0.0960070882662794 The third value is the only real solution. There may be an R package for doing that, but I don't know one. Best regards, Craig> > My query is (1) if there is any R package which will calcualte ytm or(2) is there any method in 'R' which can solve the above equation.> > Thanking you all in advance > > Regards > > Madhavi > > > > > > Your Mail works best with the New Yahoo Optimized IE8. Get itNOW! http://downloads.yahoo.com/in/internetexplorer/> [[alternative HTML version deleted]] > > >------------------------------------------------------------------------> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >______________________________________________ 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. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Dear Sir, That was GREAT!!!. Thanks a lot for the solution. Once again it showed how powerful 'R' is otherwise I was breaking my head on Newton-Raphson method. Thanks again Sir. That was really superb. Madhavi --- On Mon, 1/2/10, S Ellison <S.Ellison@lgc.co.uk> wrote: From: S Ellison <S.Ellison@lgc.co.uk> Subject: Re: [R] 'R' and 'Yield to Maturity' To: "Craig P. Pyrame" <crappyr@gmail.com>, "Madhavi Bhave" <madhavi_bhave@yahoo.com> Cc: r-help@r-project.org Date: Monday, 1 February, 2010, 3:41 AM If you know the likely range, uniroot would do it. f.ytm<-function(ytm) 100 / (1+ytm) +100 / ((1+ytm)^2) + 1100 / ((1 + ytm)^3) -1010 uniroot(f.ytm, interval=c(0,25)) #$root has the answer>>> "Craig P. Pyrame" <crappyr@gmail.com> 01/02/2010 10:19 >>>Madhavi Bhave wrote:> Dear R helpers > > I am calculating the 'Yield to Maturity' for the Bond with followingcharacteristics.> > Its a $1000 face value, 3 year bond with 10% annual coupon and ispriced at 101. The yield to maturity can be calculated after solving the equation -> > 1010 = [100 / (1+ytm)] + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3] > > This can be solved by trial and error method s.t. ytm = 9.601%. >Why don't you use sage, for example: sage: var('ytm'); sage: eqn = 1010 == (100/(1+ytm) + 100/(1+ytm)^2 + 1100/(1+ytm)^3); sage: [solution.right().n() for solution in solve(eqn, ytm)][2] 0.0960070882662794 The third value is the only real solution. There may be an R package for doing that, but I don't know one. Best regards, Craig> > My query is (1) if there is any R package which will calcualte ytm or(2) is there any method in 'R' which can solve the above equation.> > Thanking you all in advance > > Regards > > Madhavi > > > > > > Your Mail works best with the New Yahoo Optimized IE8. Get itNOW! http://downloads.yahoo.com/in/internetexplorer/> [[alternative HTML version deleted]] > > >------------------------------------------------------------------------> > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >______________________________________________ R-help@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. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:15}}
You can look at package RQuantLib from here http://cran.r-project.org/web/views/Finance.html -k On Mon, Feb 1, 2010 at 4:43 AM, Madhavi Bhave <madhavi_bhave at yahoo.com> wrote:> Dear R helpers > > I am calculating the 'Yield to Maturity' for the Bond with following characteristics. > > Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be calculated after solving the equation - > > 1010 = [100 / (1+ytm)]? + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3] > > This can be solved by trial and error method s.t. ytm = 9.601%. > > My query is (1) if there is any R package which will calcualte ytm or (2) is there any method in 'R' which can solve the above equation. > > Thanking you all in advance > > Regards > > Madhavi > > > > > > ? ? ?Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > 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. > >