QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.52k stars 3.22k forks source link

Explore Operators on Python Indicators #3107

Open jaredbroad opened 5 years ago

jaredbroad commented 5 years ago

Expected Behavior

All operators work in comparing indicators. +, -, *, /.

Actual Behavior

Only < and > work. The other operators require referencing Current.Value

Potential Solution

Explore and understand why < > work and apply lessons to other operators.

Reproducing the Problem

This shouldn't work but it does.

Checklist

gsalaz98 commented 5 years ago

These two issues might be related:

christabella commented 3 years ago

Has this issue been addressed? At least from the first Python tutorial https://www.quantconnect.com/tutorials/api-tutorials/consolidating-data-to-build-bars there is a line thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler that indicates support for addition operator on events/handlers?

But I guess events are different from indicators, and only inequality operators are implemented e.g. GreaterThan https://github.com/QuantConnect/Lean/blob/03efc1b735bb8b841eb04434f537ac3d798f5877/Tests/Indicators/IndicatorTests.cs#L227

Not sure if this is related as well https://github.com/QuantConnect/Lean/blob/d1624ab8998deea2afd54a7db6b3694886665f14/Common/Python/PandasData.cs#L265

christabella commented 3 years ago

Sorry I just realized that the event += handler pattern is not exactly an operator, I'm not familiar with C#. It's surprising that the same syntax works in Python, seems like it's out of the box since it's used in the pythonnet demo for windows forms applications too

Edit: I see now that this is done by overloading nb_inplace_add etc. in eventbinding.cs via eventobject.cs

jaredbroad commented 1 year ago