package com.smppw.core.reta.calc;

import com.smppw.common.pojo.dto.CompoundRet;
import com.smppw.common.pojo.dto.DateValue;
import com.smppw.common.pojo.enums.Frequency;
import com.smppw.utils.CalcUtils;
import com.smppw.core.reta.Rate;

import java.util.ArrayList;
import java.util.List;

/**
 * 超额收益最大回测
 */
public class ExcessReturnMaxDrawdown extends Rate {

    @Override
    public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
        List<DateValue> dateValues = new ArrayList<DateValue>();
        for (CompoundRet value : list) {
            if (value.getFundNav() == null || value.getIndexNav() == null) {
                continue;
            }
//			超额最大回撤根据超额净值计算，基金t日的超额净值 = 基金t日净值/基准t日净值
//			dateValues.add(new DateValue(value.getEndDate(), value.getRetOfFund()/value.getRetOfBmk()));
            dateValues.add(new DateValue(value.getEndDate(), value.getFundNav() / value.getIndexNav()));
        }
        Double maxDrawdown = CalcUtils.maxDrawdown(dateValues);
        return maxDrawdown == null ? null : -maxDrawdown;
    }

}
