I have an xts object called Daily_Quotes
that contains stock quotes. I'm using endpoints
to get monthly stock quotes that I retrieved using getSymbols
(from the quantmod package). I noticed that the endpoints
function creates an index of the row that contains the last trading day for the particular month and assigns it to the new object for the specified date range. Is there anyway to get first trading day of the month instead?
# My code
Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,'months')]
What I tried doing was:
# This gave me the next day or 1st day of the next month
# or next row for the object.
endpoints(Daily_Quotes,'months') + 1
# So I applied this and it gave me
# Error in `[.xts`(Daily_Quotes, endpoints(Daily_Quotes, "months") + 1) :
# subscript out of bounds
Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,'months') + 1]
How do I attempt to solve this ?
You can create a startpoints
function like this
startpoints <- function (x, on = "months", k = 1) {
head(endpoints(x, on, k) + 1, -1)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With