예제 #1
0
        public static void Main(string[] arg)
        {
            int nbRrpWarm = 2;
            int nbRunPerf = 2;

            /* Load the curve configurations from csv files */
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> configs = RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE, NODES_RESOURCE);

            /* Construct a swaps */
            ResolvedSwapTrade[] swaps = new ResolvedSwapTrade[NB_COUPONS * NB_TENORS];
            for (int loopswap = 0; loopswap < NB_COUPONS; loopswap++)
            {
                for (int looptenor = 0; looptenor < NB_TENORS; looptenor++)
                {
                    double coupon = SWAP_COUPON + loopswap * SWAP_COUPON_RANGE / NB_COUPONS;
                    swaps[looptenor * NB_COUPONS + loopswap] = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(Period.ofYears(TENOR_START + looptenor)), BuySell.BUY, SWAP_NOTIONAL, coupon, REF_DATA).resolve(REF_DATA);
                }
            }

            /* Warm-up */
            Pair <MultiCurrencyAmount[], CurrencyParameterSensitivities[]> r = Pair.of(new MultiCurrencyAmount[0], new CurrencyParameterSensitivities[0]);

            for (int i = 0; i < nbRrpWarm; i++)
            {
                r = computation(configs, swaps);
            }

            long start, end;

            start = DateTimeHelper.CurrentUnixTimeMillis();
            for (int i = 0; i < nbRunPerf; i++)
            {
                r = computation(configs, swaps);
            }

            end = DateTimeHelper.CurrentUnixTimeMillis();
            Console.WriteLine("Computation time: " + (end - start) + " ms");

            Console.WriteLine("Performance estimate for curve calibration, " + (NB_COUPONS * NB_TENORS) + " trades and " + nbRunPerf + " repetitions.\n" + Arrays.ToString(r.First) + Arrays.ToString(r.Second));
        }
        private const double BP1 = 1.0E-4;   // Scaling by 1 bp.

        public static void Main(string[] arg)
        {
            /* Load the curve configurations from csv files */
            IList <IDictionary <CurveGroupName, RatesCurveGroupDefinition> > configs = new List <IDictionary <CurveGroupName, RatesCurveGroupDefinition> >();

            for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++)
            {
                configs.Add(RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE[loopconfig], NODES_RESOURCE));
            }

            /* Construct a swap */
            ResolvedSwapTrade swap = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(SWAP_TENOR), BuySell.BUY, SWAP_NOTIONAL, SWAP_COUPON, REF_DATA).resolve(REF_DATA);

            /* Calibrate curves */
            ImmutableRatesProvider[] multicurve = new ImmutableRatesProvider[3];
            for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++)
            {
                multicurve[loopconfig] = CALIBRATOR.calibrate(configs[loopconfig][CONFIG_NAME], MARKET_QUOTES, REF_DATA);
            }

            /* Computes PV and bucketed PV01 */
            MultiCurrencyAmount[]            pv  = new MultiCurrencyAmount[NB_SETTINGS];
            CurrencyParameterSensitivities[] mqs = new CurrencyParameterSensitivities[NB_SETTINGS];
            for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++)
            {
                pv[loopconfig] = PRICER_SWAP.presentValue(swap, multicurve[loopconfig]);
                PointSensitivities             pts = PRICER_SWAP.presentValueSensitivity(swap, multicurve[loopconfig]);
                CurrencyParameterSensitivities ps  = multicurve[loopconfig].parameterSensitivity(pts);
                mqs[loopconfig] = MQC.sensitivity(ps, multicurve[loopconfig]);
            }

            /* Export to csv files. */
            for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++)
            {
                ExportUtils.export(mqs[loopconfig], BP1, PATH_RESULTS + CONFIG_STR + SETTINGS_SUFFIX[loopconfig] + "-mqs" + SUFFIX_CSV);
                ExportUtils.export(pv[loopconfig], PATH_RESULTS + CONFIG_STR + SETTINGS_SUFFIX[loopconfig] + "-pv" + SUFFIX_CSV);
            }

            Console.WriteLine("Calibration and export finished: " + CONFIG_STR);
        }
        private const double BP1 = 1.0E-4;   // Scaling by 1 bp.

        public static void Main(string[] arg)
        {
            /* Load the curve configurations from csv files */
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> configs = RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE, NODES_RESOURCE);

            /* Calibrate curves */
            ImmutableRatesProvider multicurve = CALIBRATOR.calibrate(configs[CONFIG_NAME], MARKET_QUOTES, REF_DATA);

            /* Construct a swap */
            ResolvedSwapTrade swap = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(SWAP_TENOR), BuySell.BUY, SWAP_NOTIONAL, SWAP_COUPON, REF_DATA).resolve(REF_DATA);

            /* Computes PV and bucketed PV01 */
            MultiCurrencyAmount            pv  = PRICER_SWAP.presentValue(swap, multicurve);
            PointSensitivities             pts = PRICER_SWAP.presentValueSensitivity(swap, multicurve);
            CurrencyParameterSensitivities ps  = multicurve.parameterSensitivity(pts);
            CurrencyParameterSensitivities mqs = MQC.sensitivity(ps, multicurve);

            /* Export to csv files. */
            ExportUtils.export(mqs, BP1, PATH_RESULTS + CONFIG_STR + "-delta" + SUFFIX_CSV);
            ExportUtils.export(pv, PATH_RESULTS + CONFIG_STR + "-pv" + SUFFIX_CSV);

            Console.WriteLine("Calibration and export finished: " + CONFIG_STR);
        }