Skip to content

Instantly share code, notes, and snippets.

@louisguitton
Created November 9, 2016 20:17
Show Gist options
  • Save louisguitton/32393063e8e1948a068f5d82451a394a to your computer and use it in GitHub Desktop.
Save louisguitton/32393063e8e1948a068f5d82451a394a to your computer and use it in GitHub Desktop.
These are python financial functions to generate the table for a loan
# Fomule du pret pour obtenir la mensualite
def pmt(C, n, t):
if t:
return (C * t/12)/(1-(1 + t/12)**-n)
else:
return C/n
# Formule pour obtenir la part d'interets de la mensualite
def impt(period, C, n, t):
t_per = t/12
mensu = pmt(C, n, t)
return ((1 + t_per)**(period-1))*(C*t_per - mensu) + mensu
# Formumle pour obtenir la part de capital de la mensualite
def ppmt(period, C, n, t):
return pmt(C, n, t) - impt(period, C, n, t)
def tableau_amo(C, n, t):
import numpy as np
import pandas as pd
tab = pd.DataFrame(np.array(range(1,n+1)), columns=["periods"])
tab["interets"] = tab.periods.apply(impt, args=(C,n,t,))
tab["capital"] = tab.periods.apply(ppmt, args=(C,n,t,))
tab["capital_du"] = tab.periods.apply(lambda row: C-sum(tab.capital[:row]))
return tab
def main():
# Capital emprunte
C1 = 10000
C2 = 4000
# Duree en mois
n = 6 * 12
# Taux Effectif Gobal annuel
t1 = 0.017
t2 = 0.008
t3 = 0.018
print("Scenario 1")
i_t1 = tableau_amo(C1, n, t1).interets.sum()
i_t2 = tableau_amo(C1, n, t2).interets.sum()
print("economies: "+ '{:.2f}'.format(i_t1 - i_t2) + " euros")
print("gain: " + '{:.2f}'.format(C2*t3) + " euros/an")
print("\n")
print("Scenario 2")
i_t1 = tableau_amo(C1, n, t1).interets.sum()
i_t2 = tableau_amo(C1-C2, n, t1).interets.sum()
print("economies: "+ '{:.2f}'.format(i_t1 - i_t2) + " euros")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment