Thank you Timothy. Here is the correct (I believe) code for that equation.
def units(C, n, F, r): return sum([C / (1 + r) ^ t for t in range(1, n+1)]) + F / (1 + r) ^ n def price(C, n, F, r): return 100 * (units(C, n, F, r) / F) Here, units expresses the equation I linked to, and price gives the scaled price, 100 being par. For example, evaluating the expression below demonstrates the example calculation from this site: http://www.moneychimp.com/articles/finworks/fmbondytm.htm units(70,4,1000,.0853) That evaluates to ~950 as in the example, therefore giving a price of ~95: price(70,4,1000,.0853) And sure enough, plotting the price yield curve gives sensible results: plot(price(70,4,1000,var('y')),0,.2) Now I would like to make a 3d plot where n and r are free. The trouble is, when I try it, I get the following error. Would someone point out my error? plot(price(70,var('n'),1000,var('y'))) TypeError: range() integer start argument expected, got sage.rings.integer.Integer. Thanks, Brian On Apr 3, 7:03 pm, Timothy Clemans <timothy.clem...@gmail.com> wrote: > I'm not 100% sure but I think it would look something like > > def maturity_formula(C, P, r): > return sum([C / (1 + r) ^ t + F / (1 + r) ^ n for t in range(1, n+1)]) > > On Fri, Apr 3, 2009 at 8:54 PM, Brian <medo...@gmail.com> wrote: > > > I was hoping to get help with using SAGE to plot this equation: > >http://www.streetauthority.com/images/education/ytm.gif > > > This is the yield to maturity formula, expressing that a bond's price > > is the sum of the present values of its future cash flows. > > > P = price of the bond > > n = number of periods > > C = coupon payment > > r = required rate of return on this investment > > F = maturity value > > t = time period when payment is to be received > > > All variables are fixed except P and r, so my plot will be the > > function P(r). > > > Once this is working, my next goal is to unfix n and have it vary on > > the z axis. > > > A more basic question that could get me started is, how do I express > > that summation? > > > Thanks, Brian > > > (Source:http://www.streetauthority.com/terms/y/yield-to-maturity.asp) --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---