Skip to content

fix(metrics): include the first month in value at risk - #648

Merged
MDUYN merged 1 commit into
coding-kitties:mainfrom
wavebyrd:fix/var-first-month
Nov 24, 2026
Merged

MDUYN merged 1 commit into
coding-kitties:mainfrom
wavebyrd:fix/var-first-month

Conversation

@wavebyrd

Copy link
Copy Markdown
Contributor

get_value_at_risk() and get_conditional_value_at_risk() build their monthly returns with their own copy of the old get_monthly_returns() logic, so they still drop the first month that #644 fixed. A loss in the first month never reaches VaR/CVaR, and a three-month backtest has only two returns, so both come back as 0.0.

The helper now reuses get_monthly_returns() instead of resampling again.

from datetime import datetime, timezone
from types import SimpleNamespace as S
from investing_algorithm_framework.services.metrics.value_at_risk import get_conditional_value_at_risk

snaps = [
    S(total_value=v, created_at=datetime(2024, m, d, tzinfo=timezone.utc))
    for v, m, d in [(100, 1, 1), (80, 1, 31), (88, 2, 29), (96.8, 3, 31)]
]
get_conditional_value_at_risk(snaps)
# before: 0.0
# after:  -0.2

Added test_value_at_risk.py; the metrics tests and flake8 pass.

@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@25203db). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #648   +/-   ##
=======================================
  Coverage        ?   82.62%           
=======================================
  Files           ?      697           
  Lines           ?    70521           
  Branches        ?        0           
=======================================
  Hits            ?    58269           
  Misses          ?    12252           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MDUYN

MDUYN commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Hey @wavebyrd , looks good, thanks for the fix

@MDUYN
MDUYN merged commit a24e6bc into coding-kitties:main Nov 24, 2026
33 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

Development

Successfully merging this pull request may close these issues.

3 participants