How do you calculate your PnL in your software?

Discussion in 'App Development' started by runtrader, Sep 29, 2016.

  1. runtrader

    runtrader

    I'm refactoring my backtesting engine in my software and adding additional functionality and thought I'd look into different methods of PnL calculation.

    I'm interested in how others calculate PnL in their trading systems. There are various methods - FIFO, LIFO and the average cost method. Wondering if anyone has any insight into which is the preferred method and why?
     
  2. Preferred method is MTM, in order to get correct daily returns. LIFO/FIFO matter only for taxes.
     
  3. In my backtester I close the positions FIFO since it's easier to program. It really doesn't matter.
    e.g. I opened a series of long EURUSD positions and now I start opening a series of shorts to close the longs. I start at the oldest and move forward in time. Mathematically it doesn't matter in the end.
     
  4. runtrader

    runtrader

    Thanks for the responses guys. The position management in my strategies cause constant scaling in and out and thus potentially many fills for an instrument. With FIFO you have to cycle through every fill each time (unless you keep some intermediate state), but I agree mathematically it doesn't matter in the end.

    I'm using the average cost method due to simplicity and speed.

    I use this this as my test case,
    https://www.tradingtechnologies.com...tion-algorithm/understanding-pl-calculations/

    I'd be interested in hearing about any other resources where I could find similar examples that could be used for test cases.
     
  5. zupdawg

    zupdawg

    FIFO LIFO matters only if you care about realized vs unrealized P&L. I personally don't, except maybe for taxes if you're trading on a personal account.

    When you're backtrading there are other things I'd worry more about, such as whether your data incorporates all dividends, stock splits, acquisitions. And that you avoid any selection bias such as only trading companies that still exist today
     
  6. 931

    931

    Spread, comission , -interest , all factors good to have.
    Usign avg price for execution may not work on all algos well as real tickdata comes in differently.
    May be good if algo concludes its entry point based on data before last bar, then less dif under live/test.