Description Usage Arguments Details Value Author(s) See Also Examples
Gets portfolio returns from closing prices (configurable). This uses quantmod under the hood to retrieve prices and construct returns based on a configurable transform.
Also included is a function that returns the composition of select indexes that can be used in conjunction with getPortfolioReturns() to get the underlying returns of the given index.
Additionally, there is a utility function that ensures that symbols have been properly loaded.
1 2 3 4 5 6 |
ticker |
The ticker of the index. For best mileage, use Yahoo! compatible tickers (including the caret prefix). |
hint |
A hint that specifies the number of assets in the index. If omitted, a default will be used based on pre-configured data for common indexes. |
src |
The data vendor to use. Defaults to yahoo but could work with google |
symbols |
A vector (or scalar) of tickers to download |
obs |
The number of observations to get |
start |
Alternatively, a start date can be used to specify the beginning of a range to download. |
end |
The end date of the range. Defaults to current date. |
fun |
A transform applied to the downloaded data. The default is to calculate returns on the close. |
reload |
Whether to reload data or just download missing data |
na.value |
What value to use if the resulting portfolio has NAs. The default is to omit any assets containing NA values. |
serie |
A vector (or scalar) of tickers to ensure exist in the current environment |
... |
Additional parameters to pass to getSymbols |
Typically only getPortfolioReturns and getIndexComposition will be used on a regular basis.
Ensure isn't as useful as initially conceived given that naming collisions have caused numerous issues. The code now uses auto.assign=FALSE in the underlying getSymbols call.
getPortfolioReturns returns a TxM xts object of asset returns.
getIndexComposition returns a vector of asset symbols (i.e. tickers).
ensure returns nothing.
Brian Lee Yung Rowe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ## Not run:
# Get a portfolio
h <- getPortfolioReturns(c('A','AA','AAPL'), obs=150)
# Get an index portfolio
h <- getPortfolioReturns(getIndexComposition('^DJI'), obs=100, reload=TRUE)
# Doesn't work because of numerical symbols - need to fix
#h <- getPortfolioReturns(getIndexComposition('^HSI'), obs=100, reload=TRUE)
# Ensure that some assets exist
ensure(c('K','JNPR'), src='yahoo')
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.