Skip to content

feat: add sortino, directional_accuracy metrics and PyTorch loss functions#46

Merged
ArthurBernard merged 3 commits into
developfrom
feat/loss-functions
May 11, 2026
Merged

feat: add sortino, directional_accuracy metrics and PyTorch loss functions#46
ArthurBernard merged 3 commits into
developfrom
feat/loss-functions

Conversation

@ArthurBernard
Copy link
Copy Markdown
Owner

Summary

  • Add sortino() and directional_accuracy() to fynance/features/metrics.py with shared helper _annual_downside_volatility; both exported in __all__
  • Add fynance/models/loss/ submodule: BaseLoss, SharpeLoss, SortinoLoss, DirectionalAccuracyLoss — pure torch ops, differentiable, rf/period precomputed, std(correction=0) for Sharpe consistency with numpy metric
  • Export new loss classes from fynance/models/__init__.py
  • 24 new tests (6 metric + 18 loss); all doctests pass; ruff clean; full suite 249 passed

Test plan

  • pytest fynance/tests/features/test_metrics.py::test_sortino
  • pytest fynance/tests/features/test_metrics.py::test_directional_accuracy
  • pytest fynance/tests/models/test_loss.py
  • pytest --doctest-modules fynance/models/loss/
  • pytest -q (full suite)
  • ruff check fynance/

…tions

- Add sortino() and directional_accuracy() to fynance/features/metrics.py
  with helper _annual_downside_volatility(); both exported in __all__
- Add fynance/models/loss/ submodule: BaseLoss, SharpeLoss, SortinoLoss,
  DirectionalAccuracyLoss — pure torch ops, gradient-flow tested
- Export new loss classes from fynance/models/__init__.py
- 24 new tests (6 metric + 18 loss); ruff clean; full suite 249 passed
@codecov-commenter
Copy link
Copy Markdown

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

Codecov Report

❌ Patch coverage is 99.48980% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fynance/features/metrics.py 95.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Files with missing lines Coverage Δ
fynance/models/__init__.py 100.00% <100.00%> (ø)
fynance/models/loss/__init__.py 100.00% <100.00%> (ø)
fynance/models/loss/_base.py 100.00% <100.00%> (ø)
fynance/models/loss/directional.py 100.00% <100.00%> (ø)
fynance/models/loss/sharpe.py 100.00% <100.00%> (ø)
fynance/models/loss/sortino.py 100.00% <100.00%> (ø)
fynance/tests/features/test_metrics.py 100.00% <100.00%> (ø)
fynance/tests/models/test_loss.py 100.00% <100.00%> (ø)
fynance/features/metrics.py 82.39% <95.00%> (+1.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArthurBernard ArthurBernard merged commit e12a889 into develop May 11, 2026
5 checks passed
@ArthurBernard ArthurBernard deleted the feat/loss-functions branch May 11, 2026 15:57
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.

2 participants