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 java.util.List;

public class DownCaptureReturn extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		Double countX = 0.0;
		Double UCRY = 1.0;
		for (CompoundRet value : list) {
			if (value.getRetOfBmk() == null || value.getRetOfFund() == null)
				continue;
			if (value.getRetOfBmk() < 0) {
				countX++;
				UCRY *= value.getRetOfFund() + 1;
			}
		}
		return countX == 0 ? null : Math.pow(UCRY, 1.0 / countX) - 1;
	}
}
