GithubHelp home page GithubHelp logo

Comments (2)

cjdsellers avatar cjdsellers commented on May 31, 2024

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.

jpmediadev avatar jpmediadev commented on May 31, 2024

I've made that change and will be on develop in the next push.

Thank you!

from nautilus_trader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.