Example #1
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 #2
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 #3
0
        // This method aggregates the risk on all the portfolios elements and outputs them in a riskOutputContainer.
        public ZcbRiskOutputContainer AggregateRisk(DateTime asOf)
        {
            if (_productCounter == 0)
            {
                throw new InvalidOperationException("Portfolio is empty");
            }

            if (RiskOutputs.Keys.Count == 0)
            {
                throw new InvalidOperationException("Risk has not been calculated on this portfolio");
            }

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

            // Loop over all forward curves
            foreach (CurveTenor tenor in tenors)
            {
                ZcbRiskOutput tempRiskOutput = new ZcbRiskOutput(asOf);

                // Loop over all assets
                foreach (int ident in RiskOutputs.Keys)
                {
                    if (ident == 0)
                    {
                        // Loop over all curve points and set starting valus as asset 0
                        foreach (DateTime key in RiskOutputs[0].FwdRiskCollection[tenor].IdentifierToPoint.Keys)
                        {
                            double value = RiskOutputs[0].FwdRiskCollection[tenor].RiskLookUp[RiskOutputs[0].FwdRiskCollection[tenor].IdentifierToPoint[key]];
                            tempRiskOutput.AddRiskCalculation(tenor, key, value);
                        }
                    }
                    else
                    {
                        // Loop over all curve points and add value to each curve point
                        foreach (DateTime key in RiskOutputs[0].FwdRiskCollection[tenor].IdentifierToPoint.Keys)
                        {
                            double value = RiskOutputs[ident].FwdRiskCollection[tenor].RiskLookUp[RiskOutputs[ident].FwdRiskCollection[tenor].IdentifierToPoint[key]];
                            tempRiskOutput.AddToCurvePoint(key, value);
                        }
                    }

                    // Add aggregated risk to output risk
                    output.AddForwardRisk(tenor, tempRiskOutput);
                }
            }

            // Do the same for the disc curve
            ZcbRiskOutput tempDiscRiskOutput = new ZcbRiskOutput(asOf);

            foreach (int ident in RiskOutputs.Keys)
            {
                if (ident == 0)
                {
                    // Loop over all curve points and set starting valus as asset 0
                    foreach (DateTime key in RiskOutputs[0].DiscRisk.IdentifierToPoint.Keys)
                    {
                        double value = RiskOutputs[0].DiscRisk.RiskLookUp[RiskOutputs[0].DiscRisk.IdentifierToPoint[key]];
                        tempDiscRiskOutput.AddRiskCalculation(CurveTenor.DiscOis, key, value);
                    }
                }
                else
                {
                    // Loop over all curve points and add value to each curve point
                    foreach (DateTime key in RiskOutputs[0].DiscRisk.IdentifierToPoint.Keys)
                    {
                        double value = RiskOutputs[ident].DiscRisk.RiskLookUp[RiskOutputs[ident].DiscRisk.IdentifierToPoint[key]];
                        tempDiscRiskOutput.AddToCurvePoint(key, value);
                    }
                }
            }

            output.AddDiscRisk(tempDiscRiskOutput);
            return(output);
        }