Problem: demo_latest.py crashed when passing pd.Series to plot_equity_curve(), which only accepted str (CSV path).
Solution: Updated plot_equity_curve() to accept both pd.Series and str inputs.
# Run ALL 46 tests (should all pass)
pytest tests/ -v
# Run only the 7 new plotting tests
pytest tests/test_plotting.py -vExpected Output:
tests/test_plotting.py::TestPlotEquityCurve::test_plot_from_series PASSED [ 14%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_from_csv PASSED [ 28%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_with_negative_values PASSED [ 42%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_with_small_values PASSED [ 57%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_series_matches_csv PASSED [ 71%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_with_empty_series PASSED [ 85%]
tests/test_plotting.py::TestPlotEquityCurve::test_plot_with_single_value PASSED [100%]
============================================================== 7 passed in 1.52s ===============================================================
# Uses existing results CSV files to test both input modes
python scripts/test_plotting.pyExpected Output:
Generating V1 test plot from CSV path: results\test_equity_curve.csv...
✅ V1 plot saved to: results\test_plot_v1.png
File size: 55,536 bytes
Generating V2 test plot from CSV path: results\test_equity_curve_v2.csv...
✅ V2 plot saved to: results\test_plot_v2_csv.png
File size: 61,937 bytes
Generating V2 test plot from pd.Series: results\test_equity_curve_v2.csv...
✅ V2 series plot saved to: results\test_plot_v2_series.png
File size: 62,630 bytes
============================================================
✅ Plotting test complete!
Both CSV and Series inputs work correctly.
============================================================
# Full pipeline test with synthetic data (no Yahoo API calls)
python scripts/pr1_synthetic_demo.pyExpected Output:
============================================================
PR #1 Verification: Synthetic Demo
============================================================
Generating synthetic market data...
Created 200 days of data
ES range: $80.41 - $109.92
SPY range: $87.99 - $120.25
Generating signals (V2 - beta-hedged)...
Window: 30 days
Z-score range: 0.16 to 1.73
Running backtest...
Total return: 0.00%
Num trades: 0
Final equity: 0.0000
Testing plotting with pd.Series input...
✅ Plot saved to: results\pr1_synthetic_demo.png
File size: 40,693 bytes
Testing plotting with CSV path input (legacy)...
✅ Plot saved to: results\pr1_synthetic_demo_csv.png
File size: 38,944 bytes
============================================================
✅ PR #1 FIX VERIFIED
- plot_equity_curve() accepts pd.Series ✅
- plot_equity_curve() accepts str (CSV path) ✅
- Demo completes without crash ✅
============================================================
# Full demo with 30-day lookback (minimal data fetch)
python scripts/demo_latest.py --lookback 30 --signal v2Expected Behavior:
- Should complete without crash
- Should create plot file in
results/demo_plot_*.png - If Yahoo API returns 429 error, that's a known external issue (not related to PR #1)
-
src/plotting.py - Core fix
- Function signature:
equity: pd.Series | str(was:csv_path: str) - Parameter rename:
output_file(was:out_path) - Added type checking with
isinstance() - Handles both Series and CSV path inputs
- Function signature:
-
tests/test_plotting.py - New test file (7 tests)
- Tests Series input (new functionality)
- Tests CSV path input (backward compatibility)
- Edge cases: negative values, small values, empty series
- Equivalence testing (Series vs CSV produce same output)
-
scripts/test_plotting.py - Enhanced
- Now tests both input modes
- Better output formatting
-
scripts/pr1_synthetic_demo.py - New verification script
- Full end-to-end test without network dependency
- Generates synthetic ES/SPY data
- Tests entire pipeline: data → signals → backtest → plotting
- All 46 tests pass (pytest tests/ -v)
- New plotting tests work (pytest tests/test_plotting.py -v)
- Scripts run without errors (python scripts/test_plotting.py)
- Synthetic demo completes (python scripts/pr1_synthetic_demo.py)
- Both input types work (Series and CSV path)
- Backward compatible (existing CSV code still works)
- Changes committed (git log shows "fix: accept Series or str in plot_equity_curve()")
# Quick 3-command test:
pytest tests/test_plotting.py -v # Unit tests
python scripts/test_plotting.py # Integration test
python scripts/pr1_synthetic_demo.py # End-to-end testAll three should complete without errors and show ✅ success messages.