feat: phase 1 — data downloader, backtrader runner, SMA strategy
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
from data.downloader import download_daily
|
||||
|
||||
|
||||
def test_download_single_stock():
|
||||
"""Smoke test: download data for 浦发银行 for a short window."""
|
||||
df = download_daily("sh600000", "2024-01-01", "2024-01-31")
|
||||
assert df is not None
|
||||
assert len(df) > 0
|
||||
assert list(df.columns) == ["symbol", "date", "open", "high", "low", "close", "volume", "amount"]
|
||||
assert df["close"].notna().all()
|
||||
|
||||
|
||||
def test_download_baostock_fallback():
|
||||
"""Test baostock works as secondary source."""
|
||||
df = download_daily("sz000001", "2024-06-01", "2024-06-15", source="baostock")
|
||||
assert df is not None
|
||||
assert len(df) > 0
|
||||
@@ -0,0 +1,21 @@
|
||||
import pytest
|
||||
from backtest.config import BacktestConfig
|
||||
from backtest.runner import BacktestRunner
|
||||
from strategies.base import SmaCross
|
||||
|
||||
|
||||
def test_backtest_smoke():
|
||||
"""Smoke test: run a minimal backtest and check results exist."""
|
||||
config = BacktestConfig(
|
||||
symbols=["sh600000"],
|
||||
start_date="2024-01-01",
|
||||
end_date="2024-03-31",
|
||||
initial_cash=100_000,
|
||||
)
|
||||
runner = BacktestRunner(config)
|
||||
results = runner.run(SmaCross)
|
||||
assert results is not None
|
||||
assert len(results) == 1
|
||||
# Check analyzers exist
|
||||
sharpe = results[0].analyzers.sharpe.get_analysis()
|
||||
assert "sharperatio" in sharpe
|
||||
Reference in New Issue
Block a user