[英]Monthly Rebalancing Strategies with Fees
I have a question regarding PerformanceAnalytics and Quantstrat packages.我对 PerformanceAnalytics 和 Quantstrat 软件包有疑问。 I want to test a monthly rebalancing portfolio strategy, but I want to incorporate the effect of annual fees and buy&sell fees for rebalancing.
我想测试每月再平衡投资组合策略,但我想将年费和买卖费用的影响纳入再平衡。
Is there any practical way of doing this?有什么实用的方法可以做到这一点吗? In PerformanceAnalytics, I can easily test the monthly rebalancing strategy, but fees are problematic.
在 PerformanceAnalytics 中,我可以轻松测试每月再平衡策略,但费用是有问题的。 In Quantstrat, I can easily incorporate fees, but is there a way to construct a monthly rebalance structure?
在 Quantstrat 中,我可以轻松地合并费用,但有没有办法构建每月再平衡结构?
Thank you very much,非常感谢,
Kind regards.亲切的问候。
In case an alternative package is also acceptable: here is how it could be done with the PMwR
package.如果替代 package 也是可以接受的:这是使用
PMwR
package 的方法。
Start with example data: 30 industry series from Kenneth French's website.从示例数据开始:来自 Kenneth French 网站的 30 个行业系列。
library("NMOF")
library("PMwR")
library("datetimeutils")
library("zoo")
P <- French(tempdir(),
"30_Industry_Portfolios_daily_CSV.zip",
price.series = TRUE, na.rm = TRUE)
P <- zoo(P, as.Date(row.names(P)))
P <- window(P, start = as.Date("2000-1-1"))
Now we compute the dates at which transactions take place.现在我们计算交易发生的日期。
eoy <- nth_day(index(P), period = "year", n = "last")
## [1] "2000-12-29" "2001-12-31" "2002-12-31" "2003-12-31"
## [5] "2004-12-31" "2005-12-30" "2006-12-29" "2007-12-31"
## [9] "2008-12-31" "2009-12-31" "2010-12-31" "2011-12-30"
## ....
eom <- nth_day(index(P), period = "month", n = "last")
## [1] "2000-01-31" "2000-02-29" "2000-03-31" "2000-04-28"
## [5] "2000-05-31" "2000-06-30" "2000-07-31" "2000-08-31"
## [9] "2000-09-29" "2000-10-31" "2000-11-30" "2000-12-29"
## ....
For the backtest, I'll use function btest
in the PMwR
package.对于回测,我将在 PMwR
btest
中使用PMwR
btest。 It takes as input a function signal
which evaluates to the target portfolio.它将评估为目标投资组合的 function
signal
作为输入。 Suppose we wanted an equal-weights portfolio;假设我们想要一个等权重的投资组合; then
signal
could look as follows:那么
signal
可能如下所示:
signal <- function() {
k <- ncol(Close())
rep(1/k, k)
}
btest
also accepts an argument cashflow
that can be used to add/subtract arbitrary amounts to the cash balance. btest
还接受参数cashflow
,可用于在现金余额中添加/减去任意金额。 The following function deducts 10% of the total wealth at every end of year (it's just an example).以下function每年年末扣除总财富的10%(仅举例)。
cf <- function() {
if (Timestamp(0) %in% eoy)
-Wealth()*0.1
else
0
}
This would take care of the annual fee.这将照顾年费。 The easiest way to include trading fees proportional to the amount traded is via the separate argument
tc
.包含与交易金额成比例的交易费用的最简单方法是通过单独的参数
tc
。 It remains to run the backtest:仍然需要运行回测:
bt <- btest(list(coredata(P)),
timestamp = index(P),
signal = signal,
do.signal = eom,
cashflow = cf,
tc = 0.0025, ## 0.25% transaction fees
convert.weights = TRUE,
initial.cash = 100)
summary(bt)
plot(bt)
## ---------------------------------------------------------
## 03 Jan 2000 ==> 30 Oct 2020 (5242 data points, 0 NAs)
## 100 55.2453
## ---------------------------------------------------------
## High 110.97 (28 Dec 2000)
## Low 35.32 (09 Mar 2009)
## ---------------------------------------------------------
## Return (%) -2.8 (annualised)
## ---------------------------------------------------------
## Max. drawdown (%) 68.2
## _ peak 110.97 (28 Dec 2000)
## _ trough 35.32 (09 Mar 2009)
## _ recovery (NA)
## _ underwater now (%) 50.2
## ---------------------------------------------------------
## Volatility (%) 19.1 (annualised)
## _ upside 12.1
## _ downside 14.7
## ---------------------------------------------------------
##
## Monthly returns ▁▁▃▇█▂▁
##
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec YTD
## 2000 0.0 -3.6 8.0 -0.2 -0.8 0.0 0.3 6.0 -2.3 1.4 -3.8 -4.7 -0.7
## 2001 2.8 -3.5 -4.8 7.5 1.8 -3.1 -1.3 -3.0 -11.1 3.6 6.6 -7.1 -12.5
(Disclosure: I am the maintainer of packages PMwR
, NMOF
and datetimeutils
.) (披露:我是包
PMwR
、 NMOF
和datetimeutils
的维护者。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.