Performance Attribution API

Is there an API to gather performance attribution for various positions? I have a paper portfolio running with around 450 stock positions. The portfolio has recently experience an outsized loss and I’m trying to understand which security (or securities) on a particular day lead to this huge move.

Currently the web POSITIONS page leaves a lot to be desired in terms of your ability to understand how the aggregate portfolio P&L was driven each day, historically. As far as I can tell, the POSITIONS page, for example, while purporting to show TOTAL P&L doesn’t seem to be accurate, since if I add up all the losses they don’t come close to what the HOME page shows on the line chart (i’m assuming this line chart is unrealized P&L? But there’s no tittle so it’s not obvious either).

Thanks

I would extract all orders and connect it via symbol.

Could you go into a bit more detail?

  1. You extract the closed orders:
    Orders | Alpaca Docs

  2. Put the order values into a pandas data frame.

  3. Calculate order value for each order: (qty * filled_avg_price) (*-1 for buy order)

  4. Export it into a csv

  5. Make a pivot table in Excel

  6. Group by symbol and calculate PnL via order value

(5.+6. can also be done in python instead of Excel)

Thanks, so basically you’re saying to manually extract all the orders and avg fill prices, then merge this with price data to compute P&L.

1 Like

Yes but no need to merge with price data because you getting all fill prices with the orders.