Giter Site home page Giter Site logo

Comments (5)

bizso09 avatar bizso09 commented on July 21, 2024

it's because this line is leaving a 0 at the end

for i in range(1, len(trs)-1):
    trs[i] = trs[i-1] - (trs[i-1]/float(n)) + tr[n+i]

I haven't looked into it more, but the resulting adx has no nan

from ta.

DavidAlmasan avatar DavidAlmasan commented on July 21, 2024

Is there a fix in plan for this? Or is there a workaround that we can use until a fix is in place?

from ta.

codeninja avatar codeninja commented on July 21, 2024

Bump for this as I'm running into the same problem using the latest master.

from ta.

codeninja avatar codeninja commented on July 21, 2024

@bukosabino I have fixed the error with this issue. @DavidAlmasan

solution
Trend.py lines ~140 - 180

    trs = np.zeros(len(close) - (n - 1))
    trs[0] = tr.dropna()[0:n].sum()
    tr = tr.reset_index(drop=True)
    for i in range(0, len(trs)-1):
        trs[i+1] = trs[i] - (trs[i]/float(n)) + tr[n+i]

    up = high - high.shift(1)
    dn = low.shift(1) - low
    pos = abs(((up > dn) & (up > 0)) * up)
    neg = abs(((dn > up) & (dn > 0)) * dn)

    dip_mio = np.zeros(len(close) - (n - 1))
    dip_mio[0] = pos.dropna()[0:n].sum()

    pos = pos.reset_index(drop=True)
    for i in range(0, len(dip_mio)-1):
        dip_mio[i+1] = dip_mio[i] - (dip_mio[i]/float(n)) + pos[n+i]

    din_mio = np.zeros(len(close) - (n - 1))
    din_mio[0] = neg.dropna()[0:n].sum()

    neg = neg.reset_index(drop=True)
    for i in range(0, len(din_mio)-1):
        din_mio[i+1] = din_mio[i] - (din_mio[i]/float(n)) + neg[n+i]

The issue is an off by one error by which the trs variable was not having it's final value in the list set (thus remaining 0) and this resulted in a divide by 0 error when it encountered

    for i in range(len(trs)):
        dip[i] = 100 * (dip_mio[i]/trs[i])

    din = np.zeros(len(trs))
    for i in range(len(trs)):
        din[i] = 100 * (din_mio[i]/trs[i])

I will be submitting a PR for this.

from ta.

bukosabino avatar bukosabino commented on July 21, 2024

Hi @codeninja ,

Thank you for your effort. I accepted your PR, but, when I test the results using your implementation, the tests didn't pass :(

Could you take a look again?

Best,
Dario

from ta.

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.