Example #1
0
 public SwapSchedule(DateTime asOf, DateTime startDate, DateTime endDate, DayCount dayCount, DayRule dayRule, CurveTenor frequency, StubPlacement stub = StubPlacement.NullStub)
     : base(asOf, startDate, endDate, dayCount, dayRule)
 {
     this.Frequency = frequency;
     this.Stub      = stub;
     GenerateSchedule(asOf, startDate, endDate, dayCount, dayRule, frequency, stub);
 }
Example #2
0
        public Fra(DateTime asOf, string startTenor, string endTenor, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign)
        {
            DateTime startDate = DateHandling.AddTenorAdjust(asOf, startTenor, dayRule);
            DateTime endDate   = DateHandling.AddTenorAdjust(startDate, endTenor, dayRule);

            Initialize(asOf, startDate, endDate, referenceIndex, dayCount, dayRule, fixedRate, notional, tradeSign);
        }
        public static object[,] FwdCurve_GetFromCollection(string collectionName, CurveTenor tenor)
        {
            ObjectMap.CheckExists(ObjectMap.FwdCurveCollections, collectionName, "Fwd curve collection does not exist");
            Curve fwdCurve = ObjectMap.FwdCurveCollections[collectionName].GetCurve(tenor);

            return(ExcelUtilities.BuildObjectArrayFromCurve(fwdCurve, collectionName));
        }
Example #4
0
        private LinearRateModel ReturnModelWithReplacedFwdCurve(CurveTenor tenor, Curve newCurve)
        {
            FwdCurveContainer newCollection = FwdCurveCollection.Copy();

            newCollection.AddCurve(newCurve, tenor);
            return(new LinearRateModel(DiscCurve.Copy(), newCollection, Interpolation));
        }
Example #5
0
        public ZcbRiskOutputContainer ZcbRiskProductOutputContainer(LinearRateInstrument product, DateTime asOf)
        {
            double[] risk = ZcbRiskProductAD(product);

            ZcbRiskOutputContainer output   = new ZcbRiskOutputContainer();
            ZcbRiskOutput          discRisk = new MasterThesis.ZcbRiskOutput(asOf);

            int j = 0;

            for (int i = 0; i < DiscCurve.Dimension; i++)
            {
                discRisk.AddRiskCalculation(CurveTenor.DiscOis, DiscCurve.Dates[i], risk[j]);
                j++;
            }

            output.AddDiscRisk(discRisk);

            CurveTenor[] tenors = new CurveTenor[] { CurveTenor.Fwd1M, CurveTenor.Fwd3M, CurveTenor.Fwd6M, CurveTenor.Fwd1Y };

            foreach (CurveTenor tenor in tenors.ToList())
            {
                ZcbRiskOutput tempFwdRisk = new ZcbRiskOutput(asOf);

                for (int i = 0; i < FwdCurveCollection.GetCurve(tenor).Dimension; i++)
                {
                    DateTime curvePoint = FwdCurveCollection.GetCurve(tenor).Dates[i];
                    tempFwdRisk.AddRiskCalculation(tenor, curvePoint, risk[j]);
                    j++;
                }

                output.AddForwardRisk(tenor, tempFwdRisk);
            }

            return(output);
        }
Example #6
0
        private LinearRateModel BumpFwdCurveAndReturn(CurveTenor fwdCurve, int curvePoint, double bump = 0.0001)
        {
            Curve newCurve = FwdCurveCollection.GetCurve(fwdCurve).Copy();

            newCurve.BumpCurvePoint(curvePoint, bump);
            return(ReturnModelWithReplacedFwdCurve(fwdCurve, newCurve));
        }
Example #7
0
 public CalibrationInstrument(string identifier, LinearRateInstrument instrument, CurveTenor tenor)
 {
     Tenor      = tenor;
     Instrument = instrument;
     CurvePoint = instrument.GetCurvePoint();
     Identifier = identifier;
 }
Example #8
0
 public Curve_AD(List <DateTime> Dates, List <ADouble> Values)
 {
     this.Dates     = Dates;
     this.Values    = Values;
     this.Frequency = CurveTenor.Simple;
     this.Dimension = Values.Count;
 }
Example #9
0
        public static string LinearRate_FwdCurve_StoreFromCollection(string baseHandle, string fwdCurveCollectionHandle, string tenor)
        {
            CurveTenor tenorActual = StrToEnum.CurveTenorConvert(tenor);

            LinearRateFunctions.FwdCurve_StoreFromCollection(baseHandle, fwdCurveCollectionHandle, tenorActual);
            return(baseHandle);
        }
Example #10
0
        public void AddRiskCalculation(CurveTenor curveTenor, DateTime curvePoint, double number)
        {
            string tenor          = DateHandling.ConvertDateToTenorString(curvePoint, _asOf);
            string riskIdentifier = curveTenor.ToString() + "-" + curvePoint.ToString("dd/MM/yyyy");

            RiskLookUp[riskIdentifier]    = number;
            IdentifierToPoint[curvePoint] = riskIdentifier;
        }
Example #11
0
        // Calculate BnR forward risk on a linear rate instrument
        public double BumpAndRunFwdRisk(LinearRateInstrument product, CurveTenor fwdCurve, int curvePoint, double bump = 0.0001)
        {
            double          valueNoBump = ValueLinearRateProduct(product);
            LinearRateModel newModel    = BumpFwdCurveAndReturn(fwdCurve, curvePoint, bump);
            double          valueBump   = newModel.ValueLinearRateProduct(product);

            return((valueBump - valueNoBump) / bump * 0.0001);
        }
Example #12
0
        public SwapSchedule(DateTime asOf, string startTenor, string endTenor, DayCount dayCount, DayRule dayRule, CurveTenor frequency)
            : base(asOf, startTenor, endTenor, dayCount, dayRule)
        {
            // Constructer with tenors instead of dates.

            this.Frequency = frequency;
            GenerateSchedule(asOf, StartDate, EndDate, dayCount, dayRule, frequency);
        }
Example #13
0
        public static double LinearRate_Curve_GetFwdRate(string curveHandle, DateTime asOf, DateTime startDate, string tenorStr, string dayCountStr, string dayRuleStr, string interpolationStr)
        {
            CurveTenor   tenor         = StrToEnum.CurveTenorFromSimpleTenor(tenorStr);
            InterpMethod interpolation = StrToEnum.InterpolationConvert(interpolationStr);
            DayCount     dayCount      = StrToEnum.DayCountConvert(dayCountStr);
            DayRule      dayRule       = StrToEnum.DayRuleConvert(dayRuleStr);

            return(LinearRateFunctions.Curve_GetFwdRate(curveHandle, asOf, startDate, tenor, dayCount, dayRule, interpolation));
        }
Example #14
0
        public void ConstructFullGradient()
        {
            List <CurveTenor> tenors = new CurveTenor[] { CurveTenor.DiscOis, CurveTenor.Fwd1M, CurveTenor.Fwd3M, CurveTenor.Fwd6M, CurveTenor.Fwd1Y }.ToList();

            foreach (CurveTenor tenor in tenors)
            {
                FullGradient.AddRange(DeltaVectors[tenor]);
            }
        }
Example #15
0
        public static string LinearRate_FixedLeg_Make(string baseHandle, DateTime asOf, DateTime startDate, DateTime endDate, double fixedRate,
                                                      string frequency, string dayCount, string dayRule, double notional)
        {
            CurveTenor tenorEnum    = StrToEnum.CurveTenorConvert(frequency);
            DayCount   dayCountEnum = StrToEnum.DayCountConvert(dayCount);
            DayRule    dayRuleEnum  = StrToEnum.DayRuleConvert(dayRule);

            LinearRateFunctions.FixedLeg_Make(baseHandle, asOf, startDate, endDate, fixedRate, tenorEnum, dayCountEnum, dayRuleEnum, notional);
            return(baseHandle);
        }
Example #16
0
        public double Annuity(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor tenor, DayCount dayCount, DayRule dayRule, InterpMethod interpolation)
        {
            SwapSchedule annuitySchedule = new SwapSchedule(asOf, startDate, endDate, dayCount, dayRule, tenor);
            double       result          = 0.0;

            for (int i = 0; i < annuitySchedule.AdjEndDates.Count; i++)
            {
                result += annuitySchedule.Coverages[i] * DiscCurve.DiscFactor(asOf, annuitySchedule.AdjEndDates[i], dayCount, interpolation);
            }
            return(result);
        }
Example #17
0
 protected SwapLeg(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceTenor, DayCount dayCount, DayRule dayRule, double notional)
 {
     Schedule       = new MasterThesis.SwapSchedule(asOf, startDate, endDate, dayCount, dayRule, referenceTenor);
     this.Tenor     = referenceTenor;
     this.DayRule   = dayRule;
     this.DayCount  = dayCount;
     this.Notional  = notional;
     this.AsOf      = asOf;
     this.StartDate = startDate;
     this.EndDate   = endDate;
 }
Example #18
0
 public Futures(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign, double?convexity = null)
 {
     FraSameSpec = new Fra(asOf, startDate, endDate, referenceIndex, dayCount, dayRule, fixedRate, notional, tradeSign);
     if (convexity == null)
     {
         Convexity = CalcSimpleConvexity(asOf, startDate, endDate, dayCount);
     }
     else
     {
         Convexity = (double)convexity;
     }
 }
        public static void CalibrationInstrumentSet_Make(string baseHandle, string[] linearRateProductHandles, string curveTenor)
        {
            CurveTenor tenor = StrToEnum.CurveTenorConvert(curveTenor);
            List <CalibrationInstrument> calibrationInstruments = new List <CalibrationInstrument>();

            for (int i = 0; i < linearRateProductHandles.Length; i++)
            {
                LinearRateInstrument product = ObjectMap.LinearRateInstruments[linearRateProductHandles[i]];
                calibrationInstruments.Add(new CalibrationInstrument(linearRateProductHandles[i], product, tenor));
            }

            ObjectMap.CalibrationInstrumentSets[baseHandle] = calibrationInstruments;
        }
        public static void RiskOutput_StoreFromRiskOutputContainer(string baseHandle, string riskOutputContainerHandle, string tenor)
        {
            CurveTenor tenorEnum = StrToEnum.CurveTenorConvert(tenor);

            if (tenorEnum == CurveTenor.DiscOis)
            {
                ObjectMap.ZcbRiskOutputs[baseHandle] = ObjectMap.ZcbRiskOutputContainers[riskOutputContainerHandle].DiscRisk;
            }
            else
            {
                ObjectMap.ZcbRiskOutputs[baseHandle] = ObjectMap.ZcbRiskOutputContainers[riskOutputContainerHandle].FwdRiskCollection[tenorEnum];
            }
        }
Example #21
0
        public static string Calibration_FwdCurveCalibrationProblem_Make(string baseHandle, string discCurveHandle, object[] curveCalibHandles, object[] fwdCurveTenors, string calibSpecHandle)
        {
            string[]     problemNamesString = curveCalibHandles.Cast <string>().ToArray();
            string[]     tenorsString       = fwdCurveTenors.Cast <string>().ToArray();
            CurveTenor[] tenorsActual       = new CurveTenor[tenorsString.Length];

            for (int i = 0; i < tenorsString.Length; i++)
            {
                tenorsActual[i] = StrToEnum.CurveTenorConvert(tenorsString[i]);
            }

            CalibrationFunctions.FwdCurveCalibrationProblem_Make(baseHandle, discCurveHandle, problemNamesString, tenorsActual, calibSpecHandle);
            return(baseHandle);
        }
Example #22
0
        public static string LinearRate_FwdCurveCollection_Make(string baseHandle, object[] fwdCurveHandles, object[] tenorNames)
        {
            CurveTenor[] tenorEnums          = new CurveTenor[tenorNames.Length];
            var          fwdCurveNamesString = fwdCurveHandles.Cast <string>().ToArray();

            for (int i = 0; i < tenorEnums.Length; i++)
            {
                tenorEnums[i] = StrToEnum.CurveTenorConvert((string)tenorNames[i]);
            }

            string output = LinearRateFunctions.FwdCurveCollection_Make(baseHandle, fwdCurveNamesString, tenorEnums);

            return(output);
        }
Example #23
0
        public Futures(DateTime asOf, string startTenor, string endTenor, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign, double?convexity = null)
        {
            DateTime startDate = DateHandling.AddTenorAdjust(asOf, startTenor, dayRule);
            DateTime endDate   = DateHandling.AddTenorAdjust(startDate, endTenor, dayRule);

            FraSameSpec = new Fra(asOf, startDate, endDate, referenceIndex, dayCount, dayRule, fixedRate, notional, tradeSign);
            if (convexity == null)
            {
                Convexity = CalcSimpleConvexity(asOf, startDate, endDate, dayCount);
            }
            else
            {
                Convexity = (double)convexity;
            }
        }
Example #24
0
        public FwdCurveRepresentation(Curve curve, CurveTenor tenor, DateTime asOf, DayCount dayCount, DayRule dayRule, InterpMethod interpolation)
        {
            Dates      = curve.Dates;
            _zcbValues = curve.Values;
            Dimension  = curve.Dimension;
            Tenor      = tenor;
            AsOf       = asOf;

            _fwdDayCount   = dayCount;
            _fwdDayRule    = dayRule;
            _interpolation = interpolation;

            ConstructZcbCurveFromDatesAndValues();
            ConstructFwdRates();
        }
Example #25
0
        public IrSwap(DateTime asOf, DateTime startDate, DateTime endDate, double fixedRate,
                      CurveTenor fixedFreq, CurveTenor floatFreq, DayCount fixedDayCount, DayCount floatDayCount,
                      DayRule fixedDayRule, DayRule floatDayRule, double notional, int tradeSign, double spread = 0.0)
        {
            FloatLeg = new FloatLeg(asOf, startDate, endDate, floatFreq, floatDayCount, floatDayRule, notional, spread);
            FixedLeg = new FixedLeg(asOf, startDate, endDate, fixedRate, fixedFreq, fixedDayCount, fixedDayRule, notional);

            if (tradeSign == 1 || tradeSign == -1)
            {
                TradeSign = tradeSign;
            }
            else
            {
                throw new InvalidOperationException("TradeSign has to be 1 (pay fixed) or -1 (pay float)");
            }
        }
Example #26
0
        public ZcbRiskOutputContainer RiskAgainstAllCurvesBumpAndRun(LinearRateInstrument product, DateTime asOf)
        {
            ZcbRiskOutputContainer output = new ZcbRiskOutputContainer();

            List <CurveTenor> tenors = new CurveTenor[] { CurveTenor.Fwd1M, CurveTenor.Fwd3M, CurveTenor.Fwd6M, CurveTenor.Fwd1Y }.ToList();

            foreach (CurveTenor tenor in tenors)
            {
                if (FwdCurveCollection.CurveExist(tenor) == false)
                {
                    throw new InvalidOperationException(tenor.ToString() + " does not exist in model.");
                }

                output.AddForwardRisk(tenor, CalculateZcbRiskBumpAndRun(product, tenor, asOf));
            }

            output.AddDiscRisk(CalculateZcbRiskBumpAndRun(product, CurveTenor.DiscOis, asOf));
            return(output);
        }
Example #27
0
        public FwdCurveRepresentation(Curve_AD curve, CurveTenor tenor, DateTime asOf, DayCount dayCount, DayRule dayRule, InterpMethod interpolation)
        {
            Dates     = curve.Dates;
            Dimension = curve.Dimension;
            Tenor     = tenor;
            AsOf      = asOf;

            _fwdDayCount   = dayCount;
            _fwdDayRule    = dayRule;
            _interpolation = interpolation;

            for (int i = 0; i < Dimension; i++)
            {
                Values.Add(curve.Values[i].Value);
            }

            ConstructZcbCurveFromDatesAndValues();
            ConstructFwdRates();
        }
Example #28
0
 private void Initialize(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign)
 {
     this.StartDate      = startDate;
     this.EndDate        = endDate;
     this.DayCount       = dayCount;
     this.DayRule        = dayRule;
     this.FixedRate      = fixedRate;
     this.ReferenceIndex = referenceIndex;
     this.AsOf           = asOf;
     this.Notional       = notional;
     if (tradeSign == 1 || tradeSign == -1)
     {
         TradeSign = tradeSign;
     }
     else
     {
         throw new InvalidOperationException("TradeSign of FRA has to be 1 or -1 (1 = pay fixed)");
     }
 }
Example #29
0
        private int CalculatePeriods(DateTime startDate, DateTime endDate, CurveTenor tenor)
        {
            int number;

            switch (tenor)
            {
            case CurveTenor.Fwd1M:
                number = 1;
                break;

            case CurveTenor.Fwd3M:
                number = 3;
                break;

            case CurveTenor.Fwd6M:
                number = 6;
                break;

            case CurveTenor.Fwd1Y:
                number = 12;
                break;

            default:
                throw new InvalidOperationException("Wrong tenor in CalculatePeriods.");
            }

            int Years = endDate.Year - startDate.Year;
            int Month = endDate.Month - startDate.Month;

            int periodsInMonths = 0;

            if (Month < 0)
            {
                periodsInMonths = (Years - 1) * 12 + (12 + Month);
            }
            else
            {
                periodsInMonths = Years * 12 + Month;
            }

            return(periodsInMonths / number);
        }
Example #30
0
        public static bool IsFwdTenor(CurveTenor tenor)
        {
            switch (tenor)
            {
            case CurveTenor.Fwd1M:
                return(true);

            case CurveTenor.Fwd3M:
                return(true);

            case CurveTenor.Fwd6M:
                return(true);

            case CurveTenor.Fwd1Y:
                return(true);

            default:
                return(false);
            }
        }