[Edu-sig] re: financial calculation
Guido van Rossum
gvanrossum at gmail.com
Sun Feb 13 02:11:45 CET 2005
> ____________________________________________________________
> from __future__ import division
>
> import datetime
> import math
>
> def future_value(iday,cday,ivalue,cvalue,years):
> days_invested=(cday-iday).days
> year_periods=365/days_invested
> annualized_rate = math.log(cvalue/ivalue)*year_periods
> #future_value at the end of given years
> return ivalue*math.pow(math.e,annualized_rate*years)
>
> #date we purchased stock
> iday=datetime.date(2004,12,27)
>
> #date of valuation
> cday=datetime.date(2005,2,11)
>
> #price at purchase
> ivalue=64.5
>
> #current price
> cvalue=81
>
> #let's keep this up for ten years - sure....
> print future_value(iday,cday,ivalue,cvalue,10)
> _________________________________________________
>
> which returns
> 4561078546.84
If you fix it, as follows:
year_periods=days_invested/365
the answer is about 85. :-)
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Edu-sig
mailing list