场景(使用quantstrat,blotter和portfolioanalytics)
我想知道所有交易中此策略的AVERAGE回报。
实际上,如果我只有10k,我只能同时进行一次交易,但我想知道平均回报是多少。
然后我想将其与股票指数基准进行比较。
答案 0 :(得分:0)
我有时间添加示例策略,但问题的解决方案是:
#get the portfolio returns
instRets <- PortfReturns(account.st)
#for each column, NA the values where there is no return, because when the values are averaged out, you don't want 0's to be included in the calculation
# if there are no signals in the strategy, you will invest money elsewhere rather than just leaving lying around. Therefore you only calculate the returns #when the strategy is ACTIVE
for (i in 1:ncol(instRets)){
instRets[,i][instRets[,i] == 0] <- NA
}
#this will give you the average return when the strategy is active, if there are 100 trades on, you want the average return during that period.
portfRets <- xts(rowMeans(instRets, na.rm = T), order.by = index(instRets))
portfRets <- portfRets[!is.na(portfRets)]
现在您可以将策略与基准SPY进行比较。如果策略具有alpha,则可以使用平衡规则在信号出现时将策略应用于策略,或者在没有信号时将其投入到索引中。
据我所知,印刷机内置的回报分析使用初始权益来计算回报,因此每笔交易投资的金额与初始股权相同。 10k初始股权,每笔交易10k。