Extend LeastSquaresMovingAverage to accept a benchmark reference - #9761
Open
0xpinara wants to merge 1 commit into
Open
Extend LeastSquaresMovingAverage to accept a benchmark reference#97610xpinara wants to merge 1 commit into
0xpinara wants to merge 1 commit into
Conversation
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a Least Squares Moving Average that fits the target prices against a
reference symbol instead of against time. There is a new
LSMA(target, reference, period)overload.I didn't change the old
LeastSquaresMovingAverage. It is aWindowIndicator,and that puts every input into one window, so it can't hold two symbols. The new
class uses
DualSymbolIndicator, like Beta and Correlation do. That base classmatches the two symbols by time.
The comment on the issue shows a slightly different signature. It is from May
2024, and
DualSymbolIndicatorwas only added in January 2025. So I followed thenewer pattern. I can change it if you prefer.
Related Issue
Resolves #6984. It replaces my earlier attempt in #9371. #9426 also targets this
issue, so tell me if you'd rather use that one.
Motivation and Context
LSMA could only fit prices against time. There was no built in way to fit them
against a benchmark like SPY.
Requires Documentation Change
Yes, the new overload.
How Has This Been Tested?
The tests use
CommonIndicatorTests, like the other dual symbol indicators. Iadded an
LSMAWithReferencecolumn tobi_datatest.csv. I worked those numbersout with the least squares formula myself, so they don't come from the indicator.
There is also a test that does the same fit by hand without MathNet, and two tests
in
AlgorithmIndicatorsTests.All of
QuantConnect.Tests.Indicatorspasses. 2988 passed, 0 failed, 5 skipped.Took me a while to work out why SPY and BTCUSD never paired up. The indicator just
sat at 0 and there was no error.
MultiSymbolIndicatorrounds the timestamps downbefore it compares them, added in #8564, and that rounding only runs when the input
has a duration.
IndicatorDataPointhas none, so it got skipped. Bars have one, sothe problem goes away. The test is
WorksWithDifferentTimeZones.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>