Conversation
NeuZhou
left a comment
There was a problem hiding this comment.
Good start, but there are structural issues that need fixing before merge:
🔴 Critical: Wrong file location
The factor is placed at \actors/vwap.py\ (repo root) instead of \stratevo/factors/builtin/volume.py\ or similar path under the package. This means:
- It won't be auto-discovered by the factor registry
- The test imports from \actors.vwap\ which only works with the sys.path hack, not as a proper package import
- Other volume factors live in \stratevo/factors/builtin/\ — this should follow the same pattern
Fix: Move to \stratevo/factors/builtin/volume.py\ (create it or append to existing) and register in the volume category. Update test imports accordingly.
🟡 Performance: O(n × period) nested loop
The current implementation uses a nested Python for-loop which will be very slow on large datasets (>1000 bars with period=100 → 100k iterations). Consider using numpy cumsum for O(n):
\\python
cum_pv = np.cumsum(closes * volumes)
cum_v = np.cumsum(volumes)
rolling sum via difference
\\
🟡 Missing newline at EOF
Both files are missing trailing newlines (\No newline at end of file).
✅ What's good
- Clean API matching BaseFactor interface
- Good test coverage (7 tests including edge cases)
- Zero-volume handling is correct
- Known-value test with manual calculation is great
|
Hey @hari2k7, thanks for this contribution! 🙏 Just checking in — any updates on the requested changes (moving the file to the correct location)? Let me know if you need any help with the restructuring, happy to guide you through it! |
|
Fixed all review issues:
All 8 tests passing ✅ |
Summary
Implements a rolling VWAP (Volume Weighted Average Price) factor that
measures deviation of close price from VWAP over a rolling window.
Changes
Type of Change
Testing
pytest)ruff check src/)Checklist
Related Issues
Closes #18
Screenshots / Demo
Terminal output
$ pytest tests/test_vwap.py -v
tests/test_vwap.py::TestVWAPFactor::test_output_length_matches_input PASSED
tests/test_vwap.py::TestVWAPFactor::test_nan_before_period PASSED
tests/test_vwap.py::TestVWAPFactor::test_finite_after_period PASSED
tests/test_vwap.py::TestVWAPFactor::test_zero_volume_edge_case PASSED
tests/test_vwap.py::TestVWAPFactor::test_known_value PASSED
tests/test_vwap.py::TestVWAPFactor::test_default_params PASSED
tests/test_vwap.py::TestVWAPFactor::test_param_ranges PASSED
7 passed in 0.06s