Skip to content

Reject the two point window Beta, Correlation and Covariance describe - #9728

Open
mkzung wants to merge 1 commit into
QuantConnect:masterfrom
mkzung:bug-9725-two-point-correlation-period
Open

Reject the two point window Beta, Correlation and Covariance describe#9728
mkzung wants to merge 1 commit into
QuantConnect:masterfrom
mkzung:bug-9725-two-point-correlation-period

Conversation

@mkzung

@mkzung mkzung commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Beta, Correlation and Covariance now test period < 3, which is the bound their comment and their message already state.

Related Issue

Closes #9725

Motivation and Context

All three carry the comment "assert the period is greater than two", raise "must be greater than 2 but was {period}", and then test period < 2, so a period of two reaches the calculation.

Two points always correlate perfectly. Fed ten bars of two series that are not proportional, Correlation at period 2 returns 1 or -1 on every one of its nine readings:

period  2: 1 -1 -1 -1 -1 -1 -1 -1 -1
period  3: 0.3273 -0.2402 -0.2402 -0.3974 -0.2895 -0.2895 -0.2895 -0.2895
period  4: 0.3586 0 -0.049 -0.0804 -0.0476 -0.0476 -0.0476
period 10: 0.749

Beta and Covariance share that window through DualSymbolIndicator.

ValueAtRisk states the same bound and tests period < 3.

Requires Documentation Change

No.

How Has This Been Tested?

One test per indicator, copied from ValueAtRiskTests.PeriodBelowMinimumThrows.

Keeping the tests and reverting the three source files:

Failed!  Failed: 3, Passed: 45, Total: 48

with them in place, including the Spearman fixture:

Passed!  Failed: 0, Passed: 64, Total: 64

Nothing in Tests/, Algorithm.CSharp/ or Algorithm.Python/ constructs any of the three with a period of 2, so no existing caller changes; the smallest literal in use is 3.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

All three carry the comment "assert the period is greater than two" and
raise "must be greater than 2 but was {period}", and all three test
period < 2, so a period of two reaches the calculation.

Two points always correlate perfectly. Fed ten bars of two series that are
not proportional, Correlation at period 2 returns 1 or -1 on every one of
its nine readings, while at period 3 the same series gives values between
-0.40 and 0.33. Beta and Covariance share the window.

ValueAtRisk states the same bound and tests period < 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Beta, Correlation and Covariance accept the period their message forbids

1 participant