package com.smppw.core.reta.calc;

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

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

/**
 * @author zhengsongliang
 */
public class ExcessReturn extends Rate {

    @Override
    public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
        List<Double> fundRets = new ArrayList<>();
        List<Double> bmkRets = new ArrayList<>();
        int count = 0;
        for (CompoundRet value : list) {
            if (value.getRetOfFund() == null || value.getRetOfBmk() == null)
                continue;
            fundRets.add(value.getRetOfFund());
            bmkRets.add(value.getRetOfBmk());
            count++;
        }
        Double result = count == 0 ? null : MathUtils.getIntervalReturn(fundRets) - MathUtils.getIntervalReturn(bmkRets);
        if (result != null && ifAnnualized) {
            //需要年化
//		    int dateDis = DateUtil.getDateDistance(list.get(0).getEndDate(), list.get(list.size()-1).getEndDate(), Frequency.Daily, true);
            result *= Math.pow(1 + result, frequency.getNum() / list.size()) - 1;
        }
        return result;
    }


}
