Open AlexCatarino opened 1 year 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!
@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:
SAREXT is negative if you’re in a short position, whereas PSAR is always positive regardless of current position.
You can now specify different acceleration factor parameters (start, increment, and max) that used according to whether you’re in a short or long position.
You can now specify a starting value of the indicator (where the sign of the starting value dictates whether the indicator starts in a long or short position).
An additional parameter called offsetOnReverse, which determines a percentage of the current SAR that is first incremented/decremented from the indicator before switching between long/short positions.
Comments/questions regarding testing:
To create my test .txt I just used the applied SAREXT function from tallib to spy ticker data I obtained from yahoo finance. I’ve attached the ticker data file and Python script I used to make the test file below.
I’d be happy to add the file posted by @LouisSzeto, but I’m not sure how to incorporate it if doesn’t include values for low, high, and close?
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:
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)
Welcome to LEAN @nbkell!
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
master
branch