human
Give me a the Python program you requested given the following:
I am working on the file "House Investment Return.ipynb".
The first task is:
Wow, those one and two year scenarios look pretty grisly. We have to really pay to catch our equity back up. Even the final payments for five-year switching don't look too great, but they're still manageable.
The math is basically reinforcing common sense. It makes very little finanacial sense to constantly house swap. Let's look at the rate of return for the sensible swapping intervals:
Can you write Python program for it?
assistant
#Here is the Python program you requested.

for year in (5, 10, 25, 50):
    swap_months = year * 12
    
    def buy_and_appreciate(r, term, mortgage): 
        return buy(r, term, mortgage=mortgage, appreciation=1.0)
    
    def dcf_swapping_houses(r):
        mortgage_list = list(mortgages(swap_months, appreciation / 12))
        buy_costs = [npv(buy_and_appreciate(r / 12, swap_months, m), r / 12, month)
                     for month, m in mortgage_list[:-1]]
        
        final_month, final_mortgage = mortgage_list[-1]
        mortgage_remaining = 30 * 12 - swap_months
        months_to_final = final_month
        months_remaining = total_months - months_to_final
        final_cost = npv(buy_and_appreciate(r / 12, months_remaining, final_mortgage), r / 12, months_to_final)
        
        return sum(buy_costs) + final_cost - rent(r / 12, total_months)

    print year, irr(dcf_swapping_houses)