R 计算策略的平均回报
场景(使用quantstrat、吸墨纸和portfolioanalytics)R 计算策略的平均回报,r,quantstrat,blotter,r-portfolioanalytics,R,Quantstrat,Blotter,R Portfolioanalytics,场景(使用quantstrat、吸墨纸和portfolioanalytics) 我有10万的初始股权 我有一个策略,我想对3000多个符号宇宙(股票)进行回溯测试 假设该策略是一个简单的MA交叉 每次我得到一个买入交叉点,我都会买入价值10万英镑的股票并平仓 在销售交叉线上 出于回溯测试目的,该策略可以在没有任何投资组合限制的情况下进行交易, 因此,我可能在任何时间点持有100+个职位,因此 不应考虑初始股权 我想知道这一策略在所有交易中的平均回报率 实际上,如果我只有10万英镑,我一次只能
- 我有10万的初始股权
- 我有一个策略,我想对3000多个符号宇宙(股票)进行回溯测试
- 假设该策略是一个简单的MA交叉
- 每次我得到一个买入交叉点,我都会买入价值10万英镑的股票并平仓 在销售交叉线上
- 出于回溯测试目的,该策略可以在没有任何投资组合限制的情况下进行交易, 因此,我可能在任何时间点持有100+个职位,因此 不应考虑初始股权
- 我是求和还是表示每个符号的返回流
- 这是投资组合的回报吗?这是否考虑了初始投资
公平?-我不希望回报占初始股本的百分比
或者想想符号是如何交易的。<李>
#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)]
#获取投资组合回报
说明:您必须提供数据集的样本以及理想输出的外观。如果您的数据集是敏感的,那么尝试创建一些我们可以使用的假数据,然后您可以根据您的真实数据集调整解决方案