package com.smppw.core.reta.calc;

import cn.hutool.core.util.NumberUtil;
import com.smppw.common.pojo.dto.DateValue;
import com.smppw.common.pojo.enums.Frequency;
import com.smppw.common.pojo.enums.Indicator;
import com.smppw.utils.CalcUtils;
import com.smppw.core.reta.Rate;

import java.util.List;

/**
 * 超额最大回撤修复数 -- 几何算法
 *
 * @author lizhuang
 * @date 2022/4/28 10:47
 */
public class ExcessReturnMaxDrawdownRecureIntervalExtra extends Rate {

    @Override
    public Double calc(List<DateValue> navList, List<DateValue> benchMarkNavList, Frequency frequency, boolean ifAnnualized) {
        if (navList == null || benchMarkNavList == null || navList.isEmpty() || benchMarkNavList.isEmpty()) {
            return null;
        }
        //先计算超额净值
        ExtraNav extraNav = new ExtraNav();
        List<DateValue> dateValues = extraNav.extraNav(navList, benchMarkNavList);
        if (dateValues == null || dateValues.isEmpty()) {
            return null;
        }
        String v = CalcUtils.getMaxDrawdownInfo(dateValues).get(Indicator.MaxDrawdownRecureIntervalDays);
        return NumberUtil.parseDouble(v);
    }

    @Override
    public Double calc(List<DateValue> dateValues) {
        return new MaxDrawdownRecureIntervalDays().calc(dateValues);
    }
}
