On Fri, Apr 3, 2009 at 7:45 PM, Brian <medo...@gmail.com> wrote:
>
> 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.
>

The problem is that you're giving the symbolic variable "n" as input
to the range command (in your units function), but the range command
takes a pair of integers as input.

William

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to