Support or guidance for Total P&L, Realized + Unrealized

I am looking for some help with getting the Realized & Unrealized P&L (percentage, and total $) for a user’s account, from the beginning of their account.

I posted the following in the Slack:

I’m looking for a quick way to calculate the P/L % and $ total, over the duration of a user’s account.It seems that using the /v2/account/portfolio/history endpoint, would make sense for this.

In a simple case I’d get the created_at date of the account, then query the above endpoint starting from the created_at date of the account.I would then look for the first " equity " value returned (call it say, startingVal ), and I would look for the most recent " equity " value (call it currentVal )

Then the equation is simple: ((currentVal - startingVal) / currentVal) * 100

I think there is a flaw in this approach however, because it doesn’t account for cash transactions into (and out of) the user’s account. Does anyone have a better idea of how to formulate this?

A user answered:

I run the same calc on my own portfolio, and you’re right - deposits/withdrawls just get blended in to the equity values.

The only idea I have to solve for this value is by using /v2/account/activities and parsing BUY/SELL/CASH-IN/CASH-OUT events, which I think could get pretty complicated.

Is there a better way to figure these values out with the current endpoints - if not, is there a possibility of simplifying this with some new schema?