From 5775d25e7218bf6fc300072a1317c6d3935afdd1 Mon Sep 17 00:00:00 2001 From: Pascal Date: Fri, 30 May 2025 21:09:35 +0200 Subject: [PATCH] refactor: remove erosion radio buttons and FMP API testing section from navbar --- pages/ETF_Portfolio_Builder.py | 90 +++++++++++++--------------------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/pages/ETF_Portfolio_Builder.py b/pages/ETF_Portfolio_Builder.py index 23cfa6b..c1502f9 100644 --- a/pages/ETF_Portfolio_Builder.py +++ b/pages/ETF_Portfolio_Builder.py @@ -1427,7 +1427,6 @@ def test_fmp_connection() -> bool: logger.info(f"FMP API call count: {st.session_state.api_calls}") if response.status_code == 200: - st.success("Successfully connected to FMP API") return True else: st.error(f"Failed to connect to FMP API: {response.status_code}") @@ -1866,64 +1865,51 @@ with st.sidebar: index=1 ) - # Erosion options - enable_erosion = st.radio( - "Enable NAV & Yield Erosion", - ["Yes", "No"], - index=1 - ) - # Run simulation button if st.button("Run Portfolio Simulation", type="primary", use_container_width=True): if not st.session_state.etf_allocations: st.error("Please add at least one ETF to your portfolio.") else: - try: - # Store parameters in session state - st.session_state.mode = simulation_mode - st.session_state.enable_drip = enable_drip == "Yes" - st.session_state.enable_erosion = enable_erosion == "Yes" - + # Store simulation parameters in session state + st.session_state.mode = simulation_mode + st.session_state.enable_drip = enable_drip == "Yes" + st.session_state.enable_erosion = True + + if simulation_mode == "Income Target": + st.session_state.target = monthly_target + else: + st.session_state.target = initial_capital + st.session_state.initial_capital = initial_capital + + # Run simulation + logger.info("Starting portfolio simulation...") + logger.info(f"ETF allocations: {st.session_state.etf_allocations}") + + tickers = [etf["ticker"] for etf in st.session_state.etf_allocations] + df_data = fetch_etf_data(tickers) + logger.info(f"Fetched ETF data:\n{df_data}") + + if df_data is not None and not df_data.empty: if simulation_mode == "Income Target": - st.session_state.target = monthly_target + logger.info(f"Allocating for income target: ${monthly_target}") + final_alloc = allocate_for_income(df_data, monthly_target, st.session_state.etf_allocations) else: - st.session_state.target = initial_capital - st.session_state.initial_capital = initial_capital + logger.info(f"Allocating for capital target: ${initial_capital}") + final_alloc = allocate_for_capital(df_data, initial_capital, st.session_state.etf_allocations) - # Run simulation - logger.info("Starting portfolio simulation...") - logger.info(f"ETF allocations: {st.session_state.etf_allocations}") + logger.info(f"Final allocation result:\n{final_alloc}") - tickers = [etf["ticker"] for etf in st.session_state.etf_allocations] - df_data = fetch_etf_data(tickers) - logger.info(f"Fetched ETF data:\n{df_data}") - - if df_data is not None and not df_data.empty: - if simulation_mode == "Income Target": - logger.info(f"Allocating for income target: ${monthly_target}") - final_alloc = allocate_for_income(df_data, monthly_target, st.session_state.etf_allocations) - else: - logger.info(f"Allocating for capital target: ${initial_capital}") - final_alloc = allocate_for_capital(df_data, initial_capital, st.session_state.etf_allocations) - - logger.info(f"Final allocation result:\n{final_alloc}") - - if final_alloc is not None and not final_alloc.empty: - st.session_state.simulation_run = True - st.session_state.df_data = df_data - st.session_state.final_alloc = final_alloc - st.success("Portfolio simulation completed!") - st.rerun() - else: - st.error("Failed to generate portfolio allocation. Please check your inputs and try again.") + if final_alloc is not None and not final_alloc.empty: + st.session_state.simulation_run = True + st.session_state.df_data = df_data + st.session_state.final_alloc = final_alloc + st.success("Portfolio simulation completed!") + st.rerun() else: - st.error("Failed to fetch ETF data. Please check your tickers and try again.") - - except Exception as e: - st.error(f"Error running simulation: {str(e)}") - logger.error(f"Error in simulation: {str(e)}") - logger.error(traceback.format_exc()) - + st.error("Failed to generate portfolio allocation. Please check your inputs and try again.") + else: + st.error("Failed to fetch ETF data. Please check your tickers and try again.") + # Add reset simulation button at the bottom of sidebar if st.button("🔄 Reset Simulation", use_container_width=True, type="secondary"): reset_simulation() @@ -1982,12 +1968,6 @@ with st.sidebar: debug_mode = st.checkbox("Enable Debug Mode", help="Show detailed error logs.") parallel_processing = st.checkbox("Enable Parallel Processing", value=True, help="Fetch data for multiple ETFs simultaneously") - - # Add FMP API test button - st.sidebar.subheader("FMP API Testing") - if st.sidebar.button("Test FMP API", key="test_fmp_api_button"): - test_fmp_data_fetching() - st.sidebar.success("Test completed. Check logs for details.") # Display results and interactive allocation adjustment UI after simulation is run if st.session_state.simulation_run and st.session_state.df_data is not None: