public void FactorPriceCurveFact() { var baseCurve = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { AssetId = "wooo", Currency = TestProviderHelper.CurrencyProvider.GetCurrency("USD"), CollateralSpec = "hooo", Name = "booo", SpotCalendar = TestProviderHelper.CalendarProvider.Collection["NYC"], SpotLag = new Dates.Frequency("0d") }; var sut = new FactorPriceCurve(baseCurve, 3); Assert.Equal(300.0, sut.GetPriceForDate(DateTime.Today)); Assert.Equal(300.0, sut.GetPriceForFixingDate(DateTime.Today)); Assert.Equal(300.0, sut.GetAveragePriceForDates(new[] { DateTime.Today, DateTime.Today.AddDays(1) })); Assert.Equal(baseCurve.AssetId, sut.AssetId); Assert.Equal(baseCurve.Currency, sut.Currency); Assert.Equal(baseCurve.Name, sut.Name); Assert.Equal(baseCurve.SpotCalendar, sut.SpotCalendar); Assert.Equal(baseCurve.SpotLag, sut.SpotLag); Assert.Equal(baseCurve.CurveType, sut.CurveType); Assert.Equal(baseCurve.PillarDates, sut.PillarDates); Assert.Equal(baseCurve.NumberOfPillars, sut.NumberOfPillars); Assert.Equal(baseCurve.BuildDate, sut.BuildDate); Assert.Equal(baseCurve.UnderlyingsAreForwards, sut.UnderlyingsAreForwards); Assert.Equal(baseCurve.PillarDatesForLabel(DateTime.Today.ToString("yyyy-MM-dd")), sut.PillarDatesForLabel(DateTime.Today.ToString("yyyy-MM-dd"))); Assert.Throws <NotImplementedException>(() => sut.RebaseDate(DateTime.Today)); Assert.Throws <NotImplementedException>(() => sut.Name = "yooooo"); Assert.Throws <NotImplementedException>(() => sut.Currency = null); Assert.Throws <NotImplementedException>(() => sut.SpotCalendar = null); Assert.Throws <NotImplementedException>(() => sut.SpotLag = new Dates.Frequency()); Assert.Throws <NotImplementedException>(() => sut.GetDeltaScenarios(0.0, DateTime.Today)); }
public void Process(IPathBlock block) { for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count) { var stepsByFactor = new Dictionary <int, Vector <double>[]>(); foreach (var ix in _assetIndices) { stepsByFactor.Add(ix, block.GetStepsForFactor(path, ix).ToArray()); } var indexCounter = 0; var nextIndex = _calculationDateIndices[indexCounter]; var steps = stepsByFactor.First().Value; var fixingDictionaries = _assetFxModel.FixingDictionaryNames.ToDictionary(x => x, x => (IFixingDictionary) new FixingDictionary(_assetFxModel.GetFixingDictionary(x))); for (var i = 0; i < steps.Length; i++) { var d = _timeFeature.Dates[i]; for (var j = 0; j < Vector <double> .Count; j++) { for (var a = 0; a < _assetIndices.Length; a++) { if (!fixingDictionaries.TryGetValue(_assetIds[a], out var fd)) { throw new Exception($"Fixing dictionary not found for asset {_assetIds[a]} "); } fd[d] = stepsByFactor[a][i][j]; } } if (i == nextIndex) { var currentDate = _calculationDates[indexCounter]; var newModel = _assetFxModel.Clone(); newModel.OverrideBuildDate(currentDate); newModel.AddFixingDictionaries(fixingDictionaries); var spotsByAsset = stepsByFactor.ToDictionary(x => x.Key, x => x.Value[i]); for (var j = 0; j < Vector <double> .Count; j++) { //build on-path price curves in model foreach (var spot in spotsByAsset) { var assetId = _assetIds[spot.Key]; var baseCurve = _assetFxModel.GetPriceCurve(assetId); var spotOnCurve = baseCurve.GetPriceForFixingDate(currentDate); var ratio = spot.Value[j] / spotOnCurve; var newCurve = new FactorPriceCurve(baseCurve, ratio); newModel.AddPriceCurve(assetId, newCurve); } var ead = _portfolio.SaCcrEAD(newModel, _reportingCurrency, _assetIdToGroupMap); var capital = _counterpartyRiskWeight * ead; if (!_expectedCapital.ContainsKey(currentDate)) { lock (_threadLock) { if (!_expectedCapital.ContainsKey(currentDate)) { _expectedCapital.Add(currentDate, 0.0); } } } if (double.IsNaN(capital) || double.IsInfinity(capital)) { throw new Exception("Invalid capital generated"); } _expectedCapital[currentDate] += capital; } indexCounter++; nextIndex = indexCounter < _calculationDateIndices.Length ? _calculationDateIndices[indexCounter] : int.MaxValue; } } } }