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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

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

	private static final Logger log = LoggerFactory.getLogger(WinRate.class);

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		if (list == null || list.size() == 0) {
			return null;
		}
		Double count = 0D;
		for (CompoundRet unit : list) {
			if (unit.getRetOfFund() != null && unit.getRetOfFund() > 0) {
				count++;
			}
		}
		return list.size() <= 1 ? null : count / (list.size() - 1);
	}

}
