Re: [R] Trying to Generalize a Function in R

2018-08-10 Thread rsherry8
Duncan, Since you asked, here is an updated version of my function. # This method gets the Data. getReturns1 <- function(symbol, norm = FALSE) { library(quantmod) series = getSymbols(symbol, src = "yahoo", from = start, to = end, auto.assign = FALSE) length <- nrow( series )

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Joshua Ulrich
Peter was on the right track. getSymbols() allows you to specify that you want the value returned as an object instead of load()ed by setting auto.assign = FALSE. I've also made other changes to your function: - Use requireNamespace() so you don't alter the search() path - Use TTR::ROC() to calcu

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Bert Gunter
" I am thinking that there should be an R command to tell me about the structure of series" ?str ## perhaps also/instead ?summary Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in hi

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread rsherry8
Peter, Here is the R command and its output that you requested: > class(AVB) [1] "xts" "zoo" Bob On 8/9/2018 5:29 PM, Peter Langfelder wrote: Well, your function uses AVB$AVB.Close, so I assumed AVB is a list (a data frame can be thought of as a special list). What do you get when you type cla

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread rsherry8
Duncan, Thanks for the response. I tired the following: > series <- getSymbols("AVB", src = "yahoo", from = start, to = end) > series[0] character(0) > nrow( series ) NULL nrow( series ) returned NULL. I do not understand why. I am thinking that there should be an R

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Peter Langfelder
Well, your function uses AVB$AVB.Close, so I assumed AVB is a list (a data frame can be thought of as a special list). What do you get when you type class(AVB)? Peter On Thu, Aug 9, 2018 at 2:24 PM rsherry8 wrote: > > Peter, > > Thanks for the response. I tired the following command: > AVB[[

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread rsherry8
Peter, Thanks for the response. I tired the following command: AVB[["AVB.Close"]] and I got: Error in AVB[["AVB.Close"]] : subscript out of bounds Are you assuming that AVB is a data frame? I do not think AVB is a data frame. Is there a way for me to check? Thanks, Bob On 8/9/2018 3:46

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Peter Langfelder
If I understand it correctly, the function getSymbols creates a variable with the name being the stock symbol. Then use the function get(symbol) to retrieve the value of the variable whose name is contained in the character string `symbol'. Assign that to a variable (e.g. AVB). You may also have to

[R] Trying to Generalize a Function in R

2018-08-09 Thread rsherry8
I wrote the following function: # This method gets historical stock data for the stock Avalon Bay whose symbol is AVB. getReturns <- function(norm = FALSE) { library(quantmod) getSymbols("AVB", src = "yahoo", from = start, to = end) length = length( AVB$AVB.Close ) close = a