QuantConnect / Lean

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

Implenent Parabolic SAR - Extended (SAREXT) #6987

Open AlexCatarino opened 1 year ago

AlexCatarino commented 1 year ago

Expected Behavior

Lean support the Parabolic SAR - Extended (SAREXT) Indicator.

Actual Behavior

Not supported. See #83.

Potential Solution

Implement SAREXT. There is scarce information on this indicator. We could look into TALIB's formulas to understand the difference from PSAR.

Checklist

LouisSzeto commented 1 year ago

spy_sarext.csv

nbkell commented 11 months ago

I would like to be assigned this as a first issue if it hasn't been handled yet. @AlexCatarino could you assign it to me? Thanks!

nbkell commented 10 months ago

@AlexCatarino I’ve recently made a PR that implements SAREXT, which is simply a generalization of PSAR (called SAR in talib) that gives you more control over the parameters and behavior. The differences are:

Finally I want to point out that the current Lean implementation for PSAR is not entirely consistent with that of SAR in talib (see the link to ta_SAR.c below). These discrepancies are:

I’ve implemented SAREXT to be consistent with talib (and thus some of the differences from Lean’s PSAR). Let me know if you’d rather it be consistent with Lean’s current version of PSAR.

Files and References:

LouisSzeto commented 10 months ago

Hi please refer to this reference data for checking: spy_sarext.csv

The columns are "DATE" "SPY high" "SPY low" "SAREXT"

The script generating the data

import talib
import pandas as pd

history = pd.read_csv("https://github.com/QuantConnect/Lean/raw/master/Data/equity/usa/daily/spy.zip",
                       index_col=0, names=["open", "high", "low", "close", "volume"])

high = history.high
low = history.low

sarext = talib.SAREXT(high, low).dropna().to_frame()
sarext["high"] = high
sarext["low"] = low
sarext = sarext.iloc[:, [1, 2, 0]]
sarext.to_csv("spy_sarext.csv", header=False)
jaredbroad commented 10 months ago

Welcome to LEAN @nbkell!