GithubHelp home page GithubHelp logo

Comments (1)

joshuaulrich avatar joshuaulrich commented on June 3, 2024

The R-Forge bug report included an attached file with the following contents:

DVIEx = function (price, n = 252, wts = c(0.8, 0.2), smooth = 3, magnitude = c(5, 
    100, 5), stretch = c(10, 100, 2)) 
{
    price <- try.xts(price, error = as.matrix)
    wts.sum <- sum(wts)
    wts[1] <- wts[1]/wts.sum
    wts[2] <- wts[2]/wts.sum
    r <- price/SMA(price, smooth) - 1
    mag <- SMA((SMA(r, magnitude[1]) + SMA(r, magnitude[2])/10)/2, 
        magnitude[3])
    b <- ifelse(price > lag(price), 1, -1)
    str <- SMA((runSum(b, stretch[1]) + runSum(b, stretch[2])/10)/2, 
        stretch[3])
    pctRank <- function(x, i) match(x[i], sort(coredata(x[(i - 
        (n - 1)):i])))
    dvi.mag <- dvi.str <- rep(NA, NROW(price))

    ii = 1
    len = NROW(price)

    # Find the first index for each both mag and str are not NAs
    while (ii <= len && (is.na(mag[ii]) || is.na(str[ii]))) {
        ii = ii + 1
    }

    # We want to start with n non-NA values
    ii = ii + n

    if (ii > len ) return(NULL)

    while (ii <= len) {
        dvi.mag[ii] <- pctRank(mag, ii)/n
        dvi.str[ii] <- pctRank(str, ii)/n
        ii = ii + 1
    }

    dvi <- wts[1] * dvi.mag + wts[2] * dvi.str
    reclass(cbind(dvi.mag, dvi.str, dvi), price)
}

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.