public void TestConversions(Double valueBase, String currencyBase, String currencyCounter, Double valueExpected, String currencyExpected) { FxRatesProvider ratesProvider = m_TestsFixture.RatesProvider; Amount amountBase = Amount.Of(Currency.Parse(currencyBase), Utilities.Round(valueBase, 2)); Currency oCurrencyCounter = Currency.Parse(currencyCounter); Amount expected = Amount.Of(Currency.Parse(currencyExpected), Utilities.Round(valueExpected, 2)); Amount actual = Amount.Round(ratesProvider.Convert(amountBase, oCurrencyCounter), 2, MidpointRounding.AwayFromZero); Assert.Equal(expected, actual); }
private static Decimal CalculateThresholdFactor(Currency calculationCurrency, FxRatesProvider ratesProvider, SensitivityRisk risk, SensitivityCategory category, List <Sensitivity> sensitivities) { if ((risk == SensitivityRisk.Rates) && (category == SensitivityCategory.Delta)) { sensitivities = sensitivities.Where(x => x.Subrisk != SensitivitySubrisk.CrossCurrencyBasis).ToList(); if (sensitivities.Count == 0) { return(1m); } } Amount sum = Amount.Abs(Amount.Sum(sensitivities.Select(x => x.Amount), calculationCurrency)); IThresholdIdentifier thresholdIdentifier = sensitivities.Select(y => y.ThresholdIdentifier).Distinct().Single(); Amount threshold = ratesProvider.Convert(ModelParameters.GetThreshold(risk, category, thresholdIdentifier), calculationCurrency); return(Math.Max(1m, MathUtilities.SquareRoot((sum / threshold).Value))); }