r - Accessing arbitrary list of symbols returned by getSymbols()? -
short version: how symbolically access objects returned getsymbols()?
(i learning r , first 'real life' script/function. have used better part of day searching , still bewildered).
i want take arbitrary set of symbols , percentage return each symbol high within last year until now.
(or more generally, want manipulation on each symbol individually).
i have tried several approaches; storing them new.env() , trying parse them there, , putting them list(), still cannot access $high. have still not learned lapply , eapply.
this have far:
library(quantmod) symbols<-(c("^dji", "^gdaxi", "^spc","^rut", "xom", "k")) t1<-as.posixlt(as.date(sys.date())) t1$year<-t1$year-1 #one year ago start_date<-t1 for(i in symbols) { x<-getsymbols(i, from=start_date, auto.assign=false) print(serieshi(x)) #used test # high value # last value # print symbol name: # print last/high }
i brute force, looking elegant.
i'm not sure if understand question. if have date time object in data frame, can subset date time object
#this uses range of dates, can use date parts your_subset <- subset(df, posixtime >= as.posixct('2015-02-07 13:45') posixtime <= sys.time())
then can simple make table of data. can simple as:
symbols<-c("^dji", "^gdaxi", "^spc","^rut", "xom", "k","xom") your_proportions <- table(symbols) your_proportions / length(symbols)
Comments
Post a Comment