Comments (2)
Good pickup. This is the block of code relating to the issue;
# Calculate potential PnL
cdef Money pnl = None
if position is not None and position.entry != order.side:
# Calculate PnL
pnl = position.calculate_pnl(
avg_open=position.avg_open,
avg_close=fill_price,
quantity=order.quantity,
)
cdef Currency currency # Settlement currency
if self.default_currency is not None: # Single-asset account
currency = self.default_currency
if pnl is None:
pnl = Money(0, currency)
if commission.currency != currency:
# Calculate exchange rate to account currency
xrate = self.get_xrate(
from_currency=commission.currency,
to_currency=currency,
price_type=PriceType.BID if order.side is OrderSide.SELL else PriceType.ASK,
)
# Convert to account currency
commission = Money(commission * xrate, currency)
pnl = Money(pnl * xrate, currency)
total_commissions = self.total_commissions.get(currency, Decimal()) + commission
self.total_commissions[currency] = Money(total_commissions, currency)
# Final PnL
pnl = Money(pnl - commission, self.default_currency)
else:
currency = instrument.settlement_currency
if pnl is None:
pnl = Money(0, currency)
The problem is where for a multi-asset account, when a position is not being reduced the commission is not being added to the pnl
for the fill.
So the final else block should be;
else:
currency = instrument.settlement_currency
if pnl is None:
pnl = commission
I've made that change and will be on develop
in the next push.
from nautilus_trader.
I've made that change and will be on develop in the next push.
Thank you!
from nautilus_trader.
Related Issues (20)
- logging: Error sending log event: is printed when logging messages if the logger is manually created HOT 6
- Compliation failed at master branch HOT 1
- BacktestNode won't clear data in streaming mode HOT 2
- `on_position_event` callback receives each event twice HOT 1
- Performance regression between 1.88.0 and 1.89.0 HOT 4
- Add bars processing method for `TradeTickDataWrangler` HOT 1
- Process `OrderBookDeltas` for backtest streaming
- Only small part of Orders are filled when multi symbol orders Submitted in Single Actor(Backtest Mode) HOT 1
- Incorrect order fills with bar data HOT 12
- Creating strategy with data sources from both binance spot and binance futures do not work HOT 5
- Order Filled After Cancellation Request Triggers Backtest Failure HOT 6
- BinanceBar ts_event not consistent HOT 1
- Add CFD and Commodity support for Interactive Brokers HOT 1
- Backtesting process halts upon Unsubscribing from Internal TimeBars during Mid-Test HOT 4
- No account registered error for IBKR HOT 8
- Delays for live trading HOT 3
- Sell order denied due to CUM_NOTIONAL_EXCEEDS_FREE_BALANCE when there is enough balance HOT 4
- Addition of Sequence Number in QuoteTick HOT 2
- Polygon.io integration HOT 1
- Sandbox: Error on applying OrderFilled due to incorrect venu_order_id HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nautilus_trader.