Code Monkey home page Code Monkey logo

Comments (2)

DeanLeeFumu avatar DeanLeeFumu commented on August 23, 2024

Hi, I've got the same issue here.

Turned out the problem is in this line:

numMA <- do.call(maType, c(list(num), list(n = smooth)))

The output contains strange float errors
ex:
expected 0 but -0.000000000000003552714
expected 0.2 but 0.199999999999995736744

And the code:

fastK <- numMA/denMA

That's why there are Infinities in fastK

Since the Inf is in the vector, the code below is not able to correct it:

fastK[is.nan(fastK)] <- 0.5

Can it be fixed ?

from ttr.

joshuaulrich avatar joshuaulrich commented on August 23, 2024

The only way I can reproduce this is if the Close is > High, and High and Low are equal. But that would be a data error. Regardless, this can be fixed in stoch() by changing is.nan() to !is.finite().

Here's a reproducible example:

x <- structure(c(53.99, 54.69, 55.55, 55.55, 55.55, 52.5, 52.5, 52.5, 52.5,
  52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 51.77, 51.77, 53.99,
  54.69, 55.55, 55.55, 55.55, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5, 52.5,
  52.5, 52.5, 52.5, 52.5, 52.5, 51.77, 51.77, 54.09, 54.79, 55.65, 55.65,
  55.65, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6, 52.6,
  52.6, 52.6, 51.87, 51.87), class = c("xts", "zoo"), src = "yahoo",
  updated = structure(1597593022.65377, class = c("POSIXct", "POSIXt")),
  index = structure(c(1446422400, 1446508800, 1446595200, 1446681600,
    1446768000, 1447027200, 1447113600, 1447200000, 1447286400, 1447372800,
    1447632000, 1447718400, 1447804800, 1447891200, 1447977600, 1448236800,
    1448323200, 1448409600, 1448582400, 1448841600), tzone = "UTC", tclass = "Date"),
    .Dim = c(20L, 3L), .Dimnames = list(NULL, c("QTWN.High", "QTWN.Low", "QTWN.Close")))
s <- TTR::stoch(x, 10, 3)

The error is different because the original error was from a .Fortran() call and the current code use .Call().

from ttr.

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.