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)
有帮助吗?

解决方案

User character subsetting.

AAPL[paste(Sys.Date()-365, Sys.Date(), sep="/")]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top