Seite 1 von 1

Data cleaning mit PerformanceAnalytics

Verfasst: Fr Okt 14, 2016 1:21 pm
von tr206
Hallo zusammen,
ich versuche die returns des SP500 um Ausreisser zu bereinigen. Hierzu denke ich kann Return.clean() aus dem PerformanceAnalytics package hilfreich sein. Das sieht so aus aber ich erhalte dann die Fehlermeldung. Hat jemand eine Idee wie das geht?

Code: Alles auswählen

cleantest <- read.csv("D:/Studie_vola_difference/cleantest.csv")
data<-as.vector(cleantest)
test<-Return.clean(data,method="boudt",alpha=0.01)
Error in checkData(R, method = "xts") : 
  The data cannot be converted into a time series.  If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'.  Rownames should have standard date formats, such as '1985-03-15'. 

Re: Data cleaning mit PerformanceAnalytics

Verfasst: Sa Okt 15, 2016 4:59 pm
von student
Hallo tr206,

die Antwort wird Dir im Fehlerhinweis schon gegeben! Dein Objekt data ist nicht vom typ xts! Du musst die Datei mit Return.read des Paketes einladen:

Code: Alles auswählen

> cleantest <- Return.read("cleantest.csv", frequency="d")
> str(cleantest)
An ‘xts’ object on 2000-01-03/2015-12-31 containing:
  Data: num [1:4025, 1] -0.009549 -0.038345 0.001922 0.000956 0.02709 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "x"
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
 NULL
Dieser Schritt..
data<-as.vector(cleantest)
... ist nicht nötig.

Nach dem Laden wird Return.clean ohne weitere Meldung ausgeführt:

Code: Alles auswählen

> test<-Return.clean(cleantest,method="boudt",alpha=0.01)
> str(test)
An ‘xts’ object on 2000-01-03/2015-12-31 containing:
  Data: num [1:4025, 1] -0.009549 -0.038345 0.001922 0.000956 0.02709 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "x"
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
 NULL
Nur noch ein Hinweis: Das benötigte Paket robust wird wohl nicht mit PerformanceAnalytics geladen.