有时间我会添加一个示例策略,但问题的解决方案是:
#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,您可以使用平衡规则在信号出现时将资金应用于策略,或在没有信号时继续投资于指数。
据我所知,blotter 内置的收益分析使用初始资产来计算收益,因此在每笔交易中投资与初始资产相同的金额。10k 初始权益,每笔交易 10k。