pandas - Parabolic SAR calculated in Python seems to be reversed - Stack Overflow
python - Why is only one graph showing when using talib SAR? - Stack Overflow
Mistakes in calculating the Talib-sar in different time frames
Parabolic SAR (PSAR) differences
Hi I also need a psar trend shift detecting code. I am horribly new to coding and algotrading been trying to use ai to get the code but after hundreds of codes I ran there is always a problem cam anyone provide a python code. Thanks in advance.
More on reddit.comI am trying to integrate Alpha Vantage data into my code, i.e. PSAR values, but I have noticed some discrepancies between data providers, e.g. on September 30th, 2020 the PSAR value for IBM with acceleration 0.02 and maximum 0.2 from:
-
AlphaVantage: 115.0879
-
TradingView: 116.59
-
TAlib python module: 116.480003
Here is the code I use for each source:
-
Alpha Vantage
import requestsimport pandas as pd
symbol = 'IBM'interval = 'daily'acceleration = 0.02maximum = 0.2r = requests.get(f'https://www.alphavantage.co/query?'f'function=SAR&'f'symbol={symbol}&'f'interval={interval}&'f'acceleration={acceleration}&'f'maximum={maximum}&'f'apikey={api_key}')
dat = r.json()metadata = dat["Meta Data"]key_dat = list(dat.keys())[1] # uglyts = dat[key_dat]share = pd.DataFrame(ts).Tprint(share.loc['2020-09-30'])
Output:
-
Trading view
PSAR for IBM - TradingView
-
TAlib:
import yfinance as yfimport talibimport pandas as pdimport numpy as np# import datetime# from decimal import Decimalimport math
use_trailing_stop_loss = Falseticker = 'IBM'share = yf.download(tickers=ticker, start='2019-09-29', end='2020-10-01')share = share.dropna()share['PSAR'] = talib.SAR(share['High'], share['Low'], acceleration=0.02, maximum=0.2)
Output:
In[2]: share.tail(1)
Out[2]:
Open High Low ... Adj Close Volume PSAR
Date ...
2020-09-30 121.379997 122.910004 120.800003 ... 119.930939 3261100 116.480003
Can anyone advise on why there is a discrepancy?
Thanks!
Hi I also need a psar trend shift detecting code. I am horribly new to coding and algotrading been trying to use ai to get the code but after hundreds of codes I ran there is always a problem cam anyone provide a python code. Thanks in advance.
I've been implementing my own Parabolic SAR calculation recently. Somethings that might contribute to the discrepancy:
The OHLCV data for each individual provider is likely slightly different, so it stands to reason that the parabolic SAR calculations are slightly different as well.
Parabolic SAR is also calculated recursively, using the previously calculated SAR value to obtain the next. It's unclear how a lot of these platforms track their SAR calculations. Some might have calculated the values since the beginning of their ticker history, some might approximate it at the beginning of the period you're viewing. The length of history each provider has on record to use to calculate is likely different as well.
If you're seeing very large discrepancies that aren't related to the different OHLCV data, there might be unreliable calculations, but you should also ask yourself how reliable you need them to be. Parabolic SARs is valuable to recognize trends and possibly set stop losses.
Are the up trends and downtrends you see with each provider roughly matching up? In my experience they normally are, despite a few cents difference in the quote data and calculation.
» pip install polars-talib