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

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

/**
 * @author zhengsongliang
 * @datetime 2017年7月25日 下午3:59:17
 */
public class TrackingError extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		List<Double> dValues = new ArrayList<>();
		for (CompoundRet value : list) {
			if (value.getRetOfFund() == null || value.getRetOfBmk() == null)
				continue;
			dValues.add(value.getRetOfFund() - value.getRetOfBmk());
		}
		double trackingError = Statistics.stdDevUnbiased(dValues);
		return ifAnnualized ? Rate.AnnualizedBySqrt(trackingError, frequency) : trackingError;
	}

}
