/**
  * Present value (clean price) for the payer of premiums (i.e. the buyer of protection).
  *
  * @param cds  the analytic description of a CDS traded at a certain time
  * @param yieldCurve  the yield (or discount) curve
  * @param creditCurve  the credit (or survival) curve
  * @param fractionalSpread  the <b>fraction</b> spread
  * @return the PV
  */
 public double pv(
     CDS cds,
     YieldTermStructure yieldCurve,
     PiecewiseconstantHazardRate creditCurve,
     double fractionalSpread)
 {
     return(pv(cds, yieldCurve, creditCurve, fractionalSpread, CdsPriceType.CLEAN));
 }
 /**
  * This is the present value of the premium leg per unit coupon, seen at the cash-settlement date.
  * It is equal to 10,000 times the RPV01 (Risky PV01). The actual PV of the leg is this multiplied by the
  * notional and the fractional spread (i.e. coupon in basis points divided by 10,000).
  *
  * @param cds  the analytic description of a CDS traded at a certain time
  * @param yieldCurve  the yield (or discount) curve
  * @param creditCurve  the credit (or survival) curve
  * @param cleanOrDirty  the clean or dirty price
  * @return 10,000 times the RPV01 (on a notional of 1)
  * @see #annuity
  * @see #dirtyAnnuity
  */
 public double annuity(
     CDS cds,
     YieldTermStructure yieldCurve,
     PiecewiseconstantHazardRate creditCurve,
     CdsPriceType cleanOrDirty)
 {
     return(annuity(cds, yieldCurve, creditCurve, cleanOrDirty, cds.getCashSettleTime()));
 }
Example #3
0
        static void Main(string[] args)
        {
            BigInteger p = new BigInteger("6277101735386680763835789423207666416083908700390324961279", 10);
            BigInteger a = new BigInteger("-3", 10);
            BigInteger b = new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16);

            byte[]     xG = fromHexStringToByte("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012");
            BigInteger n  = new BigInteger("ffffffffffffffffffffffff99def836146bc9b1b4d22831", 16);

            CDS        DS   = new CDS(p, a, b, n, xG);
            BigInteger d    = DS.genPrivateKey(192);
            CECPoint   Q    = DS.genPublicKey(d);
            CStribog   hash = new CStribog(256);

            /*
             * byte[] H = hash.GetHash(Encoding.Default.GetBytes("Message"));
             * string sign = DS.genDS(H, d);
             *
             * byte[] H2 = hash.GetHash(Encoding.Default.GetBytes("message"));
             * string sign2 = DS.genDS(H2, d);
             */

            Console.WriteLine("Выберите файл содержащий сообщение: ");
            String path    = Console.ReadLine();
            String message = readFile(path);

            byte[] H    = hash.GetHash(Encoding.Default.GetBytes(message));
            string sign = DS.genDS(H, d);

            Console.WriteLine("Сообщение \"{0}\" имеет следующую ЭЦП: {1}", message, sign);
            Console.WriteLine("Выберите файл для сохранение ЭЦП: ");
            path = Console.ReadLine();
            writeFile(path, sign);

            Console.WriteLine("Выберите файл для верификации сообщения: ");
            path = Console.ReadLine();
            String message2 = readFile(path);

            byte[] H2 = hash.GetHash(Encoding.Default.GetBytes(message2));
            Console.WriteLine("Выберите файл содержащий цифровую подпись: ");
            path = Console.ReadLine();
            string signVer = readFile(path);
            //string sign2 = DS.genDS(H2, d);

            bool result = DS.verifDS(H2, signVer, Q);

            if (result)
            {
                System.Console.WriteLine("Верификация прошла успешно. Цифровая подпись верна.");
            }
            else
            {
                System.Console.WriteLine("Верификация не прошла! Цифровая подпись не верна.");
            }

            System.Console.ReadLine();
        }
Example #4
0
        /**
         * The sensitivity of a CDS to the recovery rate. Note this is per unit amount, so the change
         * in PV due to a one percent (say from 40% to 41%) rise is RR will be 0.01 * the returned value.
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @return the recovery rate sensitivity (on a unit notional)
         */
        public double recoveryRateSensitivity(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve)
        {
            CDS zeroRR = cds.withRecoveryRate(0);

            return(-_pricer.protectionLeg(zeroRR, yieldCurve, creditCurve));
        }
Example #5
0
        /**
         * Immediately prior to default, the CDS has some value V (to the protection buyer).
         * After default, the contract cancelled, so there is an immediate loss of -V (or a gain if V was negative).
         * The protection buyer pays the accrued interest A and receives 1-RR, so the full
         * Value on Default (VoD) is -V + (1-RR) (where the A has been absorbed as we use the clean price for V).
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @param coupon  the coupon of the CDS
         * @return the value on default or jump to default
         */
        public double valueOnDefault(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            double coupon)
        {
            double pv = _pricer.pv(cds, yieldCurve, creditCurve, coupon);

            return(-pv + cds.getLGD());
        }
        /**
         * The par spread par spread for a given yield and credit (hazard rate/survival) curve).
         *
         * @param cds analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @return the par spread
         */
        public double parSpread(CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve)
        {
            if (cds.getProtectionEnd() <= 0.0)
            { //short cut already Expired CDSs
            }

            double rpv01  = annuity(cds, yieldCurve, creditCurve, CdsPriceType.CLEAN, 0.0);
            double proLeg = protectionLeg(cds, yieldCurve, creditCurve, 0.0);

            return(proLeg / rpv01);
        }
Example #7
0
 public void DeleteCD(String id)
 {
     foreach (CompactDisc item in CDS)
     {
         if (item.Id == id)
         {
             CDS.Remove(item);
             ReleaseLock(item.Album);
             return;
         }
     }
 }
Example #8
0
        public void TestQuantoCDS()
        {
            var spot = 1.00;
            var relJumpSizeInDefault = -0.2;
            var cdsSpread            = 0.025;
            // Trades
            var anchorDate = new Date(2016, 11, 25);
            var refEntity  = new ReferenceEntity("ABC");

            Date[]   paymentDates;
            double[] accrualFractions;
            DateGenerators.CreateDatesNoHolidays(Tenor.Months(3), anchorDate, 20, out paymentDates,
                                                 out accrualFractions);
            var zarNotionals     = Vector.Ones(paymentDates.Length).Multiply(1000000.0);
            var usdNotionals     = zarNotionals.Divide(spot);
            var zarSpreads       = Vector.Ones(paymentDates.Length).Multiply(cdsSpread);
            var usdSpreads       = zarSpreads.Multiply(1 + relJumpSizeInDefault); // Adjusted for the FX jump size.
            var boughtProtection = true;

            var cdsZAR = new CDS(refEntity, Currency.ZAR, paymentDates, zarNotionals, zarSpreads, accrualFractions,
                                 boughtProtection);
            var cdsUSD = new CDS(refEntity, Currency.USD, paymentDates, zarNotionals, usdSpreads, accrualFractions,
                                 boughtProtection);

            // Model
            var curveDates       = new[] { anchorDate, anchorDate.AddTenor(Tenor.Years(10)) };
            var expectedRecovery = 0.4;
            var hazardRates      = new[] { cdsSpread / (1 - expectedRecovery), cdsSpread / (1 - expectedRecovery) };
            var usdRates         = new[] { 0.01, 0.02 };
            var zarRates         = new[] { 0.07, 0.08 };
            IDiscountingSource         usdDiscountCurve = new DatesAndRates(Currency.USD, anchorDate, curveDates, usdRates);
            IDiscountingSource         zarDiscountCurve = new DatesAndRates(Currency.ZAR, anchorDate, curveDates, zarRates);
            ISurvivalProbabilitySource abcHazardCurve   = new HazardCurve(refEntity, anchorDate, curveDates, hazardRates);
            var otherCurrency = Currency.USD;

            var fxSource             = new FXForecastCurve(otherCurrency, Currency.ZAR, spot, usdDiscountCurve, zarDiscountCurve);
            var fxVol                = 0.15;
            NumeraireSimulator model = new DeterministicCreditWithFXJump(abcHazardCurve, otherCurrency, fxSource,
                                                                         zarDiscountCurve, fxVol, relJumpSizeInDefault, expectedRecovery);

            // Valuation
            var N        = 5000;
            var coord    = new Coordinator(model, new List <Simulator>(), N);
            var zarValue = coord.Value(new Product[] { cdsZAR }, anchorDate);
            var usdValue = coord.Value(new Product[] { cdsUSD }, anchorDate);

            Assert.AreEqual(0.0, zarValue, 800.0); // about 2bp
            Assert.AreEqual(0.0, usdValue, 800.0); // about 2bp
        }
        /**
         * Compute the present value of the protection leg with a notional of 1, which is given by the integral
         * $\frac{1-R}{P(T_{v})} \int_{T_a} ^{T_b} P(t) \frac{dQ(t)}{dt} dt$ where $P(t)$ and $Q(t)$ are the discount
         * and survival curves respectively, $T_a$ and $T_b$ are the start and end of the protection respectively,
         * $T_v$ is the valuation time (all measured from $t = 0$, 'today') and $R$ is the recovery rate.
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @param valuationTime  the valuation time, if time is zero, leg is valued today,
         *  value often quoted for cash-settlement date
         * @return the value of the protection leg (on a unit notional)
         */
        public double annuity(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            CdsPriceType cleanOrDirty,
            double valuationTime)
        {
            double pv    = dirtyAnnuity(cds, yieldCurve, creditCurve);
            double valDF = Math.Exp(-yieldCurve.getRT_(valuationTime));

            if (cleanOrDirty == CdsPriceType.CLEAN)
            {
                double csTime    = cds.getCashSettleTime();
                double protStart = cds.getEffectiveProtectionStart();
                double csDF      = valuationTime == csTime ? valDF :Math.Exp(-yieldCurve.getRT_(csTime));
                double q         = protStart == 0 ? 1.0 : Math.Exp(-creditCurve.getRT_(protStart));
                double acc       = cds.getAccruedYearFraction();
                pv -= acc * csDF * q; //subtract the accrued risky discounted to today
            }

            pv /= valDF; //roll forward to valuation date
            return(pv);
        }
        /**
         * The value of the full (or dirty) annuity (or RPV01 - the premium leg per unit of coupon) today (t=0).
         * The cash flows from premium payments and accrual-on-default are risky discounted to t=0
         * The actual value of the leg is this multiplied by the notional and the fractional coupon
         * (i.e. coupon in basis points divided by 10,000).
         * <p>
         * This is valid for both spot and forward starting CDS.
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @return the full (or dirty) annuity valued today. <b>Note</b> what is usually quoted is the clean annuity
         */
        public double dirtyAnnuity(CDS cds,
                                   YieldTermStructure yt, PiecewiseconstantHazardRate hazard)
        {
            DateTime        tradedate      = cds.tradedate;
            List <DateTime> Jumps          = yt.jumpDates_;
            DateTime        settlementDate = tradedate.AddDays(0);
            double          recoveryrate   = cds.Recovery;
            DateTime        Stepindate     = tradedate.AddDays(1);
            double          coupon         = cds.PremiumRate;

            OMLib.Conventions.DayCount.Actual360 dc = new OMLib.Conventions.DayCount.Actual360();

            CdsCoupon[] cf       = cds.getCoupons();
            double      notional = cds.Notional;

            double ita      = (double)365 / 360;
            double totalNPV = 0.0;

            for (int i = 0; i < cf.Length; ++i)
            {
                totalNPV += cf[i].getYearFrac() * notional * Math.Exp(-hazard.getRT_(cf[i].getEffEnd()))
                            * Math.Exp(-yt.getRT_(cf[i].getPaymentTime()));
            }

            double start = cds.getNumPayments() == 1 ? cds.getEffectiveProtectionStart() : cds.getAccStart();

            double[] integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(start, cds.getProtectionEnd(), yt, hazard);
            double   accPV = 0.0;

            for (int i = 0; i < cf.Length; ++i)
            {
                accPV += calculateSinglePeriodAccrualOnDefault(cf[i], cds.getEffectiveProtectionStart(), integrationSchedule, yt, hazard);
            }
            totalNPV += accPV;

            return(totalNPV);
        }
 public static extern int ChangeDisplaySettings(IntPtr devMode, CDS flags);
 public static extern int ChangeDisplaySettings(ref DEVMODE devMode, CDS flags);
		private static extern int ChangeDisplaySettingsEx(
			string lpszDeviceName,
			byte[] lpDevMode,
			IntPtr hwnd,
			CDS dwflags,
			IntPtr lParam);
Example #14
0
 /// <summary>
 /// <para>The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode.</para>
 /// <para>Use this one if you are not sure</para>
 /// </summary>
 /// <param name="deviceName">
 /// <para>String that specifies the display device whose graphics mode will change. Only display device names as returned by EnumDisplayDevices are valid.</para>
 /// <para>The <paramref name="deviceName"/> parameter can be NULL. A NULL value specifies the default display device. The default device can be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag.</para>
 /// </param>
 /// <param name="devMode"><para>A pointer to a <see cref="ScreenSettingsDevMode"/> structure that describes the new graphics mode. If <paramref name="devMode"/> is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the <paramref name="devMode"/> parameter and 0 for the <paramref name="dwFlags"/> parameter is the easiest way to return to the default mode after a dynamic mode change.</para></param>
 /// <param name="dwFlags"></param>
 /// <returns></returns>
 internal static DispChange ChangeDisplaySettingsEx(string deviceName, ref ScreenSettingsDevMode devMode, CDS dwFlags)
 {
     return (DispChange)ChangeDisplaySettingsEx(deviceName, ref devMode, IntPtr.Zero, (int)dwFlags, IntPtr.Zero);
 }
Example #15
0
 public static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, CDS dwflags, IntPtr lParam);
Example #16
0
		public static extern DISP_CHANGE ChangeDisplaySettings(IntPtr lpDevMode, CDS dwflags);
Example #17
0
		public static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, ref DevMode lpDevMode, HWND hwnd, CDS dwflags, ref VideoParameters lParam);