コード例 #1
0
        public CurveCalibrationProblem(InstrumentFactory instrumentFactory, List <InstrumentQuote> instruments)
        {
            this.Factory = instrumentFactory;
            instruments.Sort(new Comparison <InstrumentQuote>((x, y) => DateTime.Compare(x.CurvePoint, y.CurvePoint)));
            InputInstruments = instruments;
            List <double> tempValues = new List <double>();

            for (int i = 0; i < InputInstruments.Count; i++)
            {
                CurvePoints.Add(InputInstruments[i].CurvePoint);
                tempValues.Add(1.0);
            }

            CurveToBeCalibrated = new MasterThesis.Curve(CurvePoints, tempValues);
        }
コード例 #2
0
 public ADouble ValueInstrumentAD(LinearRateModel model, InstrumentFactory factory)
 {
     return(factory.ValueInstrumentFromFactoryAD(model, _identifier));
 }
コード例 #3
0
        public static object[,] MakeExcelOutput(InstrumentFactory factory, string identifier)
        {
            Schedule  schedule1             = null;
            Schedule  schedule2             = null;
            QuoteType quoteType             = factory.InstrumentTypeMap[identifier];
            bool      instrumentHasSchedule = false;

            switch (quoteType)
            {
            case QuoteType.ParSwapRate:
                schedule1             = factory.IrSwaps[identifier].FloatLeg.Schedule;
                schedule2             = factory.IrSwaps[identifier].FixedLeg.Schedule;
                instrumentHasSchedule = true;
                break;

            case QuoteType.ParBasisSpread:
                schedule1             = factory.BasisSwaps[identifier].FloatLegNoSpread.Schedule;
                schedule2             = factory.BasisSwaps[identifier].FloatLegSpread.Schedule;
                instrumentHasSchedule = true;
                break;

            case QuoteType.OisRate:
                schedule1             = factory.OisSwaps[identifier].FloatSchedule;
                schedule2             = factory.OisSwaps[identifier].FixedSchedule;
                instrumentHasSchedule = true;
                break;
            }

            if (instrumentHasSchedule)
            {
                object[,] schedule1Object = MakeScheduleArray(schedule1);
                object[,] schedule2Object = MakeScheduleArray(schedule2);
                object[,] infoArray       = MakeInstrumentInfoArray(factory, identifier);

                int length      = infoArray.GetLength(0);
                int totalLength = length + Math.Max(schedule1Object.GetLength(0), schedule2Object.GetLength(0)) + 1;

                object[,] output = new object[totalLength, 11];

                for (int i = 0; i < totalLength; i++)
                {
                    for (int j = 0; j < 11; j++)
                    {
                        output[i, j] = "";
                    }
                }

                for (int i = 0; i < length; i++)
                {
                    output[i, 0] = infoArray[i, 0];
                    output[i, 1] = infoArray[i, 1];
                }

                // Fill out first schedule
                for (int i = length; i < schedule1Object.GetLength(0) + length; i++)
                {
                    output[i, 0] = schedule1Object[i - length, 0];
                    output[i, 1] = schedule1Object[i - length, 1];
                    output[i, 2] = schedule1Object[i - length, 2];
                    output[i, 3] = schedule1Object[i - length, 3];
                    output[i, 4] = schedule1Object[i - length, 4];
                }

                // Fill out second schedule
                for (int i = length; i < schedule2Object.GetLength(0) + length; i++)
                {
                    output[i, 6]  = schedule2Object[i - length, 0];
                    output[i, 7]  = schedule2Object[i - length, 1];
                    output[i, 8]  = schedule2Object[i - length, 2];
                    output[i, 9]  = schedule2Object[i - length, 3];
                    output[i, 10] = schedule2Object[i - length, 4];
                }

                return(output);
            }
            else
            {
                return(MakeInstrumentInfoArray(factory, identifier));
            }
        }
コード例 #4
0
        public static object[,] MakeInstrumentInfoArray(InstrumentFactory factory, string identifier)
        {
            object[,] output = new object[9, 2];
            string whiteSpace = "";

            QuoteType quoteType = factory.InstrumentTypeMap[identifier];

            output[0, 0] = quoteType.ToString();
            output[0, 1] = whiteSpace;

            output[4, 0] = whiteSpace;
            output[4, 1] = whiteSpace;
            output[7, 0] = whiteSpace;
            output[7, 1] = whiteSpace;
            output[8, 0] = whiteSpace;
            output[8, 1] = whiteSpace;

            // InstrumentStrings
            output[5, 0] = InstrumentFactoryHeaders.GetHeaders[factory.InstrumentFormatTypeMap[identifier]];
            output[5, 1] = whiteSpace;
            output[6, 0] = factory.IdentifierStringMap[identifier];
            output[6, 1] = whiteSpace;

            switch (quoteType)
            {
            case QuoteType.ParSwapRate:
                output[1, 0] = factory.IrSwaps[identifier].FloatLeg.StartDate.ToString("dd/MM/yyyy");
                output[1, 1] = factory.IrSwaps[identifier].FixedLeg.StartDate.ToString("dd/MM/yyyy");
                output[2, 0] = factory.IrSwaps[identifier].FloatLeg.EndDate.ToString("dd/MM/yyyy");
                output[2, 1] = factory.IrSwaps[identifier].FixedLeg.EndDate.ToString("dd/MM/yyyy");
                output[3, 0] = factory.IrSwaps[identifier].FloatLeg.Tenor.ToString();
                output[3, 1] = factory.IrSwaps[identifier].FixedLeg.Tenor.ToString();

                break;

            case QuoteType.OisRate:
                output[1, 0] = factory.OisSwaps[identifier].StartDate.ToString("dd/MM/yyyy");
                output[1, 1] = whiteSpace;
                output[2, 0] = factory.OisSwaps[identifier].EndDate.ToString("dd/MM/yyyy");
                output[2, 1] = whiteSpace;

                //output[3, 1] = factory.OisSwaps[dentifier].
                output[3, 0] = whiteSpace;
                output[3, 1] = whiteSpace;
                output[8, 0] = "(Float schedule -- Fixed schedule)";

                break;

            case QuoteType.FraRate:
                output[1, 0] = factory.Fras[identifier].StartDate.ToString("dd/MM/yyyy");
                output[1, 1] = whiteSpace;
                output[2, 0] = factory.Fras[identifier].EndDate.ToString("dd/MM/yyyy");
                output[2, 1] = whiteSpace;
                output[3, 0] = factory.Fras[identifier].ReferenceIndex.ToString();
                output[3, 1] = whiteSpace;

                break;

            case QuoteType.ParBasisSpread:
                output[1, 0] = factory.BasisSwaps[identifier].FloatLegNoSpread.StartDate.ToString("dd/MM/yyyy");
                output[1, 1] = factory.BasisSwaps[identifier].FloatLegSpread.StartDate.ToString("dd/MM/yyyy");
                output[2, 0] = factory.BasisSwaps[identifier].FloatLegNoSpread.EndDate.ToString("dd/MM/yyyy");
                output[2, 1] = factory.BasisSwaps[identifier].FloatLegSpread.EndDate.ToString("dd/MM/yyyy");
                output[3, 0] = factory.BasisSwaps[identifier].FloatLegNoSpread.Tenor.ToString();
                output[3, 1] = factory.BasisSwaps[identifier].FloatLegSpread.Tenor.ToString();

                break;

            case QuoteType.FuturesRate:
                output[1, 0] = factory.Futures[identifier].FraSameSpec.StartDate.ToString("dd/MM/yyyy");
                output[1, 1] = whiteSpace;
                output[2, 0] = factory.Futures[identifier].FraSameSpec.EndDate.ToString("dd/MM/yyyy");
                output[2, 1] = whiteSpace;
                output[3, 0] = factory.Futures[identifier].FraSameSpec.ReferenceIndex.ToString();
                output[3, 1] = whiteSpace;
                output[8, 0] = "Convexity adjustment: " + Math.Round(factory.Futures[identifier].Convexity, 4).ToString();

                break;

            case QuoteType.Deposit:
                // do something
                break;

            default:
                throw new InvalidOperationException("QuoteType for identifier is not valid.");
            }
            return(output);
        }