Giter VIP home page Giter VIP logo

Comments (2)

mw66 avatar mw66 commented on May 24, 2024

Python test code is here:

TA-Lib/ta-lib-python#435 (comment)

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 rsi diff (max() & mean()) is quite big (because of the EMA kind of memory -- the inherent difference caused by the algorithm); But the the mfi diff is every small (it should all be 0, the diff is caused by numeric computation stability, i.e. rounding error caused by operation sequence.)

You can try this code yourself.

from ta-lib.

mckelvin avatar mckelvin commented on May 24, 2024

Hey @mingwugmail , I cloned the repo from sourceforge to github to make sure I can add the project as a git submodule. I have no plan to maintain this project however. If you are interested in maintaining this project or if you can reach to the original developer, I'd like to transfer the ownership of the git org.

from ta-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.