"""PnL calculation functions for the portfolio manager.""" from decimal import Decimal def calculate_unrealized_pnl( quantity: Decimal, avg_entry_price: Decimal, current_price: Decimal, ) -> Decimal: """Calculate unrealized PnL for an open position.""" return quantity * (current_price - avg_entry_price) def calculate_realized_pnl( buy_price: Decimal, sell_price: Decimal, quantity: Decimal, fee: Decimal = Decimal("0"), ) -> Decimal: """Calculate realized PnL for a completed trade.""" return quantity * (sell_price - buy_price) - fee