Skip to content

Conversation

@saumya1317
Copy link
Contributor

@saumya1317 saumya1317 commented Oct 23, 2025

Summary

Add weekly/monthly rebalancing options to VectorizedBacktest via rebalance_freq parameter. This allows users to configure rebalancing frequency as "D" (daily), "W" (weekly), or "M" (monthly), addressing issue #4.

Changes

  • Core Implementation: Updated _should_rebalance() method to support W/M frequencies
  • Rebalancing Logic: Weekly rebalances on Mondays, Monthly on 1st of month
  • Integration: Applied rebalancing frequency in run() method using proper DataFrame broadcasting
  • Error Handling: Added validation for unsupported frequencies
  • Documentation: Updated class docstring and constructor parameters
  • Tests: Added comprehensive test suite covering all frequencies and edge cases
  • README: Updated features list and minimal example with rebalancing usage

Testing

  • pytest passes locally (9/9 tests passing)
  • Linting passes (ruff, black)
  • 96% code coverage for backtest module
  • Backward compatibility verified (daily default unchanged)

Technical Details

  • Weekly (W): Rebalances on date.weekday() == 0 (Mondays)
  • Monthly (M): Rebalances on date.day == 1 (1st of month)
  • Daily (D): Default behavior, rebalances every day
  • Error Handling: Raises ValueError for invalid frequencies
  • Performance: Different frequencies produce different results as expected

Related Issues

Fixes #4

@saumya1317
Copy link
Contributor Author

@ayushkrtiwari PLEASE review it and if correct merge it with labels

@ayushkrtiwari
Copy link
Collaborator

ayushkrtiwari commented Oct 23, 2025

@saumya1317 please resolve the conflicts with the latest changes from main

@ayushkrtiwari ayushkrtiwari added Type:Easy intern works Semver:minor minor version changes PR:Accept To acknowledge the PR Type:Medium junior developers talks and removed Type:Easy intern works labels Oct 23, 2025
@ayushkrtiwari
Copy link
Collaborator

@saumya1317 please resolve the conflicts so the PR could be merged. If you are facing any issues, do ask.

- Update _should_rebalance to respect W and M frequencies

- Refactor run method to use conditional rebalancing logic

- Add comprehensive tests for D/W/M rebalancing

- Document rebalance_freq parameter in README

- All tests pass; daily default unchanged
@saumya1317 saumya1317 force-pushed the feature/rebalance-frequency-WM branch from 32016ff to f2211fb Compare October 26, 2025 21:02
@ayushkrtiwari ayushkrtiwari merged commit 140ea0f into OPCODE-Open-Spring-Fest:main Oct 27, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR:Accept To acknowledge the PR Semver:minor minor version changes Type:Medium junior developers talks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add weekly/monthly rebalancing option

2 participants