DataFrame.expanding(min_periods=1, center=None, axis=0, method='single')
expanding可以将之前所有数据保留,并且累计统计, 类似cumsum, 但是不同的地方在于可以实现多种统计方法。
原始:
min_periods=1, 表示最小从1个数据开始,求到当前日期为止的中位数。
min_periods=2, 表示最小从2个数据开始,求到当前日期为止的中位数
最大回撤的算法:当前净值/(从头开始的净值最大值), 找到最小的位置,再减去1。
(current_nav / current_nav.expanding(min_periods=0).max()).min() - 1