I have some experience in R but so far never used my own environment. Over the last months I had to use my own environment from time to time and I have some questions about it.
- The main reason for using an environment as "data-container" is
because it is much faster then others, right? For example, using the
quantmod
why do we load OHLC objects into an environment by usinggetSymbols
?
Having such a new environment coming from getSymbols
, i.e.
tick = c( "VNO" , "VMC" , "WMT" , "WAG")
data.env <- new.env() start<-as.Date("2013-01-01")
getSymbols(tick,env=data.env,src="yahoo",from=start)
How can we efficiently access members in data.env, e.g. if we want to check if all members in data.env are OHLC objects can we do something like: is.OHLC(data[[all elements]])
?
Moreover, for the above examples of data, how can I calculate the Value at Risk for such a portfolio. My idea was to us the function VaR
from the PerformanceAnalytics
library. The help page of VaR
says as argument: "an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns". For this purpose I wanted to use dailyReturn
to get the returns, which then can be used for the function VaR
. However dailyReturn
needs an OHLC object as argument. Hence I can calculate VaR
as soon as I know how to turn the elements in data.env
to a OHLC matrix