stocks-package: Stock Market Analysis

Description Details Note Author(s) References Examples

Description

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.

Details

Package: stocks
Type: Package
Version: 1.1.2
Date: 2018-01-29
License: GPL-2

The following functions are included:

diffs
pdiffs
pchanges
ratios
pos
neg
nonpos
nonneg
convert.rate
daily.yearly
yearly.daily
balances
final.balance
ticker.dates
load.gains
load.prices
prices.rate
gains.rate
mdd
sharpe.ratio
sortino.ratio
rrr
metrics
beta.trailing50
twofunds.graph
threefunds.graph
growth.graph
gains.graph
onemetric.graph
twometrics.graph
onemetric.overtime.graph
targetbeta.twofunds
targetall.nfunds
contango.simple
contango.hedged

Note

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.

Author(s)

Dane R. Van Domelen

Maintainer: Dane R. Van Domelen <[email protected]>

References

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.

Examples

 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"))

Example output

Loading required package: rbenchmark

stocks documentation built on May 2, 2019, 5:22 p.m.