1

I am trying to build a calculator that computes compound interest but with a few quirks. Specifically: a) I want the deposited amount to vary within a normal distribution for every month until the end of the investment b) I want the rate of interest to vary within a normal distribution for every day until the end of the investment

I started off with the basics:

    # -*- coding: utf-8 -*-
    """
    Spyder Editor

    This is a temporary script file.
    """
    import numpy as np
    from tabulate import tabulate
    tabulate.PRESERVE_WHITESPACE = True
    year = 1
    Principal = 1050
    Prev_Principal = 0
    n = 365
    Total_New = 0
    FV_prev = 0
    
    for year in range(1,5):
        RoR = 0.01*np.random.normal(7.43,4.172,1)
        PMT = np.random.normal(575,85.39,1)
        FV = PMT*(12/n)*((1+(RoR/n))**(n*year)-1)/(RoR/n)
        Total = FV + Principal*(1+(RoR/n))**(n*year)
        Total_New  = Total - Total_New
        Net_Gain = Total - (year*12*PMT+Principal)
        print(tabulate([["YEAR","FV","TOTAL","CI", "R%"],[year,np.round(FV,1),np.round(Total,1),np.round(Net_Gain,1),np.round(100*RoR,1)]], headers="firstrow", tablefmt='fancy_grid'))

This basic version just outputs the sum at the end of the year including the interest as well as the net interest by year. Unfortunately, although it varies the interest rate, it only does so once per year. I plan on doing the following however I am not sure if it's correct, both in terms of programming and mathematically. So I want to take these:

        FV = PMT*(12/n)*((1+(RoR/n))-1)/(RoR/n)
        Total = FV + Principal*(1+(RoR/n))**(n*year)

and use RoR_Array = 0.01*np.random.normal(7.43,4.172, 365) math.prod((1+RoR_Array/365))

With RoR_Array I am basically trying to create a 1D ray with 365 elements, one for each day of the year, which represents the daily interest rate. With 'math prod' I am trying to overcome the following issue: If n=365, that means that interest is fixed for the year and compounded daily so

    Total = FV + Principal*(1+(RoR/365))**(365*1)

But since I want a variable daily RoR, what's the best way of doing it? Hence why I am using math.prod.

MattDMo
  • 100,794
  • 21
  • 241
  • 231

0 Answers0