Alexvatti commited on
Commit
bce4929
·
verified ·
1 Parent(s): b97d892

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, render_template
2
+
3
+ app = Flask(__name__)
4
+
5
+ # SIP Calculation Function
6
+ def calculate_sip(P, i, n):
7
+ M = P * (((1 + i) ** n - 1) / i) * (1 + i)
8
+ return M
9
+
10
+ # REST API Endpoint for SIP Calculation
11
+ @app.route('/api/sip', methods=['POST'])
12
+ def sip_api():
13
+ try:
14
+ data = request.json # Get JSON request data
15
+ P = float(data.get("P", 5000)) # Default: 5000
16
+ i = float(data.get("i", 12)) # Default: 12% annual
17
+ n = int(data.get("n", 10)) # Default: 10 years
18
+
19
+ # Convert annual interest rate to monthly and decimal
20
+ monthly_rate = i / 12 / 100
21
+ n_payments = n * 12
22
+
23
+ M = calculate_sip(P, monthly_rate, n_payments)
24
+ total_invested = P * n_payments
25
+ estimated_returns = M - total_invested
26
+
27
+ return jsonify({
28
+ "monthly_investment": P,
29
+ "annual_interest_rate": i,
30
+ "years": n,
31
+ "final_amount": M,
32
+ "total_invested": total_invested,
33
+ "estimated_returns": estimated_returns
34
+ })
35
+
36
+ except Exception as e:
37
+ return jsonify({"error": str(e)}), 400 # Return error in JSON format
38
+
39
+ if __name__ == '__main__':
40
+ app.run(host='0.0.0.0', port=5000, debug=True)