Skip to content

[SDK] Add a member return correlation matrix #1201

Closed

Description

@collinsezedike

Summary

Compute the pairwise correlation of member return series produced by a composed run, so a composition can show whether its members diversify or move together.

Motivation

Correlation exists today only for simulated asset price paths (packages/strategies/src/correlated-paths.ts:56-94), never for strategy returns. Two members can each be sound in isolation yet rise and fall together, which is the risk a composition is meant to reveal. Without a return-correlation view, a user cannot tell a genuine diversifier from a duplicate position.

Proposed Solution

  • Add a correlationMatrix(memberReturns) function in packages/strategies/src/composition/ that takes the per-member return series from the composed runner ([SDK] Add the composed backtest runner and per-member attribution #1200) and returns a symmetric matrix of Decimal correlation coefficients with a unit diagonal.
  • Handle zero-variance members explicitly by surfacing the correlation as undefined rather than NaN, consistent with the guarded division already used in packages/strategies/src/risk-metrics.ts.
  • Reuse the existing Decimal utilities; introduce no new dependency.

Scope

Field Value
Area SDK
Protocol affected None
Network testnet
Breaking change? No

Alternatives Considered

  • Compute correlation from simulated price paths rather than member returns. Rejected, because the quantity of interest is how the strategies behave, not how their underlying assets do.
  • Add a full covariance module. Rejected as out of scope; a correlation matrix satisfies the composition view and can be extended later.

Acceptance Criteria

  • A known input yields the expected matrix, including a perfectly correlated and a perfectly anti-correlated pair.
  • A zero-variance member yields an explicit undefined entry, not NaN.
  • The matrix is symmetric with a unit diagonal.
  • pnpm --filter @meridian/strategies test and npx tsc --noEmit pass.

Additional Context

Depends on the composition interface, #1197, and the composed backtest runner, #1200, for the member return series it consumes. Part of the Meridian Strategies initiative.

Star the repo

Please star this repository before picking up this issue. It is a small ask that meaningfully helps the project reach more people.

Activity

  1. added
    enhancementNew feature or request
    mediumRequires familiarity with the Meridian codebase or relevant tooling; expect 4–8 hours
    sdkInvolves Blend or DeFindex SDK helpers in packages/stellar-sdk-helpers
    on Oct 19, 2026
  2. camesenin commented on Oct 19, 2026

    @camesenin
    Contributor

    @camesenin has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    Hi @maintainers and drydocs/meridian team!

    I would love to tackle issue #1201: [SDK] Add a member return correlation matrix.

    Execution Plan:

    1. Analyze repository architecture, module dependencies, and exact requirements.
    2. Implement a minimal, robust, fully-typed solution adhering strictly to project conventions.
    3. Add complete test coverage, verify all linters, formatting, and builds pass cleanly.
    4. Deliver an atomic, self-contained PR linking issue [SDK] Add a member return correlation matrix #1201.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @camesenin to this issue.

  3. liutingqiu commented on Oct 20, 2026

    @liutingqiu
    Contributor

    @liutingqiu has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    I'll add a correlationMatrix(memberReturns) function in packages/strategies/src/composition/, taking the per-member return series from the composed runner (#1200) and returning a symmetric matrix of Decimal correlation coefficients with a unit diagonal. I'll reuse the existing Decimal utilities and follow the guarded division pattern already in packages/strategies/src/risk-metrics.ts, so zero-variance members surface as undefined rather than NaN. No new dependency.

    Tests will cover a known input producing the expected matrix, including a perfectly correlated pair and a perfectly anti-correlated pair, plus the negative case: a zero-variance member yielding undefined correlation instead of NaN, and symmetry of the output.

    I've merged PRs #1175 and #1176 in drydocs/meridian and 65 merged PRs in Sottara-Labs/sottara, so I'm familiar with the codebase conventions here. ETA is same or next day.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @liutingqiu to this issue.

  4. Shalombonet commented on Oct 20, 2026

    @Shalombonet
    Contributor

    @Shalombonet has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    hello, i would like to help on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Shalombonet to this issue.

  5. drips-wave commented on Oct 20, 2026

    @drips-wave

    Congratulations, @liutingqiu! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on October 22, 2026.

    🧑‍💻 @liutingqiu: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  6. grantfox-oss commented on Oct 20, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox!

    @liutingqiu's PR #1211 was approved and merged by @collinsezedike.

    🏆 @liutingqiu: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (140 total points). Track your full progress on GrantFox.

    👏 Great work, @liutingqiu! Keep contributing to drydocs.

  7. drips-wave commented on Oct 20, 2026

    @drips-wave

    This issue has been completed by @liutingqiu as part of the Stellar Wave Program's 10th Wave 🥳

    😎 @liutingqiu: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestmediumRequires familiarity with the Meridian codebase or relevant tooling; expect 4–8 hourssdkInvolves Blend or DeFindex SDK helpers in packages/stellar-sdk-helpers

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions