Description Usage Arguments Details Value Note Author(s) References Examples
Implements a two-fund strategy where allocations to each fund are adjusted to maintain some user-specified portfolio beta. For example, you could back-test a zero-beta (i.e. market neutral) VFINX/VBLTX strategy using this function.
1 2 3 4 5 6 7 8 9 10 11 12 13 | targetbeta.twofunds(tickers = NULL,
intercepts = NULL, slopes = NULL, ...,
benchmark.ticker = NULL,
reference.tickers = NULL,
tickers.gains = NULL,
benchmark.gains = NULL,
reference.gains = NULL,
target.beta = 0,
tol = 0.15,
window.units = 50,
failure.method = c("cash", "closer"),
maxall.tol = tol - 0.05,
initial = 10000)
|
tickers |
Character vector specifying 2 ticker symbols. |
intercepts |
Numeric vector of values to add to daily gains for each ticker. For example, if
you want to simulate a 1% annual expense ratio for only the second fund, you
would set |
slopes |
Numeric vector of values to multiply daily gains for each ticker by. For
example, if you want to simulate a 2x leveraged version of the first fund, you
would set |
... |
Arguments to pass along with |
benchmark.ticker |
Character vector indicating ticker symbol for benchmark index that beta should be calculated from. If unspecified, the first fund is used as the benchmark. |
reference.tickers |
Character string or vector of ticker symbols to include for comparative purposes. |
tickers.gains |
Numeric matrix of gains (daily or otherwise) for the two funds. |
benchmark.gains |
Numeric vector or matrix of gains for the benchmark index that beta should be calculated from. If unspecified, the first fund is used as the benchmark. |
reference.gains |
Numeric vector or matrix of gains for reference funds. |
target.beta |
Numeric value indicating what portfolio beta you want to achieve. |
tol |
Numeric value indicating how far the effective portfolio beta has to deviate
from |
window.units |
Numeric value indicating the width of the trailing moving window used to estimate each fund's beta. |
failure.method |
Character string or vector specifying method(s) to use when fund betas are such
that the target portfolio beta cannot be achieved. Possible values are
|
maxall.tol |
Numeric value indicating tolerance to use when implementing the
|
initial |
Numeric value giving the initial value of the portfolio. |
If tickers
is specified, it gets passed to load.gains
to
load historical prices from Yahoo! Finance using the quantmod package
[1]. If tickers.gains
is specified, gains from that matrix are used.
The general implementation is as follows. Beta for each of the two funds is
estimated based on the first window.units
gains. Initial allocations are
selected to achieve portfolio beta of target.beta
. If that is not
possible - for example, if target.beta = 0
and both funds have positive
beta - then the action taken depends on what method is selected through the
failure.method
input (details below).
Assuming the target beta is attainable, the function moves over 1 day, and
applies each fund's gains for that day. It then re-calculates each fund's beta
based on the window.units
-width interval, and determines the effective
portfolio beta based on fund allocations and betas. If the effective beta is
outside of [target.beta - tol, target.beta + tol]
, a rebalancing trade is
triggered. As before, if the target beta cannot be achieved, certain actions are
taken depending on the selected method.
When outside of a trade because the target beta could not be achieved, the function attempts to rebalance each time it shifts over to a new day, regardless of the effective portfolio beta.
When failure.method = "cash"
, the entire portfolio balance is allocated
to cash when the target beta cannot be achieved.
When failure.method = "fund1"
(or "fund2"
), the entire portfolio
balance is allocated to the first (or second) fund when the target beta cannot
be achieved.
When failure.method = "fund1.maxall"
(or "fund2.maxall"
), when the
target beta cannot be achieved, fund 1 (or fund 2) is combined with cash, with
the fund 1 (fund 2) allocation as high as possible while staying within
maxall.tol
of target.beta
.
When failure.method = "inverse1"
(or "inverse2"
), an inverse
version of the first (or second) fund is used when the target beta cannot be
achieved. In many cases where the target beta cannot be achieved with the two
funds, it can be achieved with an inverse version of one and the other. If the
target beta still cannot be achieved, the entire portfolio balance is allocated
to cash.
When failure.method = "closer"
, the entire portfolio balance is allocated
to whichever fund has a beta closer to target.beta
.
For each method, a 4-element list of the following: (1) Numeric matrix named
fund.balances
giving fund balances over time; (2) Numeric matrix named
fund.betas
giving fund betas over time; (3) Numeric vector named
effective.betas
giving effective portfolio beta over time; and (4)
Numeric value named trades
giving the total number of trades that were
executed. If multiple methods are requested, a list of lists is returned.
NA
Dane R. Van Domelen
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 |
Loading required package: rbenchmark
[1] NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.