Skip to content

feat(strategies): add funding-capture and basis model - #951

Merged
collinsezedike merged 2 commits into
drydocs:mainfrom
Miraclechukwuemeka:feat/funding-capture-basis-model-927
Oct 6, 2026
Merged

collinsezedike merged 2 commits into
drydocs:mainfrom
Miraclechukwuemeka:feat/funding-capture-basis-model-927

Conversation

@Miraclechukwuemeka

@Miraclechukwuemeka Miraclechukwuemeka commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add accrueFunding() and computeBasis() to packages/strategies, modelling funding payments on the short leg and the spot-versus-derivative basis so strategies can account for carry over a simulation.

Changes

packages/strategies/src/types.ts

  • New FundingRate interface, { ratePerSecond: FixedPointDecimal }, reusing the existing FixedPointDecimal model rather than a parallel rate type.
  • New FundingPosition interface, { notional: FixedPointDecimal }, holding the absolute short-leg size. Named to avoid colliding with the portfolio's own Position.

packages/strategies/src/funding.ts (new file)

  • accrueFunding(position, fundingRate, elapsedSeconds) returns notional × ratePerSecond × elapsed / STROOPS_PER_UNIT as a FixedPointDecimal. Entirely bigint arithmetic, no floats.
  • computeBasis(spot, derivativePrice) returns spot - derivativePrice as a FixedPointDecimal. Positive means backwardation, negative means contango.
  • Sign convention (documented in JSDoc): a positive rate means the short leg receives, a negative rate means the short leg pays.

packages/strategies/src/index.ts

  • Re-exports everything from ./funding.

packages/strategies/src/funding.test.ts (new file)

  • Sign conventions: positive, negative and zero rate
  • Linearity with respect to elapsed seconds and notional
  • Full 7-decimal precision, sub-stroop truncation
  • RangeError on negative elapsedSeconds
  • All four acceptance criteria from the issue

Acceptance criteria

  • Funding accrual matches sign conventions and is documented
  • Basis computed as spot-derivative delta
  • Consumes the existing funding-rate model, no parallel rate type
  • No floats, unit-tested

Test plan

  • pnpm lint and pnpm typecheck pass across the workspace
  • pnpm --filter @meridian/strategies test passes, 11 files and 218 tests
  • packages/strategies coverage passes its thresholds, with funding.ts fully covered
  • prettier --check passes on the new files

Closes #927

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@Miraclechukwuemeka is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@Miraclechukwuemeka Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Miraclechukwuemeka and others added 2 commits October 5, 2026 23:26
Add FundingRate and Position types to types.ts, consuming the existing
FixedPointDecimal model rather than introducing a parallel rate type.

Implement two pure functions in funding.ts:
- accrueFunding(position, fundingRate, elapsedSeconds): computes funding
  payment on the short leg using integer-only bigint arithmetic
  (notional × rate × elapsed / STROOPS_PER_UNIT).  Positive rate →
  short receives; negative rate → short pays.
- computeBasis(spot, derivativePrice): returns spot − derivative as a
  FixedPointDecimal, positive in backwardation, negative in contango.

Both functions return FixedPointDecimal with no floating-point anywhere
in the computation path.  Sign conventions are documented in JSDoc.

Export accrueFunding, computeBasis, FundingRate, and Position from the
package index.

Add 25 unit tests in funding.test.ts covering:
- Sign conventions (positive, negative, zero rate)
- Linearity with respect to elapsed and notional
- Full 7-decimal precision preservation
- Integer truncation for sub-stroop results
- RangeError on negative elapsedSeconds
- All four acceptance criteria from the issue

All 61 tests pass (25 new + 36 existing).

Closes drydocs#927
@collinsezedike
collinsezedike force-pushed the feat/funding-capture-basis-model-927 branch from c21d37c to ff91084 Compare October 5, 2026 22:46

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Miraclechukwuemeka thank you for the funding-capture and basis model. I verified the accrual keeps every step in bigint stroops, that the single division by STROOPS_PER_UNIT leaves notional × ratePerSecond × elapsedSeconds exact, that a negative elapsedSeconds raises, and that computeBasis returns the spot-minus-derivative delta at full precision.

I rebased the branch onto main and fixed three things before landing. The branch declared its own Position interface in types.ts, and portfolio.ts already exports a different Position, so index.ts re-exported the name twice and the package failed to typecheck with TS2308. I renamed the funding one to FundingPosition. The two new files also carried ten em dashes in comments, which I rewrote to comply with the repository's writing rules. Prettier then reformatted three over-long lines.

packages/strategies is at 11 files and 218 tests, with funding.ts fully covered. Merging now.

@collinsezedike
collinsezedike merged commit 595cf16 into drydocs:main Oct 6, 2026
10 of 11 checks passed
@collinsezedike

Copy link
Copy Markdown
Collaborator

@Miraclechukwuemeka your work is merged into main. If Meridian is useful to you, a star on the repository helps the project keep attracting contributors: https://github.com/drydocs/meridian. There are more open issues whenever you want to pick up another one.

@collinsezedike collinsezedike mentioned this pull request Oct 6, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SDK] Add the funding-capture and basis model

2 participants