Ejemplo n.º 1
0
        public static object CreateFixedRateLoanDepo(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Start date")] DateTime StartDate,
            [ExcelArgument(Description = "End date")] DateTime EndDate,
            [ExcelArgument(Description = "Fixed rate")] double FixedRate,
            [ExcelArgument(Description = "Daycount basis, e.g. Act360")] string Basis,
            [ExcelArgument(Description = "Currency")] string Currency,
            [ExcelArgument(Description = "Notional, negative for loan")] double Notional,
            [ExcelArgument(Description = "Discount Curve")] string DiscountCurve)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                ContainerStores.SessionContainer.GetService <ICalendarProvider>().Collection.TryGetCalendar(Currency, out var cal);
                var ccy = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>()[Currency];

                if (!Enum.TryParse(Basis, out DayCountBasis basis))
                {
                    return $"Could not parse daycount basis - {Basis}";
                }

                var product = new FixedRateLoanDeposit(StartDate, EndDate, FixedRate, ccy, basis, Notional, DiscountCurve)
                {
                    TradeId = ObjectName
                };

                return ExcelHelper.PushToCache(product, ObjectName);
            }));
        }
Ejemplo n.º 2
0
        public void PastStartingFixedRateLoanDepo()
        {
            var bd         = DateTime.Today;
            var pillars    = new[] { bd, bd.AddDays(1000) };
            var flatRate   = 0.05;
            var rates      = pillars.Select(p => flatRate).ToArray();
            var usd        = TestProviderHelper.CurrencyProvider["USD"];
            var discoCurve = new IrCurve(pillars, rates, bd, "USD.BLAH", Interpolator1DType.Linear, usd);
            var fModel     = new FundingModel(bd, new[] { discoCurve }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider);

            var start    = bd.AddDays(-10);
            var maturity = bd.AddDays(365);
            var notional = 100e6;
            var iRate    = 0.07;

            var depo = new FixedRateLoanDeposit(start, maturity, iRate, usd, DayCountBasis.ACT360, notional, "USD.BLAH");

            var pv = depo.Pv(fModel, false);

            var dfEnd      = discoCurve.GetDf(bd, maturity);
            var t          = start.CalculateYearFraction(maturity, DayCountBasis.ACT360);
            var expectedPv = 0.0;                          //initial notional is in the past

            expectedPv += -notional * dfEnd;               //final notional
            expectedPv += -notional * (iRate * t) * dfEnd; //final notional
            Assert.Equal(expectedPv, pv, 8);


            var loan = new FixedRateLoanDeposit(start, maturity, iRate, usd, DayCountBasis.ACT360, -notional, "USD.BLAH");

            pv = loan.Pv(fModel, false);

            expectedPv  = 0.0;                            //initial notional is in the past
            expectedPv += notional * dfEnd;               //final notional
            expectedPv += notional * (iRate * t) * dfEnd; //final notional
            Assert.Equal(expectedPv, pv, 8);
        }
Ejemplo n.º 3
0
        public void FixedRateLoanDepo()
        {
            var bd         = DateTime.Today;
            var pillars    = new[] { bd, bd.AddDays(1000) };
            var flatRate   = 0.05;
            var rates      = pillars.Select(p => flatRate).ToArray();
            var usd        = TestProviderHelper.CurrencyProvider["USD"];
            var discoCurve = new IrCurve(pillars, rates, bd, "USD.BLAH", Interpolator1DType.Linear, usd);
            var fModel     = new FundingModel(bd, new[] { discoCurve }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider);

            var maturity = bd.AddDays(365);
            var notional = 100e6;
            var iRate    = 0.07;
            var depo     = new FixedRateLoanDeposit(bd, maturity, iRate, usd, DayCountBasis.ACT360, notional, "USD.BLAH");

            var pv = depo.Pv(fModel, false);

            var dfEnd      = discoCurve.GetDf(bd, maturity);
            var t          = bd.CalculateYearFraction(maturity, DayCountBasis.ACT360);
            var expectedPv = notional;                     //initial notional

            expectedPv += -notional * dfEnd;               //final notional
            expectedPv += -notional * (iRate * t) * dfEnd; //final notional
            Assert.Equal(expectedPv, pv, 8);
            Assert.Equal(maturity, depo.LastSensitivityDate);
            Assert.Empty(depo.AssetIds);
            Assert.Equal(usd, depo.PaymentCurrency);
            Assert.Equal(0.0, depo.CalculateParRate(fModel));

            Assert.Equal(notional, depo.FlowsT0(fModel));
            var fm2 = fModel.DeepClone(maturity);

            Assert.Equal(-notional * (1 + (iRate * t)), depo.FlowsT0(fm2));
            fm2 = fModel.DeepClone(maturity.AddDays(1));
            Assert.Equal(0.0, depo.FlowsT0(fm2));

            var flows = depo.ExpectedCashFlows(new AssetFxModel(bd, fModel));

            Assert.Equal(3, flows.Count);

            var loan = new FixedRateLoanDeposit(bd, maturity, iRate, usd, DayCountBasis.ACT360, -notional, "USD.BLAH");

            pv = loan.Pv(fModel, false);

            expectedPv  = -notional;                      //initial notional
            expectedPv += notional * dfEnd;               //final notional
            expectedPv += notional * (iRate * t) * dfEnd; //final notional
            Assert.Equal(expectedPv, pv, 8);

            Assert.Throws <NotImplementedException>(() => depo.Sensitivities(fModel));
            Assert.Throws <NotImplementedException>(() => depo.SetStrike(0.0));

            Assert.Equal("USD.BLAH", depo.Dependencies(fModel.FxMatrix)[0]);
            Assert.Empty(depo.PastFixingDates(maturity));
            Assert.Equal(FxConversionType.None, depo.FxType(null));
            Assert.Equal(string.Empty, depo.FxPair(null));


            var depo2 = depo.Clone();

            Assert.True(depo.Equals(depo2));
            Assert.False(depo.Equals(loan));
            var depo3 = depo.SetParRate(0.333);

            Assert.False(depo.Equals(depo3));
        }