@somnia-chain/markets-sdk / index / computePortfolioAnalytics
Function: computePortfolioAnalytics()
computePortfolioAnalytics(
events,opts):PortfolioAnalytics
Defined in: packages/sdk/src/unified/portfolioAnalytics.ts:335
Fold portfolio flow events into the metrics plane. PURE — every input is
explicit, so it runs identically in apps, bots, and tests. events may
arrive in any order; they are sorted oldest-first internally. Events
before the window establish the carried-in cost basis; events inside it
drive the equity curve.
Supply PortfolioFundingEvents to measure the return against real
external capital. Without them the capital base falls back to a trades-only
proxy that overstates the return for an account trading a small part of its
balance; mwrr.capitalBasis reports which definition applied.
Gotchas
- Throws InvalidInputError — a sampling bound is not a finite number:
asOf, any event'stimestamp, or the window start they derive. The equity series is sampled from those bounds, so a non-finite one leaves the loop's exit comparison false forever and the process allocates until it dies. The offending field is named in the message. Nothing is substituted and no event is dropped — an invalid time is the caller's to fix, and guessing one would silently misplace money on the curve.
Parameters
events
readonly PortfolioFlowEvent[]