vibhorag101
commited on
Commit
•
80f6abb
1
Parent(s):
57f491f
Added functionality to show current weightage
Browse files
app.py
CHANGED
@@ -130,7 +130,7 @@ def update_sip_calculator(*args):
|
|
130 |
|
131 |
# Check if start_date is before any scheme's inception date
|
132 |
inception_warnings = []
|
133 |
-
earliest_inception_date =
|
134 |
for scheme_name, inception_date in inception_dates:
|
135 |
if start_date < inception_date.date():
|
136 |
inception_warnings.append(f"Warning: {scheme_name} inception date ({inception_date.date()}) is after the chosen start date ({start_date}).")
|
@@ -139,7 +139,7 @@ def update_sip_calculator(*args):
|
|
139 |
if inception_warnings:
|
140 |
result += "The following warnings were found:\n"
|
141 |
result += "\n".join(inception_warnings) + "\n\n"
|
142 |
-
result += f"
|
143 |
|
144 |
result += f"Total portfolio SIP return: {portfolio_return:.2f}%\n"
|
145 |
result += f"Total investment: ₹{total_investment:.2f}\n"
|
@@ -185,7 +185,25 @@ def update_schemes_list(schemes_list, updated_data):
|
|
185 |
|
186 |
def update_schemes_table(schemes_list):
|
187 |
df = pd.DataFrame(schemes_list, columns=["Scheme Name", "Weight (%)"])
|
188 |
-
df["Actions"] = "❌"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
return df
|
190 |
|
191 |
def add_scheme_to_list(schemes_list, scheme_name, weight):
|
@@ -196,7 +214,16 @@ def add_scheme_to_list(schemes_list, scheme_name, weight):
|
|
196 |
|
197 |
def update_schemes(schemes_list, updated_data):
|
198 |
try:
|
199 |
-
new_schemes_list =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
if not new_schemes_list:
|
201 |
return schemes_list, update_schemes_table(schemes_list), "No valid schemes found in the table."
|
202 |
return new_schemes_list, update_schemes_table(new_schemes_list), None
|
@@ -215,11 +242,13 @@ def handle_row_selection(schemes_list, evt: gr.SelectData, table_data):
|
|
215 |
column_index = evt.index[1]
|
216 |
if column_index == 2: # "Actions" column
|
217 |
row_index = evt.index[0]
|
218 |
-
#
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
223 |
return table_data, schemes_list
|
224 |
|
225 |
def create_ui():
|
@@ -229,10 +258,10 @@ def create_ui():
|
|
229 |
gr.Markdown("# Mutual Fund SIP Returns Calculator")
|
230 |
|
231 |
with gr.Row():
|
232 |
-
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")
|
233 |
custom_start_date = gr.Textbox(label="Custom Start Date (YYYY-MM-DD)", visible=False)
|
234 |
custom_end_date = gr.Textbox(label="Custom End Date (YYYY-MM-DD)", visible=False)
|
235 |
-
SIP_Date = gr.Dropdown(label="Monthly SIP Date", choices=["start","middle","end"])
|
236 |
with gr.Column():
|
237 |
use_inception_date = gr.Checkbox(label="Use Earliest Inception Date", value=False)
|
238 |
inception_date_display = gr.Textbox(label="Earliest Inception Date", interactive=False)
|
|
|
130 |
|
131 |
# Check if start_date is before any scheme's inception date
|
132 |
inception_warnings = []
|
133 |
+
earliest_inception_date = max(inception_date for _, inception_date in inception_dates)
|
134 |
for scheme_name, inception_date in inception_dates:
|
135 |
if start_date < inception_date.date():
|
136 |
inception_warnings.append(f"Warning: {scheme_name} inception date ({inception_date.date()}) is after the chosen start date ({start_date}).")
|
|
|
139 |
if inception_warnings:
|
140 |
result += "The following warnings were found:\n"
|
141 |
result += "\n".join(inception_warnings) + "\n\n"
|
142 |
+
result += f"Possible start date for all chosen schemes is: {earliest_inception_date.date()}\n\n"
|
143 |
|
144 |
result += f"Total portfolio SIP return: {portfolio_return:.2f}%\n"
|
145 |
result += f"Total investment: ₹{total_investment:.2f}\n"
|
|
|
185 |
|
186 |
def update_schemes_table(schemes_list):
|
187 |
df = pd.DataFrame(schemes_list, columns=["Scheme Name", "Weight (%)"])
|
188 |
+
df["Actions"] = "❌"
|
189 |
+
|
190 |
+
# Calculate the sum of weights
|
191 |
+
total_weight = df["Weight (%)"].sum()
|
192 |
+
|
193 |
+
# Add a row for the total
|
194 |
+
total_row = pd.DataFrame({
|
195 |
+
"Scheme Name": ["Total"],
|
196 |
+
"Weight (%)": [total_weight],
|
197 |
+
"Actions": [""]
|
198 |
+
})
|
199 |
+
|
200 |
+
# Concatenate the original dataframe with the total row
|
201 |
+
df = pd.concat([df, total_row], ignore_index=True)
|
202 |
+
|
203 |
+
# Add a warning if total weight exceeds 100%
|
204 |
+
if total_weight > 100:
|
205 |
+
df.loc[df.index[-1], "Actions"] = "⚠️ Exceeds 100%"
|
206 |
+
|
207 |
return df
|
208 |
|
209 |
def add_scheme_to_list(schemes_list, scheme_name, weight):
|
|
|
214 |
|
215 |
def update_schemes(schemes_list, updated_data):
|
216 |
try:
|
217 |
+
new_schemes_list = []
|
218 |
+
for _, row in updated_data.iterrows():
|
219 |
+
scheme_name = row.get('Scheme Name')
|
220 |
+
weight = row.get('Weight (%)')
|
221 |
+
if scheme_name != 'Total' and weight is not None:
|
222 |
+
try:
|
223 |
+
weight_float = float(weight)
|
224 |
+
new_schemes_list.append((scheme_name, weight_float))
|
225 |
+
except ValueError:
|
226 |
+
continue
|
227 |
if not new_schemes_list:
|
228 |
return schemes_list, update_schemes_table(schemes_list), "No valid schemes found in the table."
|
229 |
return new_schemes_list, update_schemes_table(new_schemes_list), None
|
|
|
242 |
column_index = evt.index[1]
|
243 |
if column_index == 2: # "Actions" column
|
244 |
row_index = evt.index[0]
|
245 |
+
if row_index < len(table_data) - 1: # Ensure we're not trying to delete the total row
|
246 |
+
# Remove the row
|
247 |
+
table_data = table_data.drop(row_index).reset_index(drop=True)
|
248 |
+
# Update the schemes_list
|
249 |
+
updated_schemes_list = [(row['Scheme Name'], row['Weight (%)']) for _, row in table_data.iterrows() if row['Scheme Name'] != 'Total']
|
250 |
+
# Recalculate the total
|
251 |
+
return update_schemes_table(updated_schemes_list), updated_schemes_list
|
252 |
return table_data, schemes_list
|
253 |
|
254 |
def create_ui():
|
|
|
258 |
gr.Markdown("# Mutual Fund SIP Returns Calculator")
|
259 |
|
260 |
with gr.Row():
|
261 |
+
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",value="YTD")
|
262 |
custom_start_date = gr.Textbox(label="Custom Start Date (YYYY-MM-DD)", visible=False)
|
263 |
custom_end_date = gr.Textbox(label="Custom End Date (YYYY-MM-DD)", visible=False)
|
264 |
+
SIP_Date = gr.Dropdown(label="Monthly SIP Date", choices=["start","middle","end"],value="end")
|
265 |
with gr.Column():
|
266 |
use_inception_date = gr.Checkbox(label="Use Earliest Inception Date", value=False)
|
267 |
inception_date_display = gr.Textbox(label="Earliest Inception Date", interactive=False)
|