Description Usage Arguments Value Examples
View source: R/plot_metrics_overtime.R
Useful for assessing how one or two performance metrics vary over time, for one or several funds. Supports fixed-width rolling windows, fixed-width disjoint windows, and disjoint windows on per-month or per-year basis.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
metrics |
"Long" data frame with Fund column, Date column, and column
for each metric you want to plot. Typically the result of a prior call to
|
formula |
Formula specifying what to plot, e.g. |
type |
Character string or vector specifying type of calculation.
Choices are (1) |
minimum.n |
Integer value specifying the minimum number of observations per period, e.g. if you want to exclude short partial months at the beginning or end of the analysis period. |
tickers |
Character vector of ticker symbols that Yahoo! Finance recognizes, if you want to download data on the fly. |
... |
Arguments to pass along with |
gains |
Data frame with a date variable named Date and one column of gains for each investment. |
prices |
Data frame with a date variable named Date and one column of prices for each investment. |
benchmark, y.benchmark, x.benchmark |
Character string specifying which
fund to use as benchmark for metrics (if you request |
plotly |
Logical value for whether to convert the
|
title |
Character string. Only really useful if you're going to set
|
base_size |
Numeric value. |
return |
Character string specifying what to return. Choices are
|
Depending on return
, a ggplot
, a data frame
with the source data, or a list containing both.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ## Not run:
# Plot net growth each year for BRK-B and SPY
plot_metrics_overtime(formula = growth ~ ., type = "hop.year", tickers = c("BRK-B", "SPY"))
# Create previous plot in step-by-step process with pipes
c("BRK-B", "SPY") %>%
load_gains() %>%
calc_metrics_overtime("growth", type = "hop.year") %>%
plot_metrics_overtime(growth ~ .)
# Plot betas from 100-day disjoint intervals for a 2x daily (SSO) and 3x
# daily (UPRO) leveraged ETF
plot_metrics_overtime(formula = beta ~ ., type = "hop.100", tickers = c("SSO", "UPRO"))
# Create previous plot in step-by-step process with pipes
c("SPY", "SSO", "UPRO") %>%
load_gains() %>%
calc_metrics_overtime(metrics = "beta", type = "hop.100") %>%
plot_metrics_overtime(formula = beta ~ .)
# Plot 50-day rolling alpha vs. beta for SSO and UPRO during 2018
plot_metrics_overtime(
formula = alpha ~ beta,
type = "roll.50",
tickers = c("SSO", "UPRO"),
from = "2018-01-01", to = "2018-12-31"
)
# Create previous plot in step-by-step process with pipes
c("SPY", "SSO", "UPRO") %>%
load_gains(from = "2018-01-01", to = "2018-12-31") %>%
calc_metrics_overtime(metrics = c("alpha", "beta"), type = "roll.50") %>%
plot_metrics_overtime(alpha ~ beta)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.