0
檢查精確值我有一個列表這個如何在LINQ
Porfolio Value CumulativeWeights
1246.540179 0.30873%
1254.380054 0.33031%
1258.260394 0.57136%
1262.300797 4.98794%
1262.710843 5.07213%
首先:如果該列表包含第一個值大於5%選擇價值和 二:我要檢查列表包含確切5 %選擇該值。
如果不滿足上述兩個條件,我們做一些計算。所以如何選擇。
ConfidenceValue爲5%
private static double CaluculateInterpolation(List<AgeWeightedHistorical> Weights, Double ConfidenceValue, CalaculationSettings oCalcSettings)
{
double interpolation=0;
var CumulativeVal = Weights.Find(n => n.CumulativeWeights > ConfidenceValue);
if (CumulativeVal.CumulativeWeights >= ConfidenceValue)
{
interpolation = CumulativeVal.ProfolioPrices;
}
else
{
var LowestValues = Weights.Last(n => n.CumulativeWeights <= ConfidenceValue);
if (LowestValues.CumulativeWeights == ConfidenceValue)
{
interpolation = CumulativeVal.ProfolioPrices;
}
else
{
var HightValues = Weights.FirstOrDefault(n => n.CumulativeWeights >= ConfidenceValue);
double avgPrices = (LowestValues.ProfolioPrices + HightValues.ProfolioPrices)/2;
double avgWeights = (LowestValues.CumulativeWeights + HightValues.CumulativeWeights)/2;
if (avgWeights == ConfidenceValue)
{
interpolation = LowestValues.ProfolioPrices;
}
else
{
double Lowest_val = Math.Abs(LowestValues.CumulativeWeights - ConfidenceValue);
double Higest_val = Math.Abs(HightValues.CumulativeWeights - ConfidenceValue);
var FinalWeight = (Lowest_val < Higest_val) ? LowestValues : HightValues;
double minWeight = Math.Min(avgWeights, FinalWeight.CumulativeWeights)/100;
double maxWeight = Math.Max(avgWeights, FinalWeight.CumulativeWeights)/100;
interpolation = avgPrices - ((avgPrices - FinalWeight.ProfolioPrices) * (((1 - (oCalcSettings.PercentageLevelOfConfidence/100)) - minWeight)/(maxWeight - minWeight)));
}
}
}
return interpolation;
}
IM歌廳錯誤,請幫我
您究竟遇到什麼錯誤? – PaulF
沒有得到正確的值 – Jyothi
完美的問題描述! 10/10 – pitersmx