用dolphindb语句计算最大回撤时间有没有什么比较简洁的方式

如图定义的最大回撤。请问用dolphindb怎样实现计算回撤的收益,回撤的时间长度等指标

attachments-2022-05-xv8LkH0J6277c4bdbdda8.png

请先 登录 后评论

1 个回答

haaha

可以通过如下函数计算最大的回测收益,回测天数,回测的开始和结束日期

defg maxWithdraw(r){
 cumret = cumsum(r)
 return max(cumret.cummax() - cumret)
}

defg maxWithdrawTime(t, r){
 cumret = cumsum(r)
 cumretMax = cummax(cumret)
 indexMaxWithdraw = imax(cumretMax - cumret)
 indexPeak = at(cumret.subarray(0:(indexMaxWithdraw+1)) == cumretMax[indexMaxWithdraw]).tail()
 return max(cumret.cummax() - cumret),t[indexMaxWithdraw] - t[indexPeak],t[indexPeak],t[indexMaxWithdraw]
}

t = 2022.01.01 + 0..7
r = 10 20 100 -20 -50 -20 50 50
maxWithdraw(r)
maxWithdrawTime(t, r)

attachments-2022-05-JN1G8Kdp6277c90ae0a9d.png


请先 登录 后评论