plot_gains: Plot Gains for One Investment vs. Another

Description Usage Arguments Value References Examples

View source: R/plot_gains.R

Description

Useful for visualizing how two investments behave relate to each other, or how several investments behave relative to the same benchmark.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
plot_gains(
  formula = NULL,
  ...,
  gains = NULL,
  prices = NULL,
  poly_order = 1,
  plotly = FALSE,
  title = NULL,
  base_size = 16,
  return = "plot"
)

Arguments

formula

Formula, e.g. SSO + UPRO ~ SPY to plot gains for SSO and UPRO vs. SPY.

...

Arguments to pass along with tickers to load_gains.

gains

Data frame with one column of gains for each investment mentioned in formula. If unspecified, function downloads historical gains internally.

prices

Data frame with one column of prices for each investment mentioned in formula.

poly_order

Numeric value specifying the polynomial order for linear regression, e.g. 1 for simple linear regression or 2 for linear regression with first- and second-order terms.

plotly

Logical value for whether to convert the ggplot to a plotly object internally. Note that legend displaying regression estimates will disappear if you choose this option.

title

Character string.

base_size

Numeric value.

return

Character string specifying what to return. Choices are "plot", "data", and "both".

Value

In addition to the graph, a list containing fitted linear regression models returned by lm for each investment vs. the benchmark.

References

Jeffrey A. Ryan and Joshua M. Ulrich (2019). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-15. https://CRAN.R-project.org/package=quantmod

Examples

1
2
3
4
5
## Not run: 
# Plot daily gains for SSO and UPRO vs. VFINX
p <- plot_gains(SSO + UPRO ~ VFINX)

## End(Not run)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.