Created
March 30, 2021 09:49
-
-
Save mohamedamjad/59b9ca01fe3cf3d2306156ffdd26d8e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fastapi import FastAPI | |
| app = FastAPI() | |
| @app.get('/') | |
| def hello(): | |
| return {"message": "Hello World!"} | |
| @app.get('/simulation') | |
| def simulation(years: int, capital: float, ir: float): | |
| return tableau_amortissement(years, capital, ir) | |
| def annuite(interest_rate, years, capital): | |
| return (capital * interest_rate)/(1 - (1+interest_rate)**-years) | |
| def tableau_amortissement(years, capital, interest_rate): | |
| a = float(format(annuite(interest_rate, years, capital), '.2f')) | |
| r = {"annuité": a, "remboursements": []} | |
| capital_debut_periode = capital | |
| print("Annuité du prêt: " + str(a)) | |
| for i in range(years): | |
| ip = interest_rate * capital_debut_periode | |
| capital_amorti = a - i | |
| r["remboursements"].append({ | |
| "annee": str(i+1), | |
| "capital début de période": str(capital_debut_periode), | |
| "intérêts payés": str(ip), | |
| "capital amorti": str(a - ip) | |
| }) | |
| capital_debut_periode -= capital_amorti | |
| return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment