feat(CORE-001D): close remaining boundary cleanup slices
This commit is contained in:
@@ -10,6 +10,7 @@ from app.models.strategy_template import EntryPolicy, RollPolicy, StrategyTempla
|
||||
from app.services.backtesting.historical_provider import (
|
||||
DailyClosePoint,
|
||||
SyntheticHistoricalProvider,
|
||||
SyntheticOptionQuote,
|
||||
YFinanceHistoricalPriceSource,
|
||||
)
|
||||
from app.services.backtesting.service import BacktestService
|
||||
@@ -209,6 +210,50 @@ def test_backtest_rejects_unsupported_template_behaviors(field: str, value: obje
|
||||
service._validate_template_for_mvp(unsupported_template)
|
||||
|
||||
|
||||
def test_yfinance_price_source_normalizes_valid_daily_close_row() -> None:
|
||||
point = YFinanceHistoricalPriceSource._normalize_daily_close_row(
|
||||
row_date=pd.Timestamp("2024-01-03T00:00:00Z"),
|
||||
close=96.0,
|
||||
)
|
||||
|
||||
assert point == DailyClosePoint(date=date(2024, 1, 3), close=96.0)
|
||||
|
||||
|
||||
def test_yfinance_price_source_rejects_invalid_daily_close_row_types() -> None:
|
||||
with pytest.raises(TypeError, match="historical row date must support .date"):
|
||||
YFinanceHistoricalPriceSource._normalize_daily_close_row(row_date="2024-01-03", close=96.0)
|
||||
|
||||
with pytest.raises(ValueError, match="historical close must be finite"):
|
||||
YFinanceHistoricalPriceSource._normalize_daily_close_row(
|
||||
row_date=pd.Timestamp("2024-01-03T00:00:00Z"),
|
||||
close=float("nan"),
|
||||
)
|
||||
|
||||
|
||||
def test_synthetic_option_quote_rejects_invalid_field_types() -> None:
|
||||
with pytest.raises(TypeError, match="spot must be a finite number"):
|
||||
SyntheticOptionQuote(
|
||||
position_id="pos-1",
|
||||
leg_id="leg-1",
|
||||
spot="bad", # type: ignore[arg-type]
|
||||
strike=100.0,
|
||||
expiry=date(2025, 1, 1),
|
||||
quantity=1.0,
|
||||
mark=5.0,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="mark must be non-negative"):
|
||||
SyntheticOptionQuote(
|
||||
position_id="pos-1",
|
||||
leg_id="leg-1",
|
||||
spot=100.0,
|
||||
strike=100.0,
|
||||
expiry=date(2025, 1, 1),
|
||||
quantity=1.0,
|
||||
mark=-1.0,
|
||||
)
|
||||
|
||||
|
||||
def test_yfinance_price_source_treats_end_date_inclusively(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
calls: list[tuple[str, str, str]] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user