在C#列表中选择相关值

时间:2017-05-23 03:13:17

标签: c#

ExposureDate    ProfolioPrices  LastPeriods HybridWeights   CummulativeWeights  
10/03/2010       1254.380054        24       0.01836824       1.83682%      
10/26/2010       1258.260394        1        0.07623018       2.45984%      
10/16/2010       1262.710843        11       0.04105873       3.91836%  
10/07/2010       1264.986911        20       0.02352644       4.56572%  
10/09/2010       1265.461347        18       0.02662566       5.52092%  
10/19/2010       1265.76087         8        0.04943356       5.58428%  

从上面的数据我必须选择5%的价值。所以没有5%所以选择相关值接近5%(4.56572和5.52092%),各自的价格也是如此。

private static List<AgeWeightedHistorical> Service(double[] values, DateTime[] datetime)
    {

        List<AgeWeightedHistorical> Data = new List<AgeWeightedHistorical>();
        for (int i = 0; i < values.Length; i++)
        {
            var ag = new AgeWeightedHistorical();
            ag.ExposureDate = datetime[i];
            ag.ProfolioPrices = values[i];
            ag.LastPeriods = values.Length - Data.Count;
            Data.Add(ag);
        }
        Data.ForEach(sd => sd.HybridWeights =
                     Math.Round((Math.Pow(0.94, sd.LastPeriods - 1)) * ((1 - 0.94) / (1 - Math.Pow(0.94, values.Length))),8));
        Data = Data.OrderBy(sd => sd.ProfolioPrices).ToList();
        foreach (var item in Data)
        {
            item.weights = item.CummulativeWeights + item.HybridWeights;
            item.CummulativeWeights =Math.Round(Data.Sum(sd => sd.weights) * 100,5);
        }
        return Data;
    }

这是我的代码如何选择该值。建议我..

0 个答案:

没有答案