Commit
·
0530756
1
Parent(s):
c5048d8
Added More time periods
Browse files
app.py
CHANGED
@@ -95,14 +95,24 @@ def update_sip_calculator(*args):
|
|
95 |
total_weight = sum(schemes.values())
|
96 |
|
97 |
end_date = datetime.now().date()
|
|
|
98 |
if period == "Custom":
|
99 |
if not custom_start_date or not custom_end_date:
|
100 |
return "Please provide both start and end dates for custom period.", None, None, None
|
101 |
start_date = datetime.strptime(custom_start_date, "%Y-%m-%d").date()
|
102 |
end_date = datetime.strptime(custom_end_date, "%Y-%m-%d").date()
|
|
|
|
|
|
|
|
|
103 |
else:
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
try:
|
108 |
portfolio_return, final_value, total_investment, scheme_returns = calculate_portfolio_returns(schemes, sip_amount, start_date, end_date, SIP_Date,schemes_df)
|
@@ -206,10 +216,10 @@ def create_ui():
|
|
206 |
gr.Markdown("# Mutual Fund SIP Returns Calculator")
|
207 |
|
208 |
with gr.Row():
|
209 |
-
period = gr.Dropdown(choices=["1 year", "3 years", "5 years", "7 years", "10 years", "Custom"], label="Select Period")
|
210 |
custom_start_date = gr.Textbox(label="Custom Start Date (YYYY-MM-DD)", visible=False)
|
211 |
custom_end_date = gr.Textbox(label="Custom End Date (YYYY-MM-DD)", visible=False)
|
212 |
-
SIP_Date = gr.Dropdown(label="SIP Date", choices=["start","middle","end"])
|
213 |
|
214 |
sip_amount = gr.Number(label="SIP Amount (₹)")
|
215 |
|
|
|
95 |
total_weight = sum(schemes.values())
|
96 |
|
97 |
end_date = datetime.now().date()
|
98 |
+
|
99 |
if period == "Custom":
|
100 |
if not custom_start_date or not custom_end_date:
|
101 |
return "Please provide both start and end dates for custom period.", None, None, None
|
102 |
start_date = datetime.strptime(custom_start_date, "%Y-%m-%d").date()
|
103 |
end_date = datetime.strptime(custom_end_date, "%Y-%m-%d").date()
|
104 |
+
|
105 |
+
elif period == "YTD":
|
106 |
+
start_date = datetime(end_date.year, 1, 1)
|
107 |
+
|
108 |
else:
|
109 |
+
# check if string contaiins year
|
110 |
+
if 'year' in period.split()[1]:
|
111 |
+
years = int(period.split()[0])
|
112 |
+
start_date = end_date - timedelta(days=years*365)
|
113 |
+
else:
|
114 |
+
months = int(period.split()[0])
|
115 |
+
start_date = end_date - timedelta(days=months*30)
|
116 |
|
117 |
try:
|
118 |
portfolio_return, final_value, total_investment, scheme_returns = calculate_portfolio_returns(schemes, sip_amount, start_date, end_date, SIP_Date,schemes_df)
|
|
|
216 |
gr.Markdown("# Mutual Fund SIP Returns Calculator")
|
217 |
|
218 |
with gr.Row():
|
219 |
+
period = gr.Dropdown(choices=["YTD", "1 month","3 months","6 months","1 year", "3 years", "5 years", "7 years", "10 years","15 years","20 years", "Custom"], label="Select Period")
|
220 |
custom_start_date = gr.Textbox(label="Custom Start Date (YYYY-MM-DD)", visible=False)
|
221 |
custom_end_date = gr.Textbox(label="Custom End Date (YYYY-MM-DD)", visible=False)
|
222 |
+
SIP_Date = gr.Dropdown(label="Monthly SIP Date", choices=["start","middle","end"])
|
223 |
|
224 |
sip_amount = gr.Number(label="SIP Amount (₹)")
|
225 |
|