# Portfolio Management

This guide explains the Portfolio view and how to interpret portfolio metrics.

## Portfolio View Features

The Portfolio page provides a comprehensive view of your trading portfolio with three main tabs:

### Overview Tab

#### Summary Cards

At the top of the page, you'll see four summary cards:
- **Current Value**: Current portfolio value (cash + positions)
- **Unrealized P&L**: Profit/loss on open positions (color-coded: green for profit, red for loss)
- **Realized P&L**: Profit/loss from closed trades
- **Daily Change**: Percentage change in portfolio value today

#### Portfolio Value History Chart

An equity curve chart showing:
- Portfolio value over time (last 30 days by default)
- P&L line showing profit/loss progression
- Interactive tooltips showing exact values on hover

#### Risk Metrics

A grid of risk metrics cards showing:
- **Sharpe Ratio**: Risk-adjusted return measure
- **Sortino Ratio**: Downside risk-adjusted return
- **Max Drawdown**: Largest historical decline (percentage)
- **Win Rate**: Percentage of profitable trades
- **Total Return**: Overall return percentage

#### Holdings

All open positions displayed as cards showing:
- **Symbol**: Trading pair
- **Quantity**: Amount held (8 decimal precision)
- **Entry Price**: Average entry price
- **Current Price**: Latest market price
- **Value**: Current position value
- **Unrealized P&L**: Profit/loss with percentage change
- **Realized P&L**: Profit/loss from closed portions
- **Close Position Button**: Close the position directly from the card

Each position card is color-coded with a chip showing the P&L percentage.

### Allocations Tab

A pie chart visualization showing:
- Portfolio allocation by asset
- Percentage breakdown for each holding
- Interactive tooltips with exact dollar values
- Color-coded segments for easy identification

This helps you visualize your portfolio distribution and identify over-concentration in specific assets.

### Reports & Export Tab

Export functionality for:
- **Export Trades**: Download all trading history as CSV
- **Export Portfolio**: Download current portfolio holdings as CSV
- **Tax Reporting**: Generate tax reports using FIFO or LIFO methods

### Risk Metrics

- **Current Drawdown**: Current decline from peak value
- **Max Drawdown**: Largest historical decline
- **Sharpe Ratio**: Risk-adjusted return measure
- **Sortino Ratio**: Downside risk-adjusted return
- **Win Rate**: Percentage of profitable trades

### Performance Chart

The equity curve chart shows portfolio value over time, helping you visualize performance trends.

## Understanding Metrics

### Sharpe Ratio
Measures risk-adjusted returns. Higher values indicate better risk-adjusted performance:
- **> 1**: Good
- **> 2**: Very good
- **> 3**: Excellent

### Sortino Ratio
Similar to Sharpe but only considers downside volatility. Better for asymmetric return distributions.

### Drawdown
Maximum peak-to-trough decline. Lower is better:
- **< 10%**: Low risk
- **10-20%**: Moderate risk
- **> 20%**: High risk

## Closing Positions from Portfolio

You can close positions directly from the Portfolio page:

1. Navigate to the **Portfolio** page
2. In the **Overview** tab, find the position card you want to close
3. Click **Close Position** button on the card
4. In the dialog:
   - Choose order type (Market or Limit)
   - For limit orders, enter the limit price
5. Click **Close Position** to confirm

The position will be closed and removed from your holdings. You'll receive a notification when the order is filled.

## Data Freshness

The Portfolio page shows a data freshness indicator in the header showing when the data was last updated. The page automatically refreshes every 5 seconds to show the latest data.

## Exporting Data

### Export Trades

1. Navigate to **Portfolio** > **Reports & Export** tab
2. Click **Export Trades CSV** button
3. The file will download with all your trading history

### Export Portfolio

1. Navigate to **Portfolio** > **Reports & Export** tab
2. Click **Export Portfolio CSV** button
3. The file will download with current holdings

### Tax Reports

1. Navigate to **Portfolio** > **Reports & Export** tab
2. Select tax method (FIFO or LIFO)
3. Enter tax year
4. Optionally filter by symbol
5. Click **Generate Tax Report**
6. The CSV file will download with tax reporting information
