예제 #1
0
        public void Portfolio()
        {
            var bd  = DateTime.Parse("2018-09-13");
            var swp = AssetProductFactory.CreateTermAsianSwap(bd, bd.AddYears(1), 100, "AssetX", CalendarProvider.Collection["USD"], bd.AddYears(2), CcyProvider.GetCurrency("USD"));

            var pf = new Portfolio()
            {
                Instruments = new List <IInstrument>()
            };

            Assert.Empty(PortfolioEx.AssetIds(pf));

            pf.Instruments = new List <IInstrument> {
                swp
            };

            Assert.Equal(swp.LastSensitivityDate, pf.LastSensitivityDate);
            Assert.Equal("AssetX", PortfolioEx.AssetIds(pf).First());
            Assert.Equal(bd.AddYears(2), pf.LastSensitivityDate);

            var deets = PortfolioEx.Details(pf);

            Assert.Throws <NotImplementedException>(() => pf.TradeId);
            Assert.Throws <NotImplementedException>(() => pf.Counterparty);
            Assert.Throws <NotImplementedException>(() => pf.Counterparty = null);
        }
예제 #2
0
        public void TurboPFETest()
        {
            var CI   = 0.95;
            var am   = GetModel();
            var swap = AssetProductFactory.CreateTermAsianSwap(valDate.AddDays(100), valDate.AddDays(100), assetPrice, "CL", null, valDate.AddDays(101), usd);

            swap.DiscountCurve = "USD";

            var pfe = swap.QuickPFE(CI, am);

            var t           = am.BuildDate.CalculateYearFraction(swap.AverageEndDate, Transport.BasicTypes.DayCountBasis.Act365F);
            var pfePrice    = assetPrice * Exp(-assetVol * assetVol * t / 2.0 + assetVol * Sqrt(t) * Statistics.NormInv(CI));
            var expectedPfe = (pfePrice - swap.Strike) * swap.Notional;

            Assert.Equal(expectedPfe, pfe, 6);
        }
예제 #3
0
        public void QuickPFETest()
        {
            var CI   = 0.95;
            var am   = GetModel();
            var swap = AssetProductFactory.CreateTermAsianSwap(valDate.AddDays(100), valDate.AddDays(100), assetPrice, "CL", null, valDate.AddDays(101), usd);

            swap.DiscountCurve = "USD";
            var pf = new Portfolio {
                Instruments = new List <IInstrument> {
                    swap
                }
            };

            var pfeCube = QuickPFECalculator.Calculate(am, pf, CI, usd, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider);
            var pfe     = pfeCube.GetAllRows().Max(x => x.Value);

            var t           = am.BuildDate.CalculateYearFraction(swap.AverageEndDate, Transport.BasicTypes.DayCountBasis.Act365F);
            var pfePrice    = assetPrice * Exp(-assetVol * assetVol * t / 2.0 + assetVol * Sqrt(t) * Statistics.NormInv(CI));
            var expectedPfe = (pfePrice - swap.Strike) * swap.Notional;

            Assert.Equal(expectedPfe, pfe, 6);
        }
예제 #4
0
        private AssetFxMCModel GetSut(bool expensiveFutures, BaseMetric baseMetric = BaseMetric.PV)
        {
            var buildDate = DateTime.Parse("2018-10-04");
            var usd       = TestProviderHelper.CurrencyProvider["USD"];

            TestProviderHelper.CalendarProvider.Collection.TryGetCalendar("NYC", out var usdCal);
            var dfCurve = new IrCurve(new[] { buildDate, buildDate.AddDays(1000) }, new[] { 0.0, 0.0 }, buildDate, "disco", Math.Interpolation.Interpolator1DType.Linear, usd, "DISCO");

            var comCurve = new PriceCurve(buildDate, new[] { buildDate, buildDate.AddDays(15), buildDate.AddDays(100) }, new[] { 100.0, 100.0, 100.0 }, PriceCurveType.NYMEX, TestProviderHelper.CurrencyProvider)
            {
                Name    = "CL",
                AssetId = "CL"
            };
            var comSurface = new ConstantVolSurface(buildDate, 0.32)
            {
                AssetId = "CL"
            };
            var fModel = new FundingModel(buildDate, new Dictionary <string, IrCurve> {
                { "DISCO", dfCurve }
            }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider);
            var fxM = new FxMatrix(TestProviderHelper.CurrencyProvider);

            fxM.Init(usd, buildDate, new Dictionary <Currency, double>(), new List <FxPair>(), new Dictionary <Currency, string> {
                { usd, "DISCO" }
            });
            fModel.SetupFx(fxM);

            var aModel = new AssetFxModel(buildDate, fModel);

            aModel.AddVolSurface("CL", comSurface);
            aModel.AddPriceCurve("CL", comCurve);

            var product = AssetProductFactory.CreateTermAsianSwap(buildDate.AddDays(10), buildDate.AddDays(20), 99, "CL", usdCal, buildDate.AddDays(21), usd);

            product.TradeId       = "waaah";
            product.DiscountCurve = "DISCO";


            var pfolio = new Portfolio {
                Instruments = new List <IInstrument> {
                    product
                }
            };
            var creditSettings = new CreditSettings
            {
                ExposureDates = new DateTime[] { buildDate.AddDays(5), buildDate.AddDays(20), buildDate.AddDays(22) },
                Metric        = baseMetric
            };
            var settings = new McSettings
            {
                Generator                  = RandomGeneratorType.MersenneTwister,
                McModelType                = McModelType.Black,
                NumberOfPaths              = 2048,
                NumberOfTimesteps          = 1,
                ReportingCurrency          = usd,
                ExpensiveFuturesSimulation = expensiveFutures,
                Parallelize                = false,
                FuturesMappingTable        = new Dictionary <string, string> {
                    { "CL", "CL" }
                },
                CreditSettings = creditSettings
            };
            var sut = new AssetFxMCModel(buildDate, pfolio, aModel, settings, TestProviderHelper.CurrencyProvider, TestProviderHelper.FutureSettingsProvider, TestProviderHelper.CalendarProvider);

            return(sut);
        }