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.DataUtil;

import java.util.List;

public class UpCaptureRatio extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		Double countX = 0.0;
		double UCRX = 1;

		for (CompoundRet value : list) {
			if (value.getRetOfBmk() == null) {
				continue;
			}
			if (value.getRetOfBmk() >= 0) {
				countX++;
				UCRX *= value.getRetOfBmk() + 1;
			}
		}
		if (countX == 0) {
			return null;
		}
		UCRX = Math.pow(UCRX, 1.0 / countX) - 1;
		Double UCRY = new UpCaptureReturn().calc(list, frequency, ifAnnualized);
//		if (UCRY == null) {
//			return null;
//		}else if (UCRX == 0) {
//			return DataUtil.handleOverflowData(UCRY);
//		}
//
//		Double result = UCRY / UCRX;
		return DataUtil.divNearZeroValue(UCRY, UCRX);
	}

}
