Question

I'm programming a function in which I want to plot let's say the stock price for any stock during the last 365 days. However not trading days, but just a one year period. So if I'm generating the chart on the 15th of February I want data from the 16th February 2012-15th February 2013. How can I do that? last() for example shows me the last 365 trading days or days of which there is data available.

library(quantmod)
getSymbols("AAPL")
plot(AAPL)
Was it helpful?

Solution

User character subsetting.

AAPL[paste(Sys.Date()-365, Sys.Date(), sep="/")]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top