feat(CONV-001): add GLD launch date validation, feat(DATA-DB-003): add cache CLI

CONV-001:
- Add GLD_LAUNCH_DATE constant (November 18, 2004)
- Validate reference_date in gld_ounces_per_share()
- Raise ValueError for dates before GLD launch
- Update docstring with valid date range
- Add comprehensive test coverage for edge cases

DATA-DB-003:
- Create scripts/cache_cli.py with three commands:
  - vault-dash cache stats: Show cache statistics
  - vault-dash cache list: List cached entries
  - vault-dash cache clear: Clear all cache files
- Add Makefile targets: cache-stats, cache-list, cache-clear
- Integrate with DatabentoHistoricalPriceSource methods
This commit is contained in:
Bu5hm4nn
2026-03-29 12:00:30 +02:00
parent ace6d67482
commit dc4ee1f261
6 changed files with 276 additions and 17 deletions

View File

@@ -211,9 +211,7 @@ class TestDatabentoHistoricalPriceSource:
assert len(result) == 4
assert result[0].close == 185.0
def test_load_from_cache_returns_none_if_stale(
self, temp_cache_dir: Path, sample_ohlcv_df
) -> None:
def test_load_from_cache_returns_none_if_stale(self, temp_cache_dir: Path, sample_ohlcv_df) -> None:
"""Returns None if cache exceeds age threshold."""
source = DatabentoHistoricalPriceSource.__new__(DatabentoHistoricalPriceSource)

View File

@@ -10,6 +10,7 @@ from app.domain.instruments import (
GC_F_OUNCES_PER_CONTRACT,
GLD_EXPENSE_DECAY_RATE,
GLD_INITIAL_OUNCES_PER_SHARE,
GLD_LAUNCH_DATE,
GLD_LAUNCH_YEAR,
Underlying,
asset_quantity_from_weight,
@@ -22,13 +23,38 @@ from app.domain.instruments import (
from app.domain.units import BaseCurrency, Weight, WeightUnit
def test_gld_ounces_per_share_decay_formula_matches_research() -> None:
"""Verify decay formula matches research examples from docs/GLD_BASIS_RESEARCH.md."""
# Launch (2004): should be exactly 0.10 oz/share
launch_backing = gld_ounces_per_share(date(2004, 1, 1))
def test_gld_launch_date_constant() -> None:
"""Verify GLD launch date constant is November 18, 2004."""
assert GLD_LAUNCH_DATE == date(2004, 11, 18)
def test_gld_ounces_per_share_launch_date_returns_initial_backing() -> None:
"""Verify launch date (2004-11-18) returns exactly 0.10 oz/share."""
launch_backing = gld_ounces_per_share(GLD_LAUNCH_DATE)
assert launch_backing == GLD_INITIAL_OUNCES_PER_SHARE
assert launch_backing == Decimal("0.10")
def test_gld_ounces_per_share_rejects_pre_launch_date() -> None:
"""Verify dates before GLD launch raise ValueError."""
with pytest.raises(ValueError, match="GLD backing data unavailable before"):
gld_ounces_per_share(date(2004, 11, 17)) # Day before launch
with pytest.raises(ValueError, match="GLD backing data unavailable before"):
gld_ounces_per_share(date(2004, 1, 1)) # Early 2004
with pytest.raises(ValueError, match="GLD backing data unavailable before"):
gld_ounces_per_share(date(2003, 12, 31)) # Prior year
def test_gld_ounces_per_share_early_2004_within_year_raises() -> None:
"""Verify dates in 2004 but before November 18 also raise ValueError."""
with pytest.raises(ValueError, match="GLD backing data unavailable"):
gld_ounces_per_share(date(2004, 6, 1)) # June 2004, before launch
def test_gld_ounces_per_share_decay_formula_matches_research() -> None:
"""Verify decay formula matches research examples from docs/GLD_BASIS_RESEARCH.md."""
# 2026: should be ~0.0916 oz/share (8.4% decay from 22 years)
# Formula: 0.10 * e^(-0.004 * 22) = 0.10 * e^(-0.088) ≈ 0.091576
years_2026 = 2026 - GLD_LAUNCH_YEAR # 22 years