refactor: remove erosion radio buttons and FMP API testing section from navbar
This commit is contained in:
parent
7db493893e
commit
5775d25e72
@ -1427,7 +1427,6 @@ def test_fmp_connection() -> bool:
|
|||||||
logger.info(f"FMP API call count: {st.session_state.api_calls}")
|
logger.info(f"FMP API call count: {st.session_state.api_calls}")
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
st.success("Successfully connected to FMP API")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
st.error(f"Failed to connect to FMP API: {response.status_code}")
|
st.error(f"Failed to connect to FMP API: {response.status_code}")
|
||||||
@ -1866,64 +1865,51 @@ with st.sidebar:
|
|||||||
index=1
|
index=1
|
||||||
)
|
)
|
||||||
|
|
||||||
# Erosion options
|
|
||||||
enable_erosion = st.radio(
|
|
||||||
"Enable NAV & Yield Erosion",
|
|
||||||
["Yes", "No"],
|
|
||||||
index=1
|
|
||||||
)
|
|
||||||
|
|
||||||
# Run simulation button
|
# Run simulation button
|
||||||
if st.button("Run Portfolio Simulation", type="primary", use_container_width=True):
|
if st.button("Run Portfolio Simulation", type="primary", use_container_width=True):
|
||||||
if not st.session_state.etf_allocations:
|
if not st.session_state.etf_allocations:
|
||||||
st.error("Please add at least one ETF to your portfolio.")
|
st.error("Please add at least one ETF to your portfolio.")
|
||||||
else:
|
else:
|
||||||
try:
|
# Store simulation parameters in session state
|
||||||
# Store parameters in session state
|
st.session_state.mode = simulation_mode
|
||||||
st.session_state.mode = simulation_mode
|
st.session_state.enable_drip = enable_drip == "Yes"
|
||||||
st.session_state.enable_drip = enable_drip == "Yes"
|
st.session_state.enable_erosion = True
|
||||||
st.session_state.enable_erosion = enable_erosion == "Yes"
|
|
||||||
|
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":
|
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:
|
else:
|
||||||
st.session_state.target = initial_capital
|
logger.info(f"Allocating for capital target: ${initial_capital}")
|
||||||
st.session_state.initial_capital = initial_capital
|
final_alloc = allocate_for_capital(df_data, initial_capital, st.session_state.etf_allocations)
|
||||||
|
|
||||||
# Run simulation
|
logger.info(f"Final allocation result:\n{final_alloc}")
|
||||||
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]
|
if final_alloc is not None and not final_alloc.empty:
|
||||||
df_data = fetch_etf_data(tickers)
|
st.session_state.simulation_run = True
|
||||||
logger.info(f"Fetched ETF data:\n{df_data}")
|
st.session_state.df_data = df_data
|
||||||
|
st.session_state.final_alloc = final_alloc
|
||||||
if df_data is not None and not df_data.empty:
|
st.success("Portfolio simulation completed!")
|
||||||
if simulation_mode == "Income Target":
|
st.rerun()
|
||||||
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.")
|
|
||||||
else:
|
else:
|
||||||
st.error("Failed to fetch ETF data. Please check your tickers and try again.")
|
st.error("Failed to generate portfolio allocation. Please check your inputs and try again.")
|
||||||
|
else:
|
||||||
except Exception as e:
|
st.error("Failed to fetch ETF data. Please check your tickers and try again.")
|
||||||
st.error(f"Error running simulation: {str(e)}")
|
|
||||||
logger.error(f"Error in simulation: {str(e)}")
|
|
||||||
logger.error(traceback.format_exc())
|
|
||||||
|
|
||||||
# Add reset simulation button at the bottom of sidebar
|
# Add reset simulation button at the bottom of sidebar
|
||||||
if st.button("🔄 Reset Simulation", use_container_width=True, type="secondary"):
|
if st.button("🔄 Reset Simulation", use_container_width=True, type="secondary"):
|
||||||
reset_simulation()
|
reset_simulation()
|
||||||
@ -1982,12 +1968,6 @@ with st.sidebar:
|
|||||||
debug_mode = st.checkbox("Enable Debug Mode", help="Show detailed error logs.")
|
debug_mode = st.checkbox("Enable Debug Mode", help="Show detailed error logs.")
|
||||||
parallel_processing = st.checkbox("Enable Parallel Processing", value=True,
|
parallel_processing = st.checkbox("Enable Parallel Processing", value=True,
|
||||||
help="Fetch data for multiple ETFs simultaneously")
|
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
|
# 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:
|
if st.session_state.simulation_run and st.session_state.df_data is not None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user