fable just walked me through a logic error in my own trades report design. quite impressed with this.


basically I am trying to get at reconciling EoM balances with PnL.
for this I need realized PnL (easy) + unrealized PnL.
the first problem is pretty basic and was already solved for:
unrealized PnL carries over from balances already accounted for in previous months.
for example you have $1000 in balance, and in May you have a position up $100. Let's say that position is now $300 unrealized in June. Your balance was $1,100 at the end of May and if everything is correct, it should be $1,300 in June.
but if you factor in the entire position open PnL your trade report will say that your balance should be $1,400 because you're duplicating the already accounted for $100 from May.
so we have to subtract unrealized PnL from previous periods.
it becomes a bit more tricky because I do a lot of daily rebalances so we have thousands of transactions that we need to account for their fills, when, and their contribution to that position's unrealized PnL this month.
so far fine, pretty basic stuff.
the problem fable found was that I was not thinking about when we account the realized PnL for current month (the correct value from an accounting perspective) we have to factor in the portion of the PnL that was accounted as unrealized in previous month's balances, otherwise we are double counting their effect.
in our previous example lets say that in June we book the full $300 profit when we close the position. THIS is the correct value as far as an accountant is concerned.
however to match with the balances tracker, it means I have to remove the portion that was realized/added in previous months from the unrealized PnL , almost like a deduction of booked values from previous months.
this is a bit of conflict between internal tracking and for accounting purposes but they must match otherwise i can't always be sure my values are correct. I mean I know they are because of the exchange report of realized trades, which again is what matters for accounting purposes for now, but I am a bit anal about it.
PnL now reconciles perfectly with EoM balances.
I should've known better, getting dumber by the day as we use AI as a crutch for every problem we got.
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Repost
  • Share
Comment
Add a comment
Add a comment
No comments
  • Pinned