prasanth.thangavel commited on
Commit
e22872a
·
1 Parent(s): a71b954

Made improvements

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py CHANGED
@@ -184,6 +184,65 @@ fig.update_layout(
184
  # Display the plot
185
  st.plotly_chart(fig, use_container_width=True)
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  # Calculate and display final returns
188
  st.subheader("Final Investment Values")
189
  for asset in selected_assets:
 
184
  # Display the plot
185
  st.plotly_chart(fig, use_container_width=True)
186
 
187
+ # Create a summary table
188
+ st.subheader("Investment Summary")
189
+ summary_data = []
190
+ for asset in selected_assets:
191
+ valid_series = returns_data[asset].dropna()
192
+ if not valid_series.empty:
193
+ final_value = valid_series.iloc[-1]
194
+ days = (valid_series.index[-1] - valid_series.index[0]).days
195
+ years = days / 365
196
+ annualized_return = ((final_value / initial_investment) ** (1/years) - 1) * 100
197
+
198
+ # Calculate yearly return statistics
199
+ yearly_data = valid_series.resample('Y').first()
200
+ yearly_returns = yearly_data.pct_change().dropna()
201
+ positive_years = (yearly_returns > 0).sum()
202
+ total_years = len(yearly_returns)
203
+ positive_percentage = (positive_years / total_years) * 100
204
+
205
+ summary_data.append({
206
+ "Asset": asset,
207
+ f"Final Value ({currency_symbol})": final_value,
208
+ "Annualized Return (%)": annualized_return,
209
+ "Positive Years": f"{positive_years}/{total_years}",
210
+ "Positive Years %": positive_percentage
211
+ })
212
+ else:
213
+ summary_data.append({
214
+ "Asset": asset,
215
+ f"Final Value ({currency_symbol})": None,
216
+ "Annualized Return (%)": None,
217
+ "Positive Years": "N/A",
218
+ "Positive Years %": None
219
+ })
220
+
221
+ # Convert to DataFrame
222
+ df = pd.DataFrame(summary_data)
223
+
224
+ # Format the display values
225
+ df[f"Final Value ({currency_symbol})"] = df[f"Final Value ({currency_symbol})"].apply(lambda x: f"{x:,.2f}" if x is not None else "N/A")
226
+ df["Annualized Return (%)"] = df["Annualized Return (%)"].apply(lambda x: f"{x:.2f}" if x is not None else "N/A")
227
+ df["Positive Years %"] = df["Positive Years %"].apply(lambda x: f"{x:.1f}" if x is not None else "N/A")
228
+
229
+ # Display the summary table with sorting enabled
230
+ st.dataframe(
231
+ df,
232
+ hide_index=True,
233
+ column_config={
234
+ f"Final Value ({currency_symbol})": st.column_config.NumberColumn(
235
+ format="%.2f"
236
+ ),
237
+ "Annualized Return (%)": st.column_config.NumberColumn(
238
+ format="%.2f"
239
+ ),
240
+ "Positive Years %": st.column_config.NumberColumn(
241
+ format="%.1f"
242
+ )
243
+ }
244
+ )
245
+
246
  # Calculate and display final returns
247
  st.subheader("Final Investment Values")
248
  for asset in selected_assets: