calculate_pnl#
API documentation for tradeexecutor.strategy.pnl.calculate_pnl Python function.
- calculate_pnl(position, end_at=None, mark_price=None, epsilon=1e-06, max_annualised_profit=100)[source]#
Calculate the Profit and Loss (PnL) for a given trading position.
Use cumulative trading cost method
Calculate all profit variables in one pass
Works for realised and unrealised PnL
See also
tradeexecutor.visualisation.position.calculate_position_timeline()
.- Parameters:
end_at (datetime) – For non-closed positions you need to provide the end_at timestamp until we calculate the PnL.
mark_price (float) –
For non-closed positions you need to provide the mark_price to calculate the unrealised PnL.
If not given, use
TradingPosition.last_token_price
.position (tradeexecutor.state.position.TradingPosition) –
epsilon (float) –
max_annualised_profit (float) –
- Returns:
Profit in dollar and percentage, annualised percentage.
- Return type: