-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloan.py
More file actions
47 lines (39 loc) · 1.44 KB
/
loan.py
File metadata and controls
47 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ---------------------------------------------
# Copyright: (c) Cesar Herdenez 2018
# Licence: Apache License Version 2.0
# ---------------------------------------------
# M = L(I(1 + I)**N) / ((1 + I)**N - 1)
# M = Monthly Payment, L = Loan, I = Interest, N = Number of payments,
# Interés = Monto_Solicitado * ((1 + 25%) ^ (Plazo / 360) - 1)
# cifras en miles
WIDTH = 10
PRECISION = 3
def interest(capital, plazo=30, tasa=0.25):
return round(capital * ((1 + tasa) ** (plazo / 360) - 1), 3)
def get_cuota(capital, plazo, tasa):
return round((capital * tasa) / (1 - ((1 + tasa) ** -plazo)), 0)
def plan_de_pagos(capital, plazo, tasa):
cuota = get_cuota(capital, plazo, tasa)
mes, interes, amortizacion, data = 0, 0, 0, dict()
print('{:^10}{:^10}{:^10}{:^10}{:^10}'.format(
'mes', 'couta', 'interes', 'amortizacion', 'saldo'))
data['plan'] = list()
while mes <= plazo:
data['plan'].append(
dict(
mes=mes,
cuota=cuota,
interes=interes,
amortizacion=amortizacion,
saldo=capital,
)
)
# print('{:^10}{:^10}{:^10}{:^10}{:^10}'.format(
# mes, cuota, interes, amortizacion, capital))
interes = round(capital * tasa, 0)
amortizacion = round(cuota - interes, 0)
capital -= amortizacion
mes += 1
return data