Ask any Statistics/Probability/Math Question
R package 9 includes the function get.hist.quote() that can be used to download the quotes into a zoo object. The following is an example of the use of this function to get the quotes:
As the function get.hist.quote() returns an object of class zoo , we have again used the function as.xts() to compel it to xts. We should remark that if you issue these commands, you will get more data than what is provided with the object in the book package. You may wonder why we did not load the package zoo with a call to the library() function. The reason is that this was already done when
Where"2009-09-15"is the last day with quotes in the package GSPC object. Another way of obtaining quotes data from the Web (but not the only, as we will see later), is to use the function get Symbols () from package quantmod (Ryan, 2009). Again this is an extra package that you should install before using it. It provides several facilities related to financial data analysis that we will use throughout this chapter. Function get Symbols()In conjunction with other functions of this package provide a rather simple but powerful way of getting quotes data from deferent data sources.
We will now see some examples of its use:
With the framework provided by package quant mod you may actually have several symbols with different associated sources of data, each with its own parameters. All these settings can be specified at the start of your R session with the set Symbol Lookup() function, as you may see in the following example:
In this code we have specified several settings for getting the quotes from the Web of two different symbols for IBM -This is done through function
Set Symbol Lookup(), which ensures any subsequent use of the get Symbols()function in the current R session with the identifiers specified in the call, will use the settings we want. In this context, the second statement will fetch the quotes of the two symbols using the information we have specified. Functions save Symbol Lookup() and load Symbol Lookup() can be used to save and load these settings across different R sessions. Check the help of these functions for further examples and more thorough explanations of the workings behind these handy functions