Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:33:30+00:00 2026-05-23T13:33:30+00:00

I am trying to (re)build a basic prediction model of the S&P 500 INDEX

  • 0

I am trying to (re)build a basic prediction model of the S&P 500 INDEX (data orignates from Yahoo finance)

I ran into some difficulties with the “ordering” of my data set.
During the build of data.model the following error occurs

Error in xts(new.x, x.index) : NROW(x) must match length(order.by)

After some research I realize that the problem is with the ordering, and it seems to lack ordering as is required for the underlying zoo package.

Is there an elegant way to solve this issue?! Thanks in advance

library(xts)
library(tseries)
library(quantmod)

GSPC <- as.xts(get.hist.quote("^GSPC",start="1970-01-02", 
quote=c("Open", "High", "Low", "Close","Volume","AdjClose")))

head(GSPC)

T.ind <- function(quotes, tgt.margin = 0.025, n.days = 10) {
 v <- apply(HLC(quotes), 1, mean)
 r <- matrix(NA, ncol = n.days, nrow = NROW(quotes))
 for (x in 1:n.days) r[, x] <- Next(Delt(v, k = x), x)
 x <- apply(r, 1, function(x) sum(x[x > tgt.margin | x <
 -tgt.margin]))
 if (is.xts(quotes))
 xts(x, time(quotes))
 else x
}


myATR <- function(x) ATR(HLC(x))[, "atr"]
mySMI <- function(x) SMI(HLC(x))[, "SMI"]
myADX <- function(x) ADX(HLC(x))[, "ADX"]
myAroon <- function(x) aroon(x[, c("High", "Low")])$oscillator
myBB <- function(x) BBands(HLC(x))[, "pctB"]
myChaikinVol <- function(x) Delt(chaikinVolatility(x[, c("High", "Low")]))[, 1]
myCLV <- function(x) EMA(CLV(HLC(x)))[, 1]
myEMV <- function(x) EMV(x[, c("High", "Low")], x[, "Volume"])[, 2]
myMACD <- function(x) MACD(Cl(x))[, 2]
myMFI <- function(x) MFI(x[, c("High", "Low", "Close")], x[, "Volume"])
mySAR <- function(x) SAR(x[, c("High", "Close")])[, 1]
myVolat <- function(x) volatility(OHLC(x), calc = "garman")[, 1]

library(randomForest)
data.model <- specifyModel(T.ind(GSPC) ~ Delt(Cl(GSPC),k=1:10) +
 myATR(GSPC) + mySMI(GSPC) + myADX(GSPC) + myAroon(GSPC) +
 myBB(GSPC) + myChaikinVol(GSPC) + myCLV(GSPC) +
 CMO(Cl(GSPC)) + EMA(Delt(Cl(GSPC))) + myEMV(GSPC) +
 myVolat(GSPC) + myMACD(GSPC) + myMFI(GSPC) + RSI(Cl(GSPC)) +
 mySAR(GSPC) + runMean(Cl(GSPC)) + runSD(Cl(GSPC)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:33:31+00:00Added an answer on May 23, 2026 at 1:33 pm

    traceback() reveals the error occurs in the Delt(Cl(GSPC),k=1:10) call:

    > Delt(Cl(GSPC),k=1:10)
    Error in xts(new.x, x.index) : NROW(x) must match length(order.by)
    

    Delt expects a (m x 1) object but you’re passing a (m x 2) object. This is because GSPC has two columns that are matched by Cl (“Close” and “AdjClose”). This will probably cause headaches in other areas too…

    Cl expects objects like those returned by getSymbols, where the adjusted close column is named “Adjusted”. If you need to use get.hist.quote for some reason, just rename the “AdjClose” column after you download the data.

    colnames(GSPC) <- c("Open", "High", "Low", "Close","Volume","Adjusted")
    Delt(Cl(GSPC),k=1:10)  # works now
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a basic ListFragment based application which transitions from one ListFragment
I'm trying to build some basic object-persistence (save game, load game) into my sandbox
I'm trying to build VERY basic model->controller->view structure with CodeIgniter. I'd rather use models
I am trying to build a basic REST client in PHP as a way
I'm a JavaScript novice trying to build a basic share button as a learning
I am currently trying to build a very basic serial shell with my arduino.
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying build a method which returns the shortest path from one node to
I'm trying to build a basic POP3 mail client in C/++, but I've run
I am completely new to Perl. I am trying to build a basic IRC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.