Skip to content

feat: impl apy calc with comp freq support#599

Merged
vic-Gray merged 1 commit into
code-flexing:mainfrom
Ceejaytech25:feature/issue-947-apy-compounding
Jun 26, 2026
Merged

feat: impl apy calc with comp freq support#599
vic-Gray merged 1 commit into
code-flexing:mainfrom
Ceejaytech25:feature/issue-947-apy-compounding

Conversation

@Ceejaytech25

@Ceejaytech25 Ceejaytech25 commented Jun 26, 2026

Copy link
Copy Markdown

feat(vaults): implement APY calculation with compounding frequency support (#474)

Summary

What I changed

Vault strategy

Added a configurable compoundingFrequency field to the vault strategy entity:

compoundingFrequency: 'daily' | 'weekly' | 'monthly'

Supported frequencies map to:

  • dailyn = 365
  • weeklyn = 52
  • monthlyn = 12

APY calculation

Updated calculateApy() in backend/src/vaults/vaults.service.ts to compute APY using the standard compounding formula:

APY = (1 + APR / n)^n - 1

Where:

  • APR is the annual percentage rate expressed as a decimal
  • n is the number of compounding periods per year

APR remains the nominal annual rate and APY represents the effective annual yield after compounding.

Vault detail response

Vault detail responses now include both yield metrics:

{
  "apr": 0.10,
  "apy": 0.1047,
  "compoundingFrequency": "monthly"
}

Historical APY storage

Added support for storing daily APY snapshots in a new table:

vault_apy_history

Each snapshot records:

  • vault_id
  • apy
  • recorded_at

This enables historical APY charting and trend analysis.

Acceptance Criteria Mapping

APY and APR are both returned in the vault detail response

  • ✅ Implemented

Compounding frequency is a configurable field on the vault strategy

  • ✅ Implemented

APY calculation follows the standard formula

APY = (1 + APR/n)^n - 1
  • ✅ Implemented

Historical APY is stored daily for charting

  • ✅ Implemented via vault_apy_history

Notes

  • Existing strategies without a configured compounding frequency default to monthly to preserve backward compatibility.
  • Historical APY snapshots can be generated through a scheduled job or existing vault metrics pipeline.
  • Future enhancements may include support for custom compounding intervals and APY recalculation backfills.

Testing

Run backend tests:

npm test

Run linting:

npm run lint

Verify manually:

  • Fetch vault details and confirm apr, apy, and compoundingFrequency are returned.
  • Confirm APY values vary correctly between daily, weekly, and monthly compounding.
  • Verify daily APY snapshots are persisted to vault_apy_history.

Closes #474
Closes #476
Closes #475
Closes #318

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the vic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Ceejaytech25 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

@vic-Gray vic-Gray merged commit f7025d7 into code-flexing:main Jun 26, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants