English 中文(简体)
R 日内胎率
原标题:Error in Quantmod with intraday fx rates in R

我在每小时提供牛奶率数据时有问题。 I ve 改为:

csv-file such as:

 Date,Open,High,Low,Close,Volume

 2011-08-11 03:00:00,1.41758,1.42205,1.41625,1.42174,8974 

 ...

 2011-08-12 04:00:00,1.42175,1.42413,1.42067,1.42172,7229

 ...

2011-12-30 05:00:00,1.42173,1.42341,1.42062,1.42171,6703

... 


raw<- read.delim2("~/R/Data/EURUSD60.csv",header=TRUE,sep=",") 

 stripday<-strptime(raw$DATE,format="%Y%m%d") 
 fxdata<-data.frame(stripday,raw) 

 write.table(fxdata,"~/R/Data/EURUSD60.csv",quote=FALSE,sep=",",row.names=FALSE) 

 EURUSD<-as.xts(read.zoo("~/R/Data/EURUSD60.csv",sep=",",format="%Y-%m-%d %R",tz="GMT",header=T))

我随后建立了一套指标和以下模式:

 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] 
 myMACD <- function(x) MACD(Cl(x))[,2] 
 mySAR <- function(x) SAR(x[,c( High , Close )]) [,1] 
 myVolat <- function(x) volatility(OHLC(x),calc="garman")[,1] 
 myEMA10 <- function(x) EMA(Cl(x),n=10)[,1] 
 myEMA20 <- function(x) EMA(Cl(x),n=20)[,1] 
 myEMA30 <- function(x) EMA(Cl(x),n=30)[,1] 
 myEMA50 <- function(x) EMA(Cl(x),n=50)[,1] 
 myEMA60 <- function(x) EMA(Cl(x),n=60)[,1] 

 data.model <- specifyModel(Delt(Cl(EURUSD)) ~ 
 myATR(EURUSD) + mySMI(EURUSD) + myADX(EURUSD) + myAroon(EURUSD) + 
 myBB(EURUSD) + myChaikinVol(EURUSD) + myCLV(EURUSD) +myEMA10(EURUSD) +myEMA20(EURUSD)      +myEMA30(EURUSD) +myEMA50(EURUSD) + myEMA60(EURUSD) +
 CMO(Cl(EURUSD)) + EMA(Delt(Cl(EURUSD))) + 
 myVolat(EURUSD) + myMACD(EURUSD) + RSI(Cl(EURUSD)) + 
 mySAR(EURUSD) + runMean(Cl(EURUSD)) + runSD(Cl(EURUSD))) 

我当时试图做以下工作:

 Tdata.train <- as.data.frame(modelData(data.model, 
 data.window=c( 2011-08-03 , 2011-12-30 ))) 

这使我有以下错误:

 Warnings: 
 1: In which(index(model.data) >= as.Date(data.window[1], origin = "1970-01-01")) :
 incopatible methods ("Ops.POSIXt", "Ops.Date") für ">=" 
 2: In which(index(model.data) <= as.Date(data.window[2], origin = "1970-01-01")) :
 incopatible methods ("Ops.POSIXt", "Ops.Date") für "<=" 
 3: In max(i) : kein nicht-fehlendes Argument für max; gebe -Inf zurück 

请允许我告诉我,我是错了吗? 我认为,这是非常简单的事情,我在这里只是站不住脚。 谢谢你们!

最佳回答

问题在于模式。 数据功能,请尝试:

f3 <- function(...) as.POSIXct(paste(...), format = "%Y-%m-%d %H:%M")


    My_modelData <- function(x, data.window = NULL, exclude.training = FALSE)
{
  model.data <- [email protected]
  if (!is.null(data.window)) {
    if (length(data.window) > 2) {
      model.data <- model.data[index(model.data) %in% data.window]
    }
    else {
      start.date.index <- index(model.data[which(index(model.data) >=f3(data.window[1]))])
      end.date.index <- index(model.data[which(index(model.data) <= f3(data.window[2]))])
      date.range <- intersect(start.date.index, end.date.index)
      model.data <- model.data[as.POSIXct(date.range, origin="1970-01-01")]
    }
  }
  if (exclude.training == TRUE) {
    model.data <- model.data[!index(model.data) %in% [email protected]]
  }
  return(model.data)
} 

守则见:http://r.789695.n4.nabble.com/Quantmod-modelData- with-datetime-format-td3860416.html”。 http://r.789695.n4.nabble.com/Quantmod-modelData-with-date-format-td3860416.html。 我稍作修改。

问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签