Reputation: 5807
First a reproducible example:
library(quantstrat)
getSymbols("AAPL")
Test<-period.apply(AAPL,endpoints(AAPL,on="weeks",k=10),ROC)
TestDF<-as.data.frame(Test)
I want to get the ROC for a certain stock or whatever for x weeks. Or in other words, I want to compare several stocks and rank them with their 10-week ROC, 20 week ROC etc. Obviously the period apply works, however when I want to convert it to a data Frame and look at my data I always get this error:
Error in coredata.xts(x) : currently unsupported data type
Any idea whats wrong?
Upvotes: 1
Views: 919
Reputation: 176648
period.apply
requires a function that returns a single row. ROC
does not return a single row. So define your own function to do that.
Test <- period.apply(AAPL, endpoints(AAPL,on="weeks",k=10),
function(x) log(last(x)/coredata(first(x))))
Upvotes: 3