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;

public class AnnualStdDev extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		List<Double> rates = new ArrayList<>();
		for (CompoundRet value : list) {
			if (value.getRetOfFund() == null)
				continue;
			rates.add(value.getRetOfFund());
		}
		Double StdDev = Statistics.stdDevUnbiased(rates);
		if (ifAnnualized)
			StdDev *= Math.pow(frequency.getNum(), 0.5);
		return StdDev;
	}

}
