-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
doc error? why MFI function has an unstable period? #435
Comments
I can't answer your question, however I note that TA_FUNC_UNST_MFI is defined in the ta-lib source code in ta_defs.h:
|
See, for example, how the implementation of MFI seems to use the "unstable period". |
OK, I have showed my point theoretically (in the OP). Now I just did the following test, it shows (actually proves) The MFI function has no unstable period (up to numeric calculation stability). import pandas as pd
import numpy as np
def test():
# check RSI vs MFI unstable period.
fn = "SPY.csv"
df = pd.read_csv(fn)
df["ratio" ] = df["Adj Close"] / df["Close"]
df["Open" ] = df["Open" ] * df["ratio"]
df["High" ] = df["High" ] * df["ratio"]
df["Low" ] = df["Low" ] * df["ratio"]
df["Close" ] = df["Close" ] * df["ratio"]
o = np.array(df["Open"])
h = np.array(df["High"])
l = np.array(df["Low"])
c = np.array(df["Close"])
v = np.array(df["Volume"], dtype=np.double)
rsi = []
for n in [40, 50]:
r = talib.RSI(c[-n:])
print(r)
rsi.append(r)
m = 40 - 14
diff = np.abs(rsi[0][-m:] - rsi[1][-m:])
print(np.max(diff), np.mean(diff)) # 2.6424354952679963 1.1047087679412708
mfi = []
for n in [40, 50]:
m = talib.MFI(h[-n:], l[-n:], c[-n:], v[-n:])
print(m)
mfi.append(m)
m = 40 - 14
diff = np.abs(mfi[0][-m:] - mfi[1][-m:])
print(np.max(diff), np.mean(diff)) # 1.4210854715202004e-14 5.738999019600809e-15
assert(np.all(np.isclose(mfi[0][-m:], mfi[1][-m:]))) # pass! As you can see the You can try this code yourself. |
Well, that looks compelling - thanks for providing! This change should be made upstream in the ta-lib.org project and when they update the code, we can adjust the documentation. |
Well, I think the upstream in the ta-lib.org is dead. The last code update on source forge https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/ Is in 2013. Do you know it's still under maintenance? |
Oh, the new one is here: https://github.com/TA-Lib/ta-lib but it says it's "unofficial"? |
It’s a clone, not official.
Some discussion about taking over maintenance but that’s out of the scope
of this Python wrapper.
I haven’t heard from the original developers in awhile.
…On Sat, Jun 26, 2021 at 11:06 AM mingwugmail ***@***.***> wrote:
Oh, the new one is here:
https://github.com/TA-Lib/ta-lib
but it says it's "unofficial"?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#435 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF5A4I7OJ66CO2EE73OE3TUYJMFANCNFSM47KP3IYA>
.
|
OK, I reported the issue there: |
https://github.com/mrjbq7/ta-lib/blob/master/docs/func_groups/momentum_indicators.md
however, if we check the DESCRIPTION of TA_SetUnstablePeriod(https://ta-lib.org/d_api/ta_setunstableperiod.html).
and then how the MFI is calculated:
https://www.investopedia.com/terms/m/mfi.asp
How to Calculate the Money Flow Index
There are several steps for calculating the Money Flow Index. If doing it by hand, using a spreadsheet is recommended.
It's more like SMA, having look back period of 1 (compare 1st typical price is up/down with the prev typical price), rather than EMA (which will "remember" all the price effect on the current ema value all the way back to the very start).
I think this is a doc error: The MFI function has no unstable period.
The text was updated successfully, but these errors were encountered: