Hi,
I suspect I'm making this far more difficult than it needs to be,
however I've spent time looking on Stack Overflow and couldn't find an
answer. Hopefully someone here can point me in the right direction.
Thanks in advance.
I would like to do something in quantstrat like set up an initial
buy for all symbols in a portfolio on a certain date. To that end I
want a signal column that says the date is matching my buy date and
then I'l execute a specific rule. However signals need to match
columns which led me to wanting the index in a column as a value. To
that end the code below basically does this but returns a numerical
value which (I think) is referenced to 1970-01-01.
Anyway, how do I turn these numeric values back into dates that I
could test against 'testDate'?
Thanks,
Mark
require(quantstrat)
Sys.setenv(TZ="UTC")
symbol = "SPY"
getSymbols(symbol,src="yahoo",from="2014-01-01")
testDate = "2014-03-11"
xtsIndex = function(data){
xtsIndex = reclass(index(data), match.to=data)
colnames(xtsIndex)="xtsIndex"
return(xtsIndex)
}
IndexAsXts = xtsIndex(get(symbol))
tail(IndexAsXts)
#Find origin
LastVal = last(IndexAsXts)
OriginDate = index(LastVal) - as.numeric(LastVal)
print(OriginDate)
tail(as.POSIXct(coredata(IndexAsXts), origin=OriginDate,
tz=Sys.getenv("TZ")), 5)