refactor: Fix indentation and remove unused portfolio code
This commit is contained in:
parent
51ebdc1d74
commit
a643a1649e
@ -28,10 +28,10 @@ def trading_system_page():
|
||||
step=0.1)
|
||||
|
||||
with col2:
|
||||
entry_price = st.number_input("Entry Price ($)", min_value=0.01, step=0.01)
|
||||
target_price = st.number_input("Target Price ($)", min_value=0.01, step=0.01)
|
||||
|
||||
if st.button("Calculate Position"):
|
||||
entry_price = st.number_input("Entry Price ($)", min_value=0.01, step=0.01)
|
||||
target_price = st.number_input("Target Price ($)", min_value=0.01, step=0.01)
|
||||
|
||||
if st.button("Calculate Position"):
|
||||
try:
|
||||
calculator = PositionCalculator(
|
||||
account_size=account_size,
|
||||
@ -56,98 +56,3 @@ def trading_system_page():
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"Error calculating position: {str(e)}")
|
||||
|
||||
# Initialize portfolio if not in session state
|
||||
if 'portfolio' not in st.session_state:
|
||||
st.session_state.portfolio = Portfolio()
|
||||
|
||||
# Load existing open trades into portfolio
|
||||
open_trades = get_open_trades()
|
||||
for trade in open_trades:
|
||||
position = Position(
|
||||
symbol=trade['ticker'],
|
||||
entry_date=trade['entry_date'],
|
||||
entry_price=trade['entry_price'],
|
||||
shares=trade['shares'],
|
||||
stop_loss=trade['stop_loss'],
|
||||
target_price=trade['target_price']
|
||||
)
|
||||
st.session_state.portfolio.add_position(position)
|
||||
|
||||
# Add position form
|
||||
with st.expander("Add New Position"):
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
symbol = st.text_input("Symbol").upper()
|
||||
shares = st.number_input("Number of Shares", min_value=1, step=1)
|
||||
entry_price = st.number_input("Entry Price ($)", min_value=0.01, step=0.01, key="port_entry_price")
|
||||
|
||||
with col2:
|
||||
target_price = st.number_input("Target Price ($)", min_value=0.01, step=0.01, key="port_target_price")
|
||||
stop_loss = st.number_input("Stop Loss ($)", min_value=0.01, step=0.01)
|
||||
|
||||
if st.button("Add Position"):
|
||||
try:
|
||||
position = Position(
|
||||
symbol=symbol,
|
||||
entry_date=datetime.now(),
|
||||
entry_price=entry_price,
|
||||
shares=shares,
|
||||
stop_loss=stop_loss,
|
||||
target_price=target_price
|
||||
)
|
||||
st.session_state.portfolio.add_position(position)
|
||||
st.success(f"Added position: {symbol}")
|
||||
except Exception as e:
|
||||
st.error(f"Error adding position: {str(e)}")
|
||||
|
||||
# Display current portfolio
|
||||
positions = st.session_state.portfolio.get_position_summary()
|
||||
if positions:
|
||||
st.subheader("Current Positions")
|
||||
# Add a counter to make unique keys
|
||||
for i, pos in enumerate(positions):
|
||||
with st.expander(f"{pos['symbol']} Position - {format_datetime(pos['entry_date'])}"):
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.metric("Entry Price", f"${pos['entry_price']:.2f}" if pos['entry_price'] is not None else "N/A")
|
||||
st.metric("Shares", pos['shares'] if pos['shares'] is not None else "N/A")
|
||||
st.metric("Current Value", f"${pos['current_value']:.2f}" if pos['current_value'] is not None else "N/A")
|
||||
|
||||
with col2:
|
||||
st.metric("Stop Loss", f"${pos['stop_loss']:.2f}" if pos['stop_loss'] is not None else "N/A")
|
||||
st.metric("Target", f"${pos['target_price']:.2f}" if pos['target_price'] is not None else "N/A")
|
||||
st.metric("Risk/Reward", f"{pos['risk_reward_ratio']:.2f}" if pos['risk_reward_ratio'] is not None else "N/A")
|
||||
|
||||
if st.button(f"Remove {pos['symbol']}", key=f"remove_{pos['symbol']}_{i}"):
|
||||
st.session_state.portfolio.remove_position(pos['symbol'])
|
||||
st.rerun()
|
||||
else:
|
||||
st.info("No positions in portfolio")
|
||||
|
||||
with value_tab:
|
||||
st.subheader("Portfolio Value Management")
|
||||
|
||||
# Get latest portfolio value
|
||||
portfolio_data = get_latest_portfolio_value()
|
||||
|
||||
if portfolio_data:
|
||||
st.metric("Current Portfolio Value", f"${portfolio_data['total_value']:,.2f}")
|
||||
st.metric("Cash Balance", f"${portfolio_data['cash_balance']:,.2f}")
|
||||
st.text(f"Last Updated: {portfolio_data['date']}")
|
||||
else:
|
||||
st.info("No portfolio value data found")
|
||||
|
||||
# Update portfolio value form
|
||||
with st.expander("Update Portfolio Value"):
|
||||
new_value = st.number_input("New Portfolio Value ($)", min_value=0.0, step=100.0)
|
||||
new_cash = st.number_input("New Cash Balance ($)", min_value=0.0, step=100.0)
|
||||
notes = st.text_area("Notes (optional)", key="portfolio_value_notes")
|
||||
|
||||
if st.button("Update Values"):
|
||||
try:
|
||||
update_portfolio_value(new_value, new_cash, notes)
|
||||
st.success("Portfolio value updated successfully!")
|
||||
st.set_query_params(rerun=True)
|
||||
except Exception as e:
|
||||
st.error(f"Error updating portfolio value: {str(e)}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user