public void CompositePriceCurveFact() { var originDate = new DateTime(2019, 05, 28); var zar = TestProviderHelper.CurrencyProvider.GetCurrency("ZAR"); var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var zarCurve = new ConstantRateIrCurve(0.07, originDate, "ZARCurve", zar); var usdCurve = new ConstantRateIrCurve(0.02, originDate, "USDCurve", usd); var fModel = new FundingModel(originDate, new[] { zarCurve, usdCurve }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider); var fxMatrix = new FxMatrix(TestProviderHelper.CurrencyProvider); var fxPair = new FxPair { Domestic = zar, Foreign = usd, SpotLag = new Dates.Frequency("0d") }; fxMatrix.Init(zar, originDate, new Dictionary <Currency, double> { { usd, 10.0 } }, new List <FxPair>() { fxPair }, new Dictionary <Currency, string> { { usd, "USDCurve" }, { zar, "ZARCurve" } }); fModel.SetupFx(fxMatrix); var baseCurve = new ConstantPriceCurve(100.0, originDate, TestProviderHelper.CurrencyProvider) { Currency = usd, Name = "gooo", AssetId = "rooo" }; var sut = new CompositePriceCurve(originDate, baseCurve, fModel, zar); var sut2 = new CompositePriceCurve(originDate, () => baseCurve, () => fModel, zar); var fxOrigin = fModel.GetFxRate(originDate, usd, zar); Assert.Equal(baseCurve.GetPriceForDate(originDate) * fxOrigin, sut.GetPriceForDate(originDate)); Assert.Equal(baseCurve.GetPriceForDate(originDate) * fxOrigin, sut2.GetPriceForDate(originDate)); Assert.Equal(baseCurve.GetPriceForDate(originDate) * fxOrigin, sut.GetPriceForFixingDate(originDate)); Assert.Equal(baseCurve.GetPriceForDate(originDate) * fxOrigin, sut.GetAveragePriceForDates(new[] { originDate })); Assert.Equal("gooo", sut.Name); Assert.Throws <Exception>(() => sut.Name = null); Assert.Single(sut.GetDeltaScenarios(0.0, null)); Assert.Equal(PriceCurveType.Linear, sut.CurveType); Assert.False(sut.UnderlyingsAreForwards); Assert.Equal(1, sut.NumberOfPillars); Assert.Equal("rooo", sut.AssetId); Assert.Equal(zar, sut.CompoCurrency); Assert.Equal(zar, sut.Currency); Assert.Throws <Exception>(() => sut.Currency = null); Assert.Equal(usd, sut.CurveCurrency); Assert.Single(sut.PillarDates); Assert.Equal(DateTime.Today.AddDays(1), sut.RebaseDate(DateTime.Today.AddDays(1)).BuildDate); Assert.Equal(originDate, sut.PillarDatesForLabel(originDate.ToString("yyyy-MM-dd"))); Assert.Throws <Exception>(() => sut.PillarDatesForLabel("")); }
public void EuropeanBarrierOptionFact() { var orgin = new DateTime(2019, 06, 12); var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var fixDates = new[] { orgin }; var x = new EuropeanBarrierOption() { AssetId = "QS", DiscountCurve = "X", ExpiryDate = orgin, FxConversionType = FxConversionType.None, Notional = 1, PaymentCurrency = usd, PaymentDate = orgin, SpotLag = 0.Bd(), Strike = 1000, Barrier = 1500, }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); fakeModel.Setup(xx => xx.BuildDate).Returns(DateTime.Today); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("QS", a); Assert.Single(x.IrCurves(fakeModel.Object)); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(orgin, x.LastSensitivityDate); var pf = x.PastFixingDates(orgin.AddDays(1)); Assert.Contains("QS", pf.Keys); var y = (EuropeanBarrierOption)x.Clone(); Assert.True(x.Equals(y)); y.TradeId = "xxx"; Assert.False(x.Equals(y)); var z = (EuropeanBarrierOption)x.SetStrike(0); Assert.Equal(0, z.Strike); }
public void FutureOptionFact() { var orgin = new DateTime(2019, 06, 12); var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var fixDates = new[] { orgin }; var x = new FuturesOption() { AssetId = "QS", ExpiryDate = orgin, Strike = 1000, ContractQuantity = 1, LotSize = 1, Currency = usd, PriceMultiplier = 1.0, CallPut = OptionType.C }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); fakeModel.Setup(xx => xx.BuildDate).Returns(DateTime.Today); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("QS", a); Assert.Empty(x.IrCurves(fakeModel.Object)); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(orgin, x.LastSensitivityDate); Assert.Empty(x.PastFixingDates(orgin.AddDays(1))); var y = (FuturesOption)x.Clone(); Assert.True(x.Equals(y)); y.TradeId = "xxx"; Assert.False(x.Equals(y)); var z = (FuturesOption)x.SetStrike(0); Assert.Equal(0, z.Strike); }
public void AsianBasisSwapFact() { var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var fixDates = new[] { DateTime.Today }; var x = new AsianBasisSwap { PaySwaplets = new[] { new AsianSwap { AssetId = "CL", PaymentCurrency = usd, DiscountCurve = "X", FixingDates = fixDates, Strike = 6 } }, RecSwaplets = new[] { new AsianSwap { AssetId = "QS", PaymentCurrency = usd, DiscountCurve = "X", FixingDates = fixDates } }, }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("CL", a); Assert.Contains("QS", a); Assert.Single(x.IrCurves(fakeModel.Object)); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(string.Empty, x.FxPair(fakeModel.Object)); Assert.Equal(6, x.Strike); var y = (AsianBasisSwap)x.SetStrike(7); Assert.Equal(6, x.Strike); Assert.Equal(7, y.Strike); var pf = x.PastFixingDates(DateTime.Today.AddDays(1)); Assert.Contains("CL", pf.Keys); Assert.Contains("QS", pf.Keys); Assert.True(x.Equals(x)); Assert.False(x.Equals(y)); }
private AssetFxModel GetModel() { var irCurveZar = new ConstantRateIrCurve(0.07, ValDate, "ZAR-IR", zar); var irCurveUsd = new ConstantRateIrCurve(0.02, ValDate, "USD-IR", zar); var fxMatrix = new FxMatrix(TestProviderHelper.CurrencyProvider); var fxPair = new FxPair() { Domestic = usd, Foreign = zar, PrimaryCalendar = TestProviderHelper.CalendarProvider.GetCalendar("ZAR"), SecondaryCalendar = TestProviderHelper.CalendarProvider.GetCalendar("USD"), SpotLag = new Frequency("2b") }; fxMatrix.Init(usd, ValDate, new Dictionary <Currency, double> { { zar, 20.0 } }, new List <FxPair> { fxPair }, new Dictionary <Currency, string> { { zar, "ZAR-IR" }, { usd, "USD-IR" } }); var fModel = new FundingModel(ValDate, new[] { irCurveUsd, irCurveZar }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider); fModel.SetupFx(fxMatrix); var fxSurface = new ConstantVolSurface(ValDate, 0.16); fModel.VolSurfaces.Add("USD/ZAR", fxSurface); var crudeCurve = new ConstantPriceCurve(100, ValDate, TestProviderHelper.CurrencyProvider) { Name = "OIL", AssetId = "OIL", Currency = usd }; var crudeSurface = new ConstantVolSurface(ValDate, 0.32) { Name = "OIL", AssetId = "OIL", Currency = usd }; var aModel = new AssetFxModel(ValDate, fModel); aModel.AddPriceCurve("OIL", crudeCurve); aModel.AddVolSurface("OIL", crudeSurface); aModel.CorrelationMatrix = new CorrelationMatrix(new[] { "OIL" }, new[] { "USD/ZAR" }, new double[][] { new [] { 0.5 } }); return(aModel); }
public void AsianSwapStripFact() { var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var fixDates = new[] { DateTime.Today }; var x = new AsianSwapStrip { Swaplets = new[] { new AsianSwap { AssetId = "CL", PaymentCurrency = usd, DiscountCurve = "X", FixingDates = fixDates, Strike = 6, Notional = 1 } }, }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("CL", a); Assert.Single(x.IrCurves(fakeModel.Object)); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(6, x.Swaplets.First().Strike); var y = (AsianSwapStrip)x.SetStrike(7); Assert.Equal(6, x.Swaplets.First().Strike); Assert.Equal(7, y.Swaplets.First().Strike); var pf = x.PastFixingDates(DateTime.Today.AddDays(1)); Assert.Contains("CL", pf.Keys); var z = (AsianSwapStrip)x.Clone(); Assert.True(x.Equals(z)); z.TradeId = "zzz"; Assert.False(x.Equals(z)); Assert.Equal(1.0, x.SupervisoryDelta(fakeModel.Object)); }
private AssetFxModel GetModel() { var vol = new ConstantVolSurface(valDate, assetVol) { AssetId = assetId, Name = assetId }; var fwd = new ConstantPriceCurve(assetPrice, valDate, TestProviderHelper.CurrencyProvider) { AssetId = assetId, Name = assetId }; var ir = new FlatIrCurve(0.0, usd, "USD"); var fm = new FundingModel(valDate, new[] { ir }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider); var am = new AssetFxModel(valDate, fm); am.AddPriceCurve(assetId, fwd); am.AddVolSurface(assetId, vol); return(am); }
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 ForwardFact() { var orgin = new DateTime(2019, 06, 12); var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var zar = TestProviderHelper.CurrencyProvider.GetCurrency("ZAR"); var fixDates = new[] { orgin }; var x = new Forward() { AssetId = "QS", DiscountCurve = "X", ExpiryDate = orgin, FxConversionType = FxConversionType.None, Notional = 1, PaymentCurrency = usd, PaymentDate = orgin, SpotLag = 0.Bd(), Strike = 1000, }; var xFx = new Forward() { AssetId = "USD/ZAR", DiscountCurve = "Y", ExpiryDate = orgin, FxConversionType = FxConversionType.None, Notional = 1, PaymentCurrency = usd, PaymentDate = orgin, SpotLag = 0.Bd(), Strike = 1000, }; var x2 = new Forward() { AssetId = "QS", DiscountCurve = "X", ExpiryDate = orgin, FxConversionType = FxConversionType.AverageThenConvert, Notional = 1, PaymentCurrency = zar, PaymentDate = orgin, SpotLag = 0.Bd(), Strike = 1000, }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); fakeModel.Setup(xx => xx.BuildDate).Returns(DateTime.Today); var fxMatrix = new FxMatrix(TestProviderHelper.CurrencyProvider); fxMatrix.Init(usd, orgin, new Dictionary <Currency, double>(), new List <FxPair>(), new Dictionary <Currency, string> { { usd, "X" }, { zar, "Y" } }); var fModel = new Mock <IFundingModel>(); fModel.Setup(xx => xx.FxMatrix).Returns(fxMatrix); fakeModel.Setup(xx => xx.FundingModel).Returns(fModel.Object); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("QS", a); Assert.Single(x.IrCurves(fakeModel.Object)); var ir2 = xFx.IrCurves(fakeModel.Object); Assert.Contains("X", ir2); Assert.Contains("Y", ir2); ir2 = x2.IrCurves(fakeModel.Object); Assert.Contains("X", ir2); Assert.Contains("Y", ir2); Assert.Equal(string.Empty, x.FxPair(fakeModel.Object)); Assert.Equal("USD/ZAR", x2.FxPair(fakeModel.Object)); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(orgin, x.LastSensitivityDate); var pf = x.PastFixingDates(orgin.AddDays(1)); Assert.Contains("QS", pf.Keys); var y = (Forward)x.Clone(); Assert.True(x.Equals(y)); y.TradeId = "xxx"; Assert.False(x.Equals(y)); var z = (Forward)x.SetStrike(0); Assert.Equal(0, z.Strike); Assert.Equal(1.0, z.SupervisoryDelta(fakeModel.Object)); }
public void MultiPeriodBackpricingOptionFact() { var orgin = new DateTime(2019, 06, 12); var usd = TestProviderHelper.CurrencyProvider.GetCurrency("USD"); var zar = TestProviderHelper.CurrencyProvider.GetCurrency("ZAR"); var fixDates = new[] { orgin }; var x = new MultiPeriodBackpricingOption() { AssetId = "QS", CallPut = OptionType.C, DiscountCurve = "X", FixingDates = new List <DateTime[]>() { fixDates }, FxConversionType = FxConversionType.None, Notional = 1, PaymentCurrency = usd, SpotLag = 0.Bd(), SpotLagRollType = RollType.F, PeriodDates = new [] { new Tuple <DateTime, DateTime> (orgin, orgin) } }; var x2 = new MultiPeriodBackpricingOption() { AssetId = "QS", CallPut = OptionType.C, DiscountCurve = "X", FixingDates = new List <DateTime[]>() { fixDates }, FxConversionType = FxConversionType.AverageThenConvert, Notional = 1, PaymentCurrency = zar, SpotLag = 0.Bd(), SpotLagRollType = RollType.F, PeriodDates = new[] { new Tuple <DateTime, DateTime>(orgin, orgin) } }; var fakeModel = new Mock <IAssetFxModel>(); var c = new ConstantPriceCurve(100, DateTime.Today, TestProviderHelper.CurrencyProvider) { Currency = usd }; fakeModel.Setup(xx => xx.GetPriceCurve(It.IsAny <string>(), null)).Returns(c); var fxMatrix = new FxMatrix(TestProviderHelper.CurrencyProvider); fxMatrix.Init(usd, orgin, new Dictionary <Currency, double>(), new List <FxPair>(), new Dictionary <Currency, string> { { usd, "X" }, { zar, "Y" } }); var fModel = new Mock <IFundingModel>(); fModel.Setup(xx => xx.FxMatrix).Returns(fxMatrix); fakeModel.Setup(xx => xx.FundingModel).Returns(fModel.Object); Assert.Equal(usd, x.Currency); Assert.Equal(usd, x.PaymentCurrency); var a = x.AssetIds; Assert.Contains("QS", a); Assert.Single(x.IrCurves(fakeModel.Object)); var ir2 = x2.IrCurves(fakeModel.Object); Assert.Contains("X", ir2); Assert.Contains("Y", ir2); Assert.Equal(FxConversionType.None, x.FxType(fakeModel.Object)); Assert.Equal(orgin, x.LastSensitivityDate); var pf = x.PastFixingDates(orgin.AddDays(1)); Assert.Contains("QS", pf.Keys); Assert.Equal(string.Empty, x.FxPair(fakeModel.Object)); Assert.Throws <InvalidOperationException>(() => x.SetStrike(0)); }