计算基金最大回撤的Python代码
def get_maximum_retracement(date_totalworth_dict:dict):
"""
date_totalworth_dict:dict
eg. -->{'2019-10-16': 1.0022, '2019-09-11': 1.0, '2019-09-12': 1.0, }
return maximum_retracement
"""
sort_dates = sorted(date_totalworth_dict.keys())
retracement_list = []
for index1, date1 in enumerate(sort_dates):
for index2, date2 in enumerate(sort_dates[:index1]):
result = 1 - date_totalworth_dict[date1] / date_totalworth_dict[date2]
if result > 0:
retracement_list.append(result)
return max(retracement_list)