Skip to content
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

Of Indicator Extension Doesn't Follow Order of Operations for Updates #6708

Closed
4 tasks done
DerekMelchin opened this issue Oct 21, 2022 · 1 comment
Closed
4 tasks done

Comments

@DerekMelchin
Copy link
Collaborator

Expected Behavior

If we create an Of indicator extension and then Update it, it updates the RHS indicator with the input and then updates the LHS indicator with the output of the RHS indicator.

Actual Behavior

If we create an Of indicator extension and then Update it, it updates the LHS indicator with the input.

Potential Solution

Change the Update behavior of the Of indicator extension so that it follows the correct order of operations.

Reproducing the Problem

Run this backtest. We get

Samples: ROC=0; MAX=10; indicator=10

This backtest also highlights the issue.

System Information

QC Cloud

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
@Martin-Molinero
Copy link
Member

If we create an Of indicator extension

Of is not creating a new indicator but returning the given one. In this case indicator is the maximum indicator instance, which is the one that will be receiving the update calls, believe this is to allow chaining it further. See https://github.com/QuantConnect/Lean/blob/master/Indicators/IndicatorExtensions.cs#L51

        public override void Initialize()
        {
            var roc = new RateOfChange(1);
            var max = new Maximum(10);
            var indicator = (max).Of(roc);
            
            for(var i = 0; i < 10; i++)
            {
                indicator.Update(new DateTime(), 1m);
            }

            Quit($"Samples: ROC={roc.Samples}; MAX={max.Samples}; indicator={indicator.Samples}");
        }

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

No branches or pull requests

2 participants