The brief
A bank is arranging a 20-year loan to a solar farm, secured on its power sales. The farm sells power around the clock, so its income arrives continuously. It earns $2.4 million a year now, indexed to grow at a continuous 2% a year.
The bank's model values that income as a continuous stream. The buyer, though, pays at the end of each month for the power delivered in it. The credit team wants both values, and the cost of the monthly timing.
Your task
- Write
pv_continuous(c0, g, r, T): the present value of income paid continuously at a year for years, discounted at the continuous rate . RaiseValueErrorifTis negative. - Write
monthly_payments(c0, g, T): the list of monthly payments, first month first. Payment is the income earned during month , paid at its end. RaiseValueErrorifTis negative or is not a whole number of months. - Write
pv_monthly(c0, g, r, T): the present value of those payments, each discounted at from the end of its month.
Keep full precision when equals or nearly does, and when is 0 or tiny.
The data
INCOME, GROWTH, RATE and YEARS in the code hold the farm's terms. Rates are annual decimals, continuously compounded, and times are in years.
Hint: Where to start
Lesson 2.5.5 values a growing stream as the integral of over . Write the closed form with math.expm1, as that lesson does, so that a tiny keeps its digits.
Hint: The monthly payments
The income earned between times and is the integral of its rate from to (lesson 2.5.3). An antiderivative of is (lesson 2.5.2), so the payment is . Factor out and use math.expm1 for the rest.
Hint: Checking your answer
Paid at month ends, each month's income arrives on average half a month late. So the monthly value should be about times the continuous one. In the same way, lesson 2.5.5 found mid-year payments worth almost as much as the continuous stream.