Validate futures series contract dates - #1
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds internal validation for futures series identifiers and contract dates, surfacing invalid inputs as clear errors and warning when an outright suffix month/year conflicts with the supplied expiration, while keeping existing storage formats (including YYYY-MM) and series/spread/continuous formats supported.
Changes:
- Introduces internal parsing/validation helpers for suffixes and date inputs, including mismatch warnings and invalid-date errors.
- Wires the new validation into
future_series()construction flow. - Adds focused tinytest coverage for successful creation, warnings, and error cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
R/instrument.R |
Calls the new internal validator during future_series() construction. |
R/future_series_validation.R |
Adds internal helpers to parse/validate suffixes and (month/day) date inputs, emitting warnings/errors. |
inst/tinytest/test_future_series.R |
Adds regression tests covering valid series creation, mismatch warnings, and invalid inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Vector formats and dates are mishandled, and invalid expiration errors can be masked by suffix validation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
R/future_series_validation.R:120
parse_suffix()can return multipleformatvalues for a recognized butterfly whose legs use different suffix formats (it callsunique()across the legs). Passing that vector directly to||warns on older R versions and errors on current R versions, so an existing spread format such asU1.Z11.H2012is rejected. Collapse the missingness check to one logical value.
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Balanced
| if (!is.null(first_info) && !is.null(expiry_info) && | ||
| nrow(first_info) == 1L && nrow(expiry_info) == 1L) { |
There was a problem hiding this comment.
Addressed in 1f8c2d1: vector date inputs now have explicit R-style recycling semantics in the validation path, with regression coverage for scalar-to-vector recycling; paired vectors continue to reject any invalid chronological pair.
Co-authored-by: JustinMShea <[email protected]>
Co-authored-by: JustinMShea <[email protected]>
Adds validation for futures contract suffixes and dates. Invalid dates now produce clear errors, inconsistent contract months produce warnings, and the existing continuous-contract and spread formats remain supported. Adds focused tinytest coverage without changing the public API.