Functions for analyzing stocks or other investments. Main features are loading and aligning historical data for ticker symbols, calculating performance metrics for individual funds or portfolios (e.g. compound annualized growth rate, maximum drawdown, Sharpe/Sortino ratio), and creating graphs. C++ code is used where possible to improve processing speed.
The following functions are included:
Many of the functions download data from Yahoo! Finance. In the first half of 2017, there were some issues with the adjusted closing prices listed on Yahoo! Finance. As of Oct. 19, 2017, I believe these issues have been resolved. But if you see really strange results for a particular analysis, you might want to take a closer look and cross-reference with some other sources to verify it's not due to bad data.
Dane R. Van Domelen
Maintainer: Dane R. Van Domelen <[email protected]>
1. Jeffrey A. Ryan (2016). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-6, https://cran.r-project.org/package=quantmod.
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Load historical prices for VFINX and VBLTX #vfinx.vbltx <- load.prices(tickers = c("VFINX", "VBLTX")) # Calculate total growth for VFINX and VBLTX #apply(vfinx.vbltx, 2, prices.rate) # Calculate performance metrics for VFINX and VBLTX #metrics(prices = vfinx.vbltx) # Plot mean vs. SD of daily gains for VFINX/VBLTX portfolios #graph1 <- twofunds.graph(tickers = c("VFINX", "VBLTX")) # Plot CAGR vs. MDD for VFINX/VBLTX and VFINX/VWEHX portfolios #graph2 <- twofunds.graph(tickers = matrix(c("VFINX", "VBLTX", "VFINX", "VWEHX"), 2), # x.metric = "mdd", y.metric = "cagr") # Plot mean vs. SD of monthly gains for VWEHX/VFINX/VBLTX portfolio #graph3 <- threefunds.graph(tickers = c("VWEHX", "VFINX", "VBLTX"))
Loading required package: rbenchmark
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.