-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New Feature: Implement Covariance Indicator #6982 #9144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
New Feature: Implement Covariance Indicator #6982 #9144
Conversation
|
Hi team! 👋 |
|
Hey @yyxxddjj! Welcome to Lean! |
16cd161 to
fd14f3f
Compare
|
Hi @Martin-Molinero, |
Martin-Molinero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! almost there 👍
|
Hi @Martin-Molinero, thanks for catching that! |
|
Hey @yyxxddjj! Please re run the python commands Louis had shared 👍 I don't think current csv looks right. Also please use English comments to follow standard |
|
Hi @Martin-Molinero, I have updated the comments to English. |
|
@yyxxddjj tests are failing 👀 |
|
@Martin-Molinero Thank you for the feedback! I have pushed a significant update based on your suggestions.
Reasoning: The base class enforces strict checks for standard OHLC columns (e.g., throwing exceptions if 'open' is missing during Renko tests). Since Covariance is a dual-symbol indicator using specific verification data, fitting it into the base class's expected format required filling unrelated OHLC columns with arbitrary values, which felt semantically incorrect and introduced unnecessary complexity. Solution: I implemented a dedicated, standalone test class. This allows for explicit, readable tests without working around the base class limitations.
Source: It uses the raw price data from the LEAN data/ directory (SPY and QQQ). CSV Structure: Date, SPY (Price), QQQ (Price), Covariance (Expected Result).
Accuracy: Validates calculations against the Python-generated control data (with robust handling for scientific notation). Lifecycle: Fully tests IsReady logic, WarmUpPeriod, and Reset() behavior. Dual-Stream: Explicitly verifies the indicator handles updates from two different symbols correctly. For transparency, I have included the data generation script below: Click to view Python Generation Script (generate_data.py)Python ConfigurationSPY_PATH = 'data/spy.zip' def read_lean_zip(path, symbol): 1. Load Dataspy = read_lean_zip(SPY_PATH, 'SPY') 2. Align and Calculate Covariancedata = pd.concat([spy, qqq], axis=1).dropna() 3. Export Clean Verification Dataoutput = pd.DataFrame({ output.to_csv(OUTPUT_FILE, index=True, header=True) |
|
Hey @yyxxddjj! Sorry but should revert changes in unrelated files like |
a1ee9ce to
1559c24
Compare
1559c24 to
7ea0f60
Compare
|
Hi @Martin-Molinero, thanks for the review. |
Description
Implemented the
Covarianceindicator as requested in issue #6982.This indicator computes the covariance between two data series (target and reference) over a specified period using
MathNet.Numerics.Statistics.Covariance.Related Issue
Closes #6982
Motivation and Context
Covariance is a fundamental statistical measure used in finance, particularly for portfolio optimization and risk management. Adding this indicator allows users to easily calculate the joint variability of two assets within the Lean engine.
Requires Documentation Change
No. (Standard indicator addition)
How Has This Been Tested?
CovarianceTests.cs.IsReady,Reset, andWarmUp.dotnet test.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>