示例#1
0
        public string SendBondData(Bond obj)
        {
            PropertyInfo[] properties = obj.GetType().GetProperties();

            if (obj == null)
                return "False";
            else
            {
                DataTable tempTable = new DataTable();
                List<string> columnList = DataAccessLayer.DAL.GetColumnNames("Bond", true);
                for (int i = 0; i < columnList.Count && columnList[i] != ""; i++)
                {
                    DataColumn dc = new DataColumn(columnList[i], typeof(string));
                    tempTable.Columns.Add(dc);
                }

                DataRow dr = tempTable.NewRow();
                foreach (PropertyInfo p in properties)
                {
                    dr[p.Name] = p.GetValue(obj, null);
                }
                tempTable.Rows.Add(dr);

                return DataAccessLayer.DAL.SendDataToDB(tempTable, "Bond").ToString();
            }
        }
示例#2
0
      public static bool isTradable(Bond bond, Date settlementDate = null)
      {
         if (settlementDate == null)
            settlementDate = bond.settlementDate();

         return bond.notional(settlementDate) != 0.0;
      }
示例#3
0
      public static CashFlow previousCashFlow(Bond bond, Date refDate = null)
      {
         if (refDate == null)
            refDate = bond.settlementDate();

         return CashFlows.previousCashFlow(bond.cashflows(), false, refDate);
      }
示例#4
0
      public static Date nextCashFlowDate(Bond bond, Date refDate = null)
      {
         if (refDate == null)
            refDate = bond.settlementDate();

         return CashFlows.nextCashFlowDate(bond.cashflows(), false, refDate);
      }
示例#5
0
 static void Main(string[] args)
 {
     DependencyInversionTradeController ditc = new DependencyInversionTradeController();
     Gilt gilt = new Gilt() { value = 10 };
     Bond bond = new Bond() { value = 100 };
     ditc.TradeStock(gilt);
     ditc.TradeStock(bond);
 }
        /*! \warning Setting a pricing engine to the passed bond from
                     external code will cause the bootstrap to fail or
                     to give wrong results. It is advised to discard
                     the bond after creating the helper, so that the
                     helper has sole ownership of it.
        */
        public BondHelper(Handle<Quote> cleanPrice, Bond bond) : base(cleanPrice) {
            bond_ = bond;

            latestDate_ = bond_.maturityDate();
            initializeDates();

            IPricingEngine bondEngine = new DiscountingBondEngine(termStructureHandle_);
            bond_.setPricingEngine(bondEngine);        
        }
示例#7
0
        public static Date accrualStartDate(Bond bond, Date settlementDate = null)
        {
            if (settlementDate == null)
            settlementDate = bond.settlementDate();

             Utils.QL_REQUIRE(BondFunctions.isTradable(bond, settlementDate),
                   "non tradable at " + settlementDate +
                   " (maturity being " + bond.maturityDate() + ")");

             return CashFlows.accrualStartDate(bond.cashflows(), false, settlementDate);
        }
        public string SendBondData(Bond obj)
        {
            if (obj == null)
                return "False";
            else
            {
                DataTable tempTable = new DataTable();
                List<string> columnList = DataAccessLayer.DAL.GetColumnNames("Bond");
                for (int i = 0; i < columnList.Count && columnList[i] != ""; i++)
                {
                    DataColumn dc = new DataColumn(columnList[i], typeof(string));
                    tempTable.Columns.Add(dc);
                }
                
                tempTable.Rows.Add(new Object[] { obj.securityName, obj.securityDescription, obj.assetType,obj.investmentType,
                    obj.tradingFactor,obj.pricingFactor,obj.isin,obj.bloombergTicker,
                    obj.bloombergUniqueID,obj.cusip,obj.sedol,obj.firstCouponDate,obj.cap,obj.floor,
                    obj.couponFrequency,obj.coupon,obj.couponType,obj.spread,
                    obj.callableFlag,obj.fixToFloatFlag,obj.putableFlag,obj.issueDate,
                    obj.lastResetDate,obj.maturity,obj.callNotificationMaxDays,obj.putNotificationMaxDays,
                    obj.penultimateCouponDate,obj.resetFrequency,obj.hasPosition,obj.macaulayDuration,
                    obj.thirtyDayVolatility,obj.ninetyDayVolatility,obj.convexity,obj.thirtyDayAvgVolume,
                    obj.formPFAssetClass,obj.formPFCountry,obj.formPFCreditRating,obj.formPFCurrency,
                    obj.formPFInstrument,obj.formPFLiquidityProfile,obj.formPFMaturity,obj.formPFNAICSCode,
                    obj.formPFRegion,obj.formPFSector,obj.formPFSubAssetClass,obj.bloombergIndustryGroup,
                    obj.bloombergIndustrySubGroup,obj.bloombergIndustrySector,obj.countryOfIssuance,obj.issueCurrency,
                    obj.issuer,obj.riskCurrency,obj.putDate,obj.putPrice,
                    obj.askPrice,obj.highPrice,obj.lowPrice,obj.openPrice,
                    obj.volume,obj.bidPrice,obj.lastPrice,obj.callDate,
                    obj.callPrice });

                Console.WriteLine(tempTable.Columns.Count);

                DataAccessLayer.DAL.SendDataToDB(tempTable, "Bond");
                return "True";
            }
        }
示例#9
0
 protected void OnVisit(Bond instrument)
 {
     _result = string.Format("Bond: {0}", this.ConvertSymbol(instrument.Symbol));
 }
示例#10
0
 protected void OnVisit(Bond instrument)
 {
     _result = string.Format("Maturity: {0:d}, Price: {1:#0.000}", instrument.MaturityDate, instrument.Price);
 }
示例#11
0
        public IHttpActionResult updateBondsById(Bond c)
        {
            int changeLine = BondsDao.updateBond(c);

            return(Ok(changeLine));
        }
示例#12
0
        private List <AsyncAction> SetBondPropertiesActions()
        {
            var ans = new List <AsyncAction>();

            foreach (var bond in network.Connection.ResolveAll(network.TheBonds))
            {
                Bond b = bond;  // have to copy it otherwise it will change to the last bond before the delegates are called
                ans.Add(new DelegatedAsyncAction(bond.Connection,
                                                 Messages.SET_BOND_HASHING_ALGORITHM_ACTION_TITLE,
                                                 Messages.SET_BOND_HASHING_ALGORITHM_ACTION_START,
                                                 Messages.SET_BOND_HASHING_ALGORITHM_ACTION_END,
                                                 session => Bond.set_property(session, b.opaque_ref, "hashing_algorithm", Bond.HashingAlgoritmToString(NewHashingAlgorithm)),
                                                 true,
                                                 "bond.set_property"));
            }
            return(ans.Count == 0 ? null : ans);
        }
示例#13
0
        private static String BondOrder(int molNumber)
        {
            String order = string.Empty;

            return(Bond.OrderValueToOrder(molNumber));
        }
示例#14
0
 public static bool isTradable(Bond bond) {
   bool ret = NQuantLibcPINVOKE.BondFunctions_isTradable__SWIG_1(Bond.getCPtr(bond));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#15
0
        public void testMASWWithGenericBond()
        {
            // Testing market asset swap against par asset swap with generic bond...

             CommonVars vars = new CommonVars();

             Calendar bondCalendar = new TARGET();
             int settlementDays = 3;
             int fixingDays = 2;
             bool payFixedRate = true;
             bool parAssetSwap = true;
             bool mktAssetSwap = false;
             bool inArrears = false;

             // Fixed Underlying bond (Isin: DE0001135275 DBR 4 01/04/37)
             // maturity doesn't occur on a business day

             Date fixedBondStartDate1 = new Date(4,Month.January,2005);
             Date fixedBondMaturityDate1 = new Date(4,Month.January,2037);
             Schedule fixedBondSchedule1 = new Schedule(fixedBondStartDate1,
                                    fixedBondMaturityDate1,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg1 = new FixedRateLeg(fixedBondSchedule1)
            .withCouponRates(0.04, new ActualActual(ActualActual.Convention.ISDA))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption1 = bondCalendar.adjust(fixedBondMaturityDate1,   BusinessDayConvention.Following);
             fixedBondLeg1.Add(new SimpleCashFlow(100.0, fixedbondRedemption1));
             Bond fixedBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount, fixedBondMaturityDate1,
            fixedBondStartDate1, fixedBondLeg1);
             IPricingEngine bondEngine = new DiscountingBondEngine(vars.termStructure);
             IPricingEngine swapEngine = new DiscountingSwapEngine(vars.termStructure);
             fixedBond1.setPricingEngine(bondEngine);

             double fixedBondMktPrice1 = 89.22 ; // market price observed on 7th June 2007
             double fixedBondMktFullPrice1=fixedBondMktPrice1+fixedBond1.accruedAmount();
             AssetSwap fixedBondParAssetSwap1= new AssetSwap(payFixedRate,
                                          fixedBond1, fixedBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             fixedBondParAssetSwap1.setPricingEngine(swapEngine);
             double fixedBondParAssetSwapSpread1 = fixedBondParAssetSwap1.fairSpread();
             AssetSwap fixedBondMktAssetSwap1 = new AssetSwap(payFixedRate,
                                          fixedBond1, fixedBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          mktAssetSwap);
             fixedBondMktAssetSwap1.setPricingEngine(swapEngine);
             double fixedBondMktAssetSwapSpread1 = fixedBondMktAssetSwap1.fairSpread();

             double tolerance = 1.0e-13;
             double error1 =
            Math.Abs(fixedBondMktAssetSwapSpread1-
                     100*fixedBondParAssetSwapSpread1/fixedBondMktFullPrice1);

             if (error1>tolerance)
            Assert.Fail("wrong asset swap spreads for fixed bond:" +
                        "\n  market asset swap spread: " + fixedBondMktAssetSwapSpread1 +
                        "\n  par asset swap spread:    " + fixedBondParAssetSwapSpread1 +
                        "\n  error:                    " + error1 +
                        "\n  tolerance:                " + tolerance);

             // Fixed Underlying bond (Isin: IT0006527060 IBRD 5 02/05/19)
             // maturity occurs on a business day

             Date fixedBondStartDate2 = new Date(5,Month.February,2005);
             Date fixedBondMaturityDate2 = new Date(5,Month.February,2019);
             Schedule fixedBondSchedule2 = new Schedule(fixedBondStartDate2,
                                    fixedBondMaturityDate2,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg2 = new FixedRateLeg(fixedBondSchedule2)
            .withCouponRates(0.05, new Thirty360(Thirty360.Thirty360Convention.BondBasis))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption2 = bondCalendar.adjust(fixedBondMaturityDate2,  BusinessDayConvention.Following);
             fixedBondLeg2.Add(new SimpleCashFlow(100.0, fixedbondRedemption2));
             Bond fixedBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount, fixedBondMaturityDate2, fixedBondStartDate2,
            fixedBondLeg2);
             fixedBond2.setPricingEngine(bondEngine);

             double fixedBondMktPrice2 = 99.98 ; // market price observed on 7th June 2007
             double fixedBondMktFullPrice2=fixedBondMktPrice2+fixedBond2.accruedAmount();
             AssetSwap fixedBondParAssetSwap2= new AssetSwap(payFixedRate,
                                          fixedBond2, fixedBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             fixedBondParAssetSwap2.setPricingEngine(swapEngine);
             double fixedBondParAssetSwapSpread2 = fixedBondParAssetSwap2.fairSpread();
             AssetSwap fixedBondMktAssetSwap2= new AssetSwap(payFixedRate,
                                          fixedBond2, fixedBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          mktAssetSwap);
             fixedBondMktAssetSwap2.setPricingEngine(swapEngine);
             double fixedBondMktAssetSwapSpread2 = fixedBondMktAssetSwap2.fairSpread();
             double error2 = Math.Abs(fixedBondMktAssetSwapSpread2-
                     100*fixedBondParAssetSwapSpread2/fixedBondMktFullPrice2);

             if (error2>tolerance)
            Assert.Fail("wrong asset swap spreads for fixed bond:" +
                        "\n  market asset swap spread: " + fixedBondMktAssetSwapSpread2 +
                        "\n  par asset swap spread:    " + fixedBondParAssetSwapSpread2 +
                        "\n  error:                    " + error2 +
                        "\n  tolerance:                " + tolerance);

             // FRN Underlying bond (Isin: IT0003543847 ISPIM 0 09/29/13)
             // maturity doesn't occur on a business day

             Date floatingBondStartDate1 = new Date(29,Month.September,2003);
             Date floatingBondMaturityDate1 = new Date(29,Month.September,2013);
             Schedule floatingBondSchedule1= new Schedule(floatingBondStartDate1,
                                       floatingBondMaturityDate1,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg1 = new IborLeg(floatingBondSchedule1, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0056)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption1 =
            bondCalendar.adjust(floatingBondMaturityDate1, BusinessDayConvention.Following);
             floatingBondLeg1.Add(new SimpleCashFlow(100.0, floatingbondRedemption1));
             Bond floatingBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,  floatingBondMaturityDate1,
            floatingBondStartDate1, floatingBondLeg1);
             floatingBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond1.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(27,Month.March,2007), 0.0402);
             // market price observed on 7th June 2007
             double floatingBondMktPrice1 = 101.64 ;
             double floatingBondMktFullPrice1 =
            floatingBondMktPrice1+floatingBond1.accruedAmount();
             AssetSwap floatingBondParAssetSwap1 = new AssetSwap(payFixedRate,
                                             floatingBond1, floatingBondMktPrice1,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             floatingBondParAssetSwap1.setPricingEngine(swapEngine);
             double floatingBondParAssetSwapSpread1 =
            floatingBondParAssetSwap1.fairSpread();
             AssetSwap floatingBondMktAssetSwap1 = new AssetSwap(payFixedRate,
                                             floatingBond1, floatingBondMktPrice1,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             mktAssetSwap);
             floatingBondMktAssetSwap1.setPricingEngine(swapEngine);
             double floatingBondMktAssetSwapSpread1 =
            floatingBondMktAssetSwap1.fairSpread();
             double error3 = Math.Abs(floatingBondMktAssetSwapSpread1-
                     100*floatingBondParAssetSwapSpread1/floatingBondMktFullPrice1);

             if (error3>tolerance)
            Assert.Fail("wrong asset swap spreads for floating bond:" +
                        "\n  market asset swap spread: " + floatingBondMktAssetSwapSpread1 +
                        "\n  par asset swap spread:    " + floatingBondParAssetSwapSpread1 +
                        "\n  error:                    " + error3 +
                        "\n  tolerance:                " + tolerance);

             // FRN Underlying bond (Isin: XS0090566539 COE 0 09/24/18)
             // maturity occurs on a business day

             Date floatingBondStartDate2 = new Date(24,Month.September,2004);
             Date floatingBondMaturityDate2 = new Date(24,Month.September,2018);
             Schedule floatingBondSchedule2 = new Schedule(floatingBondStartDate2,
                                       floatingBondMaturityDate2,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg2 = new IborLeg(floatingBondSchedule2, vars.iborIndex)
            .withFixingDays(fixingDays)
            .withSpreads(0.0025)
            .inArrears(inArrears)
            .withPaymentDayCounter(new Actual360())
            .withPaymentAdjustment(BusinessDayConvention.ModifiedFollowing)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption2 =
            bondCalendar.adjust(floatingBondMaturityDate2, BusinessDayConvention.ModifiedFollowing);
             floatingBondLeg2.Add(new
            SimpleCashFlow(100.0, floatingbondRedemption2));
             Bond floatingBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount, floatingBondMaturityDate2,
            floatingBondStartDate2, floatingBondLeg2);
             floatingBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond2.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(22,Month.March,2007), 0.04013);
             // market price observed on 7th June 2007
             double floatingBondMktPrice2 = 101.248 ;
             double floatingBondMktFullPrice2 =
            floatingBondMktPrice2+floatingBond2.accruedAmount();
             AssetSwap floatingBondParAssetSwap2 = new AssetSwap(payFixedRate,
                                             floatingBond2, floatingBondMktPrice2,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             floatingBondParAssetSwap2.setPricingEngine(swapEngine);
             double floatingBondParAssetSwapSpread2 = floatingBondParAssetSwap2.fairSpread();
             AssetSwap floatingBondMktAssetSwap2 = new AssetSwap(payFixedRate,
                                             floatingBond2, floatingBondMktPrice2,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             mktAssetSwap);
             floatingBondMktAssetSwap2.setPricingEngine(swapEngine);
             double floatingBondMktAssetSwapSpread2 =
            floatingBondMktAssetSwap2.fairSpread();
             double error4 = Math.Abs(floatingBondMktAssetSwapSpread2-
                     100*floatingBondParAssetSwapSpread2/floatingBondMktFullPrice2);

             if (error4>tolerance)
            Assert.Fail("wrong asset swap spreads for floating bond:" +
                        "\n  market asset swap spread: " + floatingBondMktAssetSwapSpread2 +
                        "\n  par asset swap spread:    " + floatingBondParAssetSwapSpread2 +
                        "\n  error:                    " + error4 +
                        "\n  tolerance:                " + tolerance);

             // CMS Underlying bond (Isin: XS0228052402 CRDIT 0 8/22/20)
             // maturity doesn't occur on a business day

             Date cmsBondStartDate1 = new Date(22,Month.August,2005);
             Date cmsBondMaturityDate1 = new Date(22,Month.August,2020);
             Schedule cmsBondSchedule1= new Schedule(cmsBondStartDate1,
                                 cmsBondMaturityDate1,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg1 = new CmsLeg(cmsBondSchedule1, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withCaps(0.055)
            .withFloors(0.025)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption1 = bondCalendar.adjust(cmsBondMaturityDate1, BusinessDayConvention.Following);
             cmsBondLeg1.Add(new SimpleCashFlow(100.0, cmsbondRedemption1));
             Bond cmsBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount, cmsBondMaturityDate1, cmsBondStartDate1,
            cmsBondLeg1);
             cmsBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond1.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(18,Month.August,2006), 0.04158);
             double cmsBondMktPrice1 = 88.45 ; // market price observed on 7th June 2007
             double cmsBondMktFullPrice1 = cmsBondMktPrice1+cmsBond1.accruedAmount();
             AssetSwap cmsBondParAssetSwap1 = new AssetSwap(payFixedRate,
                                       cmsBond1, cmsBondMktPrice1,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             cmsBondParAssetSwap1.setPricingEngine(swapEngine);
             double cmsBondParAssetSwapSpread1 = cmsBondParAssetSwap1.fairSpread();
             AssetSwap cmsBondMktAssetSwap1 = new AssetSwap(payFixedRate,
                                       cmsBond1, cmsBondMktPrice1,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       mktAssetSwap);
             cmsBondMktAssetSwap1.setPricingEngine(swapEngine);
             double cmsBondMktAssetSwapSpread1 = cmsBondMktAssetSwap1.fairSpread();
             double error5 =
            Math.Abs(cmsBondMktAssetSwapSpread1-
                     100*cmsBondParAssetSwapSpread1/cmsBondMktFullPrice1);

             if (error5>tolerance)
            Assert.Fail("wrong asset swap spreads for cms bond:" +
                        "\n  market asset swap spread: " + cmsBondMktAssetSwapSpread1 +
                        "\n  par asset swap spread:    " + cmsBondParAssetSwapSpread1 +
                        "\n  error:                    " + error5 +
                        "\n  tolerance:                " + tolerance);

             // CMS Underlying bond (Isin: XS0218766664 ISPIM 0 5/6/15)
             // maturity occurs on a business day

             Date cmsBondStartDate2 = new Date(06,Month.May,2005);
             Date cmsBondMaturityDate2 = new Date(06,Month.May,2015);
             Schedule cmsBondSchedule2= new Schedule(cmsBondStartDate2,
                                 cmsBondMaturityDate2,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg2 = new CmsLeg(cmsBondSchedule2, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withGearings(0.84)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption2 = bondCalendar.adjust(cmsBondMaturityDate2,  BusinessDayConvention.Following);
             cmsBondLeg2.Add(new SimpleCashFlow(100.0, cmsbondRedemption2));
             Bond cmsBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,  cmsBondMaturityDate2, cmsBondStartDate2,
            cmsBondLeg2);
             cmsBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond2.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(04,Month.May,2006), 0.04217);
             double cmsBondMktPrice2 = 94.08 ; // market price observed on 7th June 2007
             double cmsBondMktFullPrice2 = cmsBondMktPrice2+cmsBond2.accruedAmount();
             AssetSwap cmsBondParAssetSwap2 = new AssetSwap(payFixedRate,
                                       cmsBond2, cmsBondMktPrice2,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             cmsBondParAssetSwap2.setPricingEngine(swapEngine);
             double cmsBondParAssetSwapSpread2 = cmsBondParAssetSwap2.fairSpread();
             AssetSwap cmsBondMktAssetSwap2 = new AssetSwap(payFixedRate,
                                       cmsBond2, cmsBondMktPrice2,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       mktAssetSwap);
             cmsBondMktAssetSwap2.setPricingEngine(swapEngine);
             double cmsBondMktAssetSwapSpread2 = cmsBondMktAssetSwap2.fairSpread();
             double error6 =
            Math.Abs(cmsBondMktAssetSwapSpread2-
                     100*cmsBondParAssetSwapSpread2/cmsBondMktFullPrice2);

             if (error6>tolerance)
            Assert.Fail("wrong asset swap spreads for cms bond:" +
                        "\n  market asset swap spread: " + cmsBondMktAssetSwapSpread2 +
                        "\n  par asset swap spread:    " + cmsBondParAssetSwapSpread2 +
                        "\n  error:                    " + error6 +
                        "\n  tolerance:                " + tolerance);

             // Zero Coupon bond (Isin: DE0004771662 IBRD 0 12/20/15)
             // maturity doesn't occur on a business day

             Date zeroCpnBondStartDate1 = new Date(19,Month.December,1985);
             Date zeroCpnBondMaturityDate1 = new Date(20,Month.December,2015);
             Date zeroCpnBondRedemption1 = bondCalendar.adjust(zeroCpnBondMaturityDate1,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg1 = new List<CashFlow>{new SimpleCashFlow(100.0, zeroCpnBondRedemption1)};
             Bond zeroCpnBond1 = new  Bond(settlementDays, bondCalendar, vars.faceAmount, zeroCpnBondMaturityDate1,
            zeroCpnBondStartDate1, zeroCpnBondLeg1);
             zeroCpnBond1.setPricingEngine(bondEngine);

             // market price observed on 12th June 2007
             double zeroCpnBondMktPrice1 = 70.436 ;
             double zeroCpnBondMktFullPrice1 =
            zeroCpnBondMktPrice1+zeroCpnBond1.accruedAmount();
             AssetSwap zeroCpnBondParAssetSwap1 = new AssetSwap(payFixedRate,zeroCpnBond1,
                                          zeroCpnBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             zeroCpnBondParAssetSwap1.setPricingEngine(swapEngine);
             double zeroCpnBondParAssetSwapSpread1 = zeroCpnBondParAssetSwap1.fairSpread();
             AssetSwap zeroCpnBondMktAssetSwap1 = new AssetSwap(payFixedRate,zeroCpnBond1,
                                          zeroCpnBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          mktAssetSwap);
             zeroCpnBondMktAssetSwap1.setPricingEngine(swapEngine);
             double zeroCpnBondMktAssetSwapSpread1 = zeroCpnBondMktAssetSwap1.fairSpread();
             double error7 =
            Math.Abs(zeroCpnBondMktAssetSwapSpread1-
                     100*zeroCpnBondParAssetSwapSpread1/zeroCpnBondMktFullPrice1);

             if (error7>tolerance)
            Assert.Fail("wrong asset swap spreads for zero cpn bond:" +
                        "\n  market asset swap spread: " + zeroCpnBondMktAssetSwapSpread1 +
                        "\n  par asset swap spread:    " + zeroCpnBondParAssetSwapSpread1 +
                        "\n  error:                    " + error7 +
                        "\n  tolerance:                " + tolerance);

             // Zero Coupon bond (Isin: IT0001200390 ISPIM 0 02/17/28)
             // maturity occurs on a business day

             Date zeroCpnBondStartDate2 = new Date(17,Month.February,1998);
             Date zeroCpnBondMaturityDate2 = new Date(17,Month.February,2028);
             Date zerocpbondRedemption2 = bondCalendar.adjust(zeroCpnBondMaturityDate2,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg2 = new List<CashFlow>{new SimpleCashFlow(100.0, zerocpbondRedemption2)};
             Bond zeroCpnBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate2, zeroCpnBondStartDate2, zeroCpnBondLeg2);
             zeroCpnBond2.setPricingEngine(bondEngine);

             // double zeroCpnBondPrice2 = zeroCpnBond2.cleanPrice();
             // market price observed on 12th June 2007
             double zeroCpnBondMktPrice2 = 35.160 ;
             double zeroCpnBondMktFullPrice2 =
            zeroCpnBondMktPrice2+zeroCpnBond2.accruedAmount();
             AssetSwap zeroCpnBondParAssetSwap2 = new AssetSwap(payFixedRate,zeroCpnBond2,
                                          zeroCpnBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             zeroCpnBondParAssetSwap2.setPricingEngine(swapEngine);
             double zeroCpnBondParAssetSwapSpread2 = zeroCpnBondParAssetSwap2.fairSpread();
             AssetSwap zeroCpnBondMktAssetSwap2 = new AssetSwap(payFixedRate,zeroCpnBond2,
                                          zeroCpnBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          mktAssetSwap);
             zeroCpnBondMktAssetSwap2.setPricingEngine(swapEngine);
             double zeroCpnBondMktAssetSwapSpread2 = zeroCpnBondMktAssetSwap2.fairSpread();
             double error8 =
            Math.Abs(zeroCpnBondMktAssetSwapSpread2-
                     100*zeroCpnBondParAssetSwapSpread2/zeroCpnBondMktFullPrice2);

             if (error8>tolerance)
            Assert.Fail("wrong asset swap spreads for zero cpn bond:" +
                        "\n  market asset swap spread: " + zeroCpnBondMktAssetSwapSpread2 +
                        "\n  par asset swap spread:    " + zeroCpnBondParAssetSwapSpread2 +
                        "\n  error:                    " + error8 +
                        "\n  tolerance:                " + tolerance);
        }
        public string Put(Bond bond)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    //Execute Reader
                    DataTable  table   = new DataTable();
                    string     command = "UpdateBonds";
                    SqlCommand cmd     = new SqlCommand(command, con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@Id", bond.ID);
                    cmd.Parameters.AddWithValue("@SecurityDescription", bond.SecurityDescription);
                    cmd.Parameters.AddWithValue("@SecurityName", bond.SecurityName);
                    cmd.Parameters.AddWithValue("@AssetType", bond.AssetType);
                    cmd.Parameters.AddWithValue("@InvestmentType", bond.InvestmentType);
                    cmd.Parameters.AddWithValue("@TradingFactor", bond.TradingFactor);
                    cmd.Parameters.AddWithValue("@PricingFactor", bond.PricingFactor);
                    cmd.Parameters.AddWithValue("@ISIN", bond.ISIN);
                    cmd.Parameters.AddWithValue("@BBGTicker", bond.BBGTicker);
                    cmd.Parameters.AddWithValue("@BBGUniqueID", bond.BBGUniqueID);
                    cmd.Parameters.AddWithValue("@CUSIP", bond.CUSIP);
                    cmd.Parameters.AddWithValue("@SEDOL", bond.SEDOL);
                    cmd.Parameters.AddWithValue("@FirstCouponDate", bond.FirstCouponDate);
                    cmd.Parameters.AddWithValue("@Cap", bond.Cap);
                    cmd.Parameters.AddWithValue("@FloorValue", bond.FloorValue);
                    cmd.Parameters.AddWithValue("@CouponFrequency", bond.CouponFrequency);
                    cmd.Parameters.AddWithValue("@Coupon", bond.Coupon);
                    cmd.Parameters.AddWithValue("@CouponType", bond.CouponType);
                    cmd.Parameters.AddWithValue("@Spread", bond.Spread);
                    cmd.Parameters.AddWithValue("@CallableFlag", bond.CallableFlag);
                    cmd.Parameters.AddWithValue("@FixtoFloatFlag", bond.FixtoFloatFlag);
                    cmd.Parameters.AddWithValue("@PutableFlag", bond.PutableFlag);
                    cmd.Parameters.AddWithValue("@IssueDate", bond.IssueDate);
                    cmd.Parameters.AddWithValue("@LastResetDate", bond.LastResetDate);
                    cmd.Parameters.AddWithValue("@Maturity", bond.Maturity);
                    cmd.Parameters.AddWithValue("@CallNotificationMaxDays", bond.CallNotificationMaxDays);
                    cmd.Parameters.AddWithValue("@PutNotificationMaxDays", bond.PutNotificationMaxDays);
                    cmd.Parameters.AddWithValue("@PenultimateCouponDate", bond.PenultimateCouponDate);
                    cmd.Parameters.AddWithValue("@ResetFrequency", bond.ResetFrequency);
                    cmd.Parameters.AddWithValue("@HasPosition", bond.HasPosition);
                    cmd.Parameters.AddWithValue("@MacaulayDuration", bond.MacaulayDuration);
                    cmd.Parameters.AddWithValue("@Volatility_30D", bond.Volatility_30D);
                    cmd.Parameters.AddWithValue("@Volatility_90D", bond.Volatility_90D);
                    cmd.Parameters.AddWithValue("@Convexity", bond.Convexity);
                    cmd.Parameters.AddWithValue("@AverageVolume_30Day", bond.AverageVolume_30Day);
                    cmd.Parameters.AddWithValue("@PFAssetClass", bond.PFAssetClass);
                    cmd.Parameters.AddWithValue("@PFCountry", bond.PFCountry);
                    cmd.Parameters.AddWithValue("@PFCreditRating", bond.PFCreditRating);
                    cmd.Parameters.AddWithValue("@PFCurrency", bond.PFCurrency);
                    cmd.Parameters.AddWithValue("@PFInstrument", bond.PFInstrument);
                    cmd.Parameters.AddWithValue("@PFLiquidityProfile", bond.PFLiquidityProfile);
                    cmd.Parameters.AddWithValue("@PFMaturity", bond.PFMaturity);
                    cmd.Parameters.AddWithValue("@PFNAICSCode", bond.PFNAICSCode);
                    cmd.Parameters.AddWithValue("@PFRegion", bond.PFRegion);
                    cmd.Parameters.AddWithValue("@PFSector", bond.PFSector);
                    cmd.Parameters.AddWithValue("@PFSubAssetClass", bond.PFSubAssetClass);
                    cmd.Parameters.AddWithValue("@BloombergIndustryGroup", bond.BloombergIndustryGroup);
                    cmd.Parameters.AddWithValue("@BloombergIndustrySubGroup", bond.BloombergIndustrySubGroup);
                    cmd.Parameters.AddWithValue("@BloombergIndustrySector", bond.BloombergIndustrySector);
                    cmd.Parameters.AddWithValue("@CountryofIssuance", bond.CountryofIssuance);
                    cmd.Parameters.AddWithValue("@IssueCurrency", bond.IssueCurrency);
                    cmd.Parameters.AddWithValue("@IssuerName", bond.IssuerName);
                    cmd.Parameters.AddWithValue("@RiskCurrency", bond.RiskCurrency);
                    cmd.Parameters.AddWithValue("@PutDate", bond.PutDate);
                    cmd.Parameters.AddWithValue("@PutPrice", bond.PutPrice);
                    cmd.Parameters.AddWithValue("@AskPrice", bond.AskPrice);
                    cmd.Parameters.AddWithValue("@HighPrice", bond.HighPrice);
                    cmd.Parameters.AddWithValue("@LowPrice", bond.LowPrice);
                    cmd.Parameters.AddWithValue("@OpenPrice", bond.OpenPrice);
                    cmd.Parameters.AddWithValue("@Volume", bond.Volume);
                    cmd.Parameters.AddWithValue("@BidPrice", bond.BidPrice);
                    cmd.Parameters.AddWithValue("@LastPrice", bond.LastPrice);
                    cmd.Parameters.AddWithValue("@CallDate", bond.CallDate);
                    cmd.Parameters.AddWithValue("@CallPrice", bond.CallPrice);

                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(table);

                    return("put success");
                }
            }
            catch (Exception)
            {
                return("could not put");
            }
        }
示例#17
0
        private void ReadBonds(StreamReader reader, int bonds)
        {
            int idx = 0;

            while (!reader.EndOfStream && idx < bonds)
            {
                string line = SdFileConverter.GetNextLine(reader); //reader.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    // create bond

                    int  atomNumber1 = ParseInteger(line, 0, 3);
                    Atom atom1       = atomByNumber[atomNumber1];

                    if (atom1 == null)
                    {
                        //throw new Exception("Cannot resolve atomNumber :" + atomNumber1 + ": in " + line);
                        _molecule.Warnings.Add($"Cannot resolve atomNumber {atomNumber1} at line {SdFileConverter.LineNumber}");
                        _molecule.Warnings.Add($"{line}");
                    }

                    int  atomNumber2 = ParseInteger(line, 3, 3);
                    Atom atom2       = atomByNumber[atomNumber2];

                    if (atom2 == null)
                    {
                        //throw new Exception("Cannot resolve atomNumber :" + atomNumber2 + ": in " + line);
                        _molecule.Warnings.Add($"Cannot resolve atomNumber {atomNumber2} at line {SdFileConverter.LineNumber}");
                        _molecule.Warnings.Add($"{line}");
                    }
                    idx++;

                    Bond thisBond = new Bond();
                    thisBond.StartAtomInternalId = atom1?.InternalId;
                    thisBond.EndAtomInternalId   = atom2?.InternalId;

                    // Bond Order
                    String order = GetSubString(line, 6, 3);
                    if (!string.IsNullOrEmpty(order))
                    {
                        int bondOrder = ParseInteger(order);
                        if (bondOrder <= 4)
                        {
                            thisBond.Order = BondOrder(bondOrder);
                        }
                        else
                        {
                            thisBond.Order = BondOrder(bondOrder);
                            _molecule.Warnings.Add($"Unsupported Bond Type of {order} at Line {SdFileConverter.LineNumber}");
                        }
                    }

                    // stereo
                    String stereo = GetSubString(line, 9, 3);
                    if (!string.IsNullOrEmpty(stereo))
                    {
                        thisBond.Stereo = BondStereoFromMolfile(ParseInteger(stereo));
                    }

                    // add bond to molecule
                    _molecule.AddBond(thisBond);
                    thisBond.Parent = _molecule;
                    bondByNumber.Add(idx, thisBond);
                }
            }
        }
 public BondHoverAdorner(UIElement adornedElement, BondVisual targetedVisual) : this(adornedElement)
 {
     _targetedVisual = targetedVisual;
     _targetedBond   = _targetedVisual.ParentBond;
 }
示例#19
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Bond obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#20
0
        public BondLayout GetBondLayout(Point startPoint, Point endPoint, double bondLength,
                                        Globals.BondStereo stereo, string order, Ring existingRing = null,
                                        Ring subsidiaryRing = null)
        {
            BondLayout descriptor = null;

            //check to see if it's a wedge or a hatch yet
            if (stereo == Globals.BondStereo.Wedge || stereo == Globals.BondStereo.Hatch)
            {
                var wbd = new WedgeBondLayout {
                    Start = startPoint, End = endPoint
                };
                BondGeometry.GetWedgeBondGeometry(wbd, bondLength, CurrentEditor.ViewModel.Standoff);
                return(wbd);
            }

            if (stereo == Globals.BondStereo.Indeterminate && (order == Globals.OrderSingle))
            {
                descriptor = new BondLayout {
                    Start = startPoint, End = endPoint
                };
                BondGeometry.GetWavyBondGeometry(descriptor, bondLength, CurrentEditor.ViewModel.Standoff);
                return(descriptor);
            }

            var ordervalue = Bond.OrderToOrderValue(order);

            //single or dotted bond
            if (ordervalue <= 1)
            {
                descriptor = new BondLayout {
                    Start = startPoint, End = endPoint
                };
                BondGeometry.GetSingleBondGeometry(descriptor, CurrentEditor.ViewModel.Standoff);
            }

            //double bond
            if (ordervalue == 2 || ordervalue == 1.5)
            {
                DoubleBondLayout dbd = new DoubleBondLayout {
                    Start = startPoint, End = endPoint
                };
                if (stereo == Globals.BondStereo.Indeterminate)
                {
                    BondGeometry.GetCrossedDoubleGeometry(dbd, bondLength, CurrentEditor.ViewModel.Standoff);
                }
                else
                {
                    dbd.PrimaryCentroid   = existingRing?.Centroid;
                    dbd.SecondaryCentroid = subsidiaryRing?.Centroid;
                    BondGeometry.GetDoubleBondGeometry(dbd, bondLength, CurrentEditor.ViewModel.Standoff);
                }

                descriptor = dbd;
            }

            //tripe bond
            if (ordervalue == 2.5 || ordervalue == 3)
            {
                var tbd = new TripleBondLayout {
                    Start = startPoint, End = endPoint
                };
                BondGeometry.GetTripleBondGeometry(tbd, bondLength, CurrentEditor.ViewModel.Standoff);
                descriptor = tbd;
            }

            return(descriptor);
        }
示例#21
0
        // @cdk.inchi InChI=1S/C13H12/c1-3-7-12(8-4-1)11-13-9-5-2-6-10-13/h1-10H,11H2
        public static IAtomContainer Benzylbenzene()
        {
            var   mol = new AtomContainer();
            IAtom a1  = new Atom("C");

            mol.Atoms.Add(a1);
            IAtom a2 = new Atom("C");

            mol.Atoms.Add(a2);
            IAtom a3 = new Atom("C");

            mol.Atoms.Add(a3);
            IAtom a4 = new Atom("C");

            mol.Atoms.Add(a4);
            IAtom a5 = new Atom("C");

            mol.Atoms.Add(a5);
            IAtom a6 = new Atom("C");

            mol.Atoms.Add(a6);
            IAtom a7 = new Atom("C");

            mol.Atoms.Add(a7);
            IAtom a8 = new Atom("C");

            mol.Atoms.Add(a8);
            IAtom a9 = new Atom("C");

            mol.Atoms.Add(a9);
            IAtom a10 = new Atom("C");

            mol.Atoms.Add(a10);
            IAtom a11 = new Atom("C");

            mol.Atoms.Add(a11);
            IAtom a12 = new Atom("C");

            mol.Atoms.Add(a12);
            IAtom a13 = new Atom("C");

            mol.Atoms.Add(a13);
            IBond b1 = new Bond(a6, a7, BondOrder.Single);

            mol.Bonds.Add(b1);
            IBond b2 = new Bond(a7, a8, BondOrder.Single);

            mol.Bonds.Add(b2);
            IBond b3 = new Bond(a6, a5, BondOrder.Single);

            mol.Bonds.Add(b3);
            IBond b4 = new Bond(a5, a4, BondOrder.Double);

            mol.Bonds.Add(b4);
            IBond b5 = new Bond(a4, a3, BondOrder.Single);

            mol.Bonds.Add(b5);
            IBond b6 = new Bond(a3, a2, BondOrder.Double);

            mol.Bonds.Add(b6);
            IBond b7 = new Bond(a6, a1, BondOrder.Double);

            mol.Bonds.Add(b7);
            IBond b8 = new Bond(a2, a1, BondOrder.Single);

            mol.Bonds.Add(b8);
            IBond b9 = new Bond(a10, a11, BondOrder.Double);

            mol.Bonds.Add(b9);
            IBond b10 = new Bond(a10, a9, BondOrder.Single);

            mol.Bonds.Add(b10);
            IBond b11 = new Bond(a9, a8, BondOrder.Double);

            mol.Bonds.Add(b11);
            IBond b12 = new Bond(a8, a13, BondOrder.Single);

            mol.Bonds.Add(b12);
            IBond b13 = new Bond(a13, a12, BondOrder.Double);

            mol.Bonds.Add(b13);
            IBond b14 = new Bond(a12, a11, BondOrder.Single);

            mol.Bonds.Add(b14);
            return(mol);
        }
示例#22
0
        private static void AddMolecule(dynamic data, Model newModel)
        {
            var     newMol = new Molecule();
            Element ce;

            // GitHub: Issue #13 https://github.com/Chem4Word/Version3/issues/13
            if (data.a != null)
            {
                foreach (AtomJSON a in data.a)
                {
                    if (!string.IsNullOrEmpty(a.l))
                    {
                        bool ok = Globals.PeriodicTable.HasElement(a.l);
                        ce = Globals.PeriodicTable.Elements[a.l];
                    }
                    else
                    {
                        ce = Globals.PeriodicTable.C;
                    }

                    Atom atom = new Atom()
                    {
                        Element  = ce,
                        Position = new Point(a.x, a.y)
                    };

                    if (a.c != null)
                    {
                        atom.FormalCharge = a.c.Value;
                    }
                    newMol.Atoms.Add(atom);
                }
            }

            if (data.b != null)
            {
                foreach (BondJSON b in data.b)
                {
                    string o;
                    if (b.o != null)
                    {
                        o = Bond.OrderValueToOrder(double.Parse(b.o.ToString()));
                    }
                    else
                    {
                        o = Bond.OrderSingle;
                    }

                    BondStereo s;
                    if (!string.IsNullOrEmpty(b.s))
                    {
                        if (o == Bond.OrderDouble)
                        {
                            if (b.s.Equals(Ambiguous))
                            {
                                s = BondStereo.Indeterminate;
                            }
                            else
                            {
                                s = BondStereo.None;
                            }
                        }
                        else
                        {
                            if (b.s.Equals(Recessed))
                            {
                                s = BondStereo.Hatch;
                            }
                            else if (b.s.Equals(Protruding))
                            {
                                s = BondStereo.Wedge;
                            }
                            else if (b.s.Equals(Ambiguous))
                            {
                                s = BondStereo.Indeterminate;
                            }
                            else
                            {
                                s = BondStereo.None;
                            }
                        }
                    }
                    else
                    {
                        s = BondStereo.None;
                    }

                    Bond newBond = new Bond()
                    {
                        StartAtom = newMol.Atoms[b.b.Value],
                        EndAtom   = newMol.Atoms[b.e.Value],
                        Stereo    = s,
                        Order     = o
                    };
                    newMol.Bonds.Add(newBond);
                }
            }
            newModel.Molecules.Add(newMol);
        }
示例#23
0
 public static double basisPointValue(Bond bond, InterestRate yield, Date settlementDate) {
   double ret = NQuantLibcPINVOKE.BondFunctions_basisPointValue__SWIG_0(Bond.getCPtr(bond), InterestRate.getCPtr(yield), Date.getCPtr(settlementDate));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#24
0
        private string GetManagementBondName()
        {
            Bond bond = NetworkingHelper.GetMasterManagementBond(Connection);

            return(bond == null ? Messages.UNKNOWN : bond.Name());
        }
示例#25
0
 public static double yieldValueBasisPoint(Bond bond, InterestRate yield) {
   double ret = NQuantLibcPINVOKE.BondFunctions_yieldValueBasisPoint__SWIG_1(Bond.getCPtr(bond), InterestRate.getCPtr(yield));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#26
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <returns></returns>
        public static Asset Parse(string instrumentId)
        {
            Asset underlyingAsset;
            var   properties = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            case AssetTypesEnum.ZeroRate:
            {
                var zeroRate = new Cash {
                    id = instrumentId
                };
                underlyingAsset = zeroRate;
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                var deposit = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = deposit;
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                var simplefra = new SimpleFra {
                    id = instrumentId, startTerm = properties.TermTenor
                };
                if (properties.ForwardIndex == null)
                {
                    throw new ArgumentException("ForwardIndex must be set in the instrumentId " + instrumentId,
                                                nameof(instrumentId));
                }
                simplefra.endTerm = simplefra.startTerm.Sum(properties.ForwardIndex);
                underlyingAsset   = simplefra;
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                var simpleIRCap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRCap;
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRFuture:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                //  var tenor = results[2];
                var equityAsset = new EquityAsset {
                    id = instrumentId
                };
                underlyingAsset = equityAsset;
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                //  var tenor = results[2];
                var fxRateAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = fxRateAsset;
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                var commodityAsset = new Commodity {
                    id = instrumentId
                };
                underlyingAsset = commodityAsset;
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                var bond = new Bond {
                    id = instrumentId
                };
                underlyingAsset = bond;
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            return(underlyingAsset);
        }
示例#27
0
 public static Date nextCashFlowDate(Bond bond) {
   Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_nextCashFlowDate__SWIG_1(Bond.getCPtr(bond)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#28
0
 public static double nextCouponRate(Bond bond) {
   double ret = NQuantLibcPINVOKE.BondFunctions_nextCouponRate__SWIG_1(Bond.getCPtr(bond));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#29
0
        public void testZSpreadWithGenericBond()
        {
            // Testing clean and dirty price with null Z-spread against theoretical prices...

             CommonVars vars = new CommonVars();

             Calendar bondCalendar = new TARGET();
             int settlementDays = 3;
             int fixingDays = 2;
             bool inArrears = false;

             // Fixed Underlying bond (Isin: DE0001135275 DBR 4 01/04/37)
             // maturity doesn't occur on a business day

             Date fixedBondStartDate1 = new Date(4,Month.January,2005);
             Date fixedBondMaturityDate1 = new Date(4,Month.January,2037);
             Schedule fixedBondSchedule1= new Schedule(fixedBondStartDate1,
                                    fixedBondMaturityDate1,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg1 = new FixedRateLeg(fixedBondSchedule1)
            .withCouponRates(0.04, new ActualActual(ActualActual.Convention.ISDA))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption1 = bondCalendar.adjust(fixedBondMaturityDate1,
                                                         BusinessDayConvention.Following);
             fixedBondLeg1.Add(new SimpleCashFlow(100.0, fixedbondRedemption1));
             Bond fixedBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount, fixedBondMaturityDate1, fixedBondStartDate1,
                  fixedBondLeg1);
             IPricingEngine bondEngine = new DiscountingBondEngine(vars.termStructure);
             fixedBond1.setPricingEngine(bondEngine);

             double fixedBondImpliedValue1 = fixedBond1.cleanPrice();
             Date fixedBondSettlementDate1= fixedBond1.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double fixedBondCleanPrice1 = BondFunctions.cleanPrice(fixedBond1, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Annual, fixedBondSettlementDate1);
             double tolerance = 1.0e-13;
             double error1 = Math.Abs(fixedBondImpliedValue1-fixedBondCleanPrice1);
             if (error1>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: "
                        + fixedBondImpliedValue1
                        + "\n  par asset swap spread: " + fixedBondCleanPrice1
                        + "\n  error:                 " + error1
                        + "\n  tolerance:             " + tolerance);
             }

             // Fixed Underlying bond (Isin: IT0006527060 IBRD 5 02/05/19)
             // maturity occurs on a business day

             Date fixedBondStartDate2 = new Date(5,Month.February,2005);
             Date fixedBondMaturityDate2 = new Date(5,Month.February,2019);
             Schedule fixedBondSchedule2= new Schedule(fixedBondStartDate2,
                                    fixedBondMaturityDate2,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg2 = new FixedRateLeg(fixedBondSchedule2)
            .withCouponRates(0.05, new Thirty360(Thirty360.Thirty360Convention.BondBasis))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption2 = bondCalendar.adjust(fixedBondMaturityDate2, BusinessDayConvention.Following);
             fixedBondLeg2.Add(new SimpleCashFlow(100.0, fixedbondRedemption2));
             Bond fixedBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  fixedBondMaturityDate2, fixedBondStartDate2, fixedBondLeg2);
             fixedBond2.setPricingEngine(bondEngine);

             double fixedBondImpliedValue2 = fixedBond2.cleanPrice();
             Date fixedBondSettlementDate2= fixedBond2.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve

             double fixedBondCleanPrice2 = BondFunctions.cleanPrice(fixedBond2, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Annual, fixedBondSettlementDate2);
             double error3 = Math.Abs(fixedBondImpliedValue2-fixedBondCleanPrice2);
             if (error3>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: "
                        + fixedBondImpliedValue2
                        + "\n  par asset swap spread: " + fixedBondCleanPrice2
                        + "\n  error:                 " + error3
                        + "\n  tolerance:             " + tolerance);
             }

             // FRN Underlying bond (Isin: IT0003543847 ISPIM 0 09/29/13)
             // maturity doesn't occur on a business day

             Date floatingBondStartDate1 = new Date(29,Month.September,2003);
             Date floatingBondMaturityDate1 = new Date(29,Month.September,2013);
             Schedule floatingBondSchedule1= new Schedule(floatingBondStartDate1,
                                       floatingBondMaturityDate1,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg1 = new IborLeg(floatingBondSchedule1, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0056)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption1 =
            bondCalendar.adjust(floatingBondMaturityDate1, BusinessDayConvention.Following);
             floatingBondLeg1.Add(new SimpleCashFlow(100.0, floatingbondRedemption1));
             Bond floatingBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  floatingBondMaturityDate1, floatingBondStartDate1,
                  floatingBondLeg1);
             floatingBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond1.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(27,Month.March,2007), 0.0402);
             double floatingBondImpliedValue1 = floatingBond1.cleanPrice();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double floatingBondCleanPrice1 = BondFunctions.cleanPrice(floatingBond1, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Semiannual, fixedBondSettlementDate1);
             double error5 = Math.Abs(floatingBondImpliedValue1-floatingBondCleanPrice1);
             if (error5>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: " +
                        floatingBondImpliedValue1
                        + "\n  par asset swap spread: " + floatingBondCleanPrice1
                        + "\n  error:                 " + error5
                        + "\n  tolerance:             " + tolerance);
             }

             // FRN Underlying bond (Isin: XS0090566539 COE 0 09/24/18)
             // maturity occurs on a business day

             Date floatingBondStartDate2 = new Date(24,Month.September,2004);
             Date floatingBondMaturityDate2 = new Date(24,Month.September,2018);
             Schedule floatingBondSchedule2 = new Schedule(floatingBondStartDate2,
                                       floatingBondMaturityDate2,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg2 = new IborLeg(floatingBondSchedule2, vars.iborIndex)
            .withFixingDays(fixingDays)
            .withSpreads(0.0025)
            .withPaymentDayCounter(new Actual360())
            .inArrears(inArrears)
            .withPaymentAdjustment(BusinessDayConvention.ModifiedFollowing)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption2 = bondCalendar.adjust(floatingBondMaturityDate2, BusinessDayConvention.ModifiedFollowing);
             floatingBondLeg2.Add(new SimpleCashFlow(100.0, floatingbondRedemption2));
             Bond floatingBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount, floatingBondMaturityDate2,
            floatingBondStartDate2, floatingBondLeg2);
             floatingBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond2.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(22,Month.March,2007), 0.04013);
             double floatingBondImpliedValue2 = floatingBond2.cleanPrice();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double floatingBondCleanPrice2 = BondFunctions.cleanPrice(floatingBond2, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Semiannual,  fixedBondSettlementDate1);
             double error7 = Math.Abs(floatingBondImpliedValue2-floatingBondCleanPrice2);
             if (error7>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: " +
                        floatingBondImpliedValue2
                        + "\n  par asset swap spread: " + floatingBondCleanPrice2
                        + "\n  error:                 " + error7
                        + "\n  tolerance:             " + tolerance);
             }

             // CMS Underlying bond (Isin: XS0228052402 CRDIT 0 8/22/20)
             // maturity doesn't occur on a business day

             Date cmsBondStartDate1 = new Date(22,Month.August,2005);
             Date cmsBondMaturityDate1 = new Date(22,Month.August,2020);
             Schedule cmsBondSchedule1= new Schedule(cmsBondStartDate1,
                                 cmsBondMaturityDate1,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg1 = new CmsLeg(cmsBondSchedule1, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withCaps(0.055)
            .withFloors(0.025)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption1 = bondCalendar.adjust(cmsBondMaturityDate1, BusinessDayConvention.Following);
             cmsBondLeg1.Add(new SimpleCashFlow(100.0, cmsbondRedemption1));
             Bond cmsBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount, cmsBondMaturityDate1, cmsBondStartDate1,
            cmsBondLeg1);
             cmsBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond1.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(18,Month.August,2006), 0.04158);
             double cmsBondImpliedValue1 = cmsBond1.cleanPrice();
             Date cmsBondSettlementDate1= cmsBond1.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double cmsBondCleanPrice1 = BondFunctions.cleanPrice(cmsBond1, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Annual,
            cmsBondSettlementDate1);
             double error9 = Math.Abs(cmsBondImpliedValue1-cmsBondCleanPrice1);
             if (error9>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: " + cmsBondImpliedValue1
                        + "\n  par asset swap spread: " + cmsBondCleanPrice1
                        + "\n  error:                 " + error9
                        + "\n  tolerance:             " + tolerance);
             }

             // CMS Underlying bond (Isin: XS0218766664 ISPIM 0 5/6/15)
             // maturity occurs on a business day

             Date cmsBondStartDate2 = new Date(06,Month.May,2005);
             Date cmsBondMaturityDate2 = new Date(06,Month.May,2015);
             Schedule cmsBondSchedule2= new Schedule(cmsBondStartDate2,
                                 cmsBondMaturityDate2,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg2 = new CmsLeg(cmsBondSchedule2, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withGearings(0.84)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption2 = bondCalendar.adjust(cmsBondMaturityDate2,  BusinessDayConvention.Following);
             cmsBondLeg2.Add(new SimpleCashFlow(100.0, cmsbondRedemption2));
             Bond cmsBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  cmsBondMaturityDate2, cmsBondStartDate2, cmsBondLeg2);
             cmsBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond2.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(04,Month.May,2006), 0.04217);
             double cmsBondImpliedValue2 = cmsBond2.cleanPrice();
             Date cmsBondSettlementDate2= cmsBond2.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double cmsBondCleanPrice2 = BondFunctions.cleanPrice(cmsBond2, vars.termStructure, vars.spread,
            new Actual365Fixed(), vars.compounding, Frequency.Annual,
            cmsBondSettlementDate2);
             double error11 = Math.Abs(cmsBondImpliedValue2-cmsBondCleanPrice2);
             if (error11>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  market asset swap spread: " + cmsBondImpliedValue2
                        + "\n  par asset swap spread: " + cmsBondCleanPrice2
                        + "\n  error:                 " + error11
                        + "\n  tolerance:             " + tolerance);
             }

             // Zero Coupon bond (Isin: DE0004771662 IBRD 0 12/20/15)
             // maturity doesn't occur on a business day

             Date zeroCpnBondStartDate1 = new Date(19,Month.December,1985);
             Date zeroCpnBondMaturityDate1 = new Date(20,Month.December,2015);
             Date zeroCpnBondRedemption1 = bondCalendar.adjust(zeroCpnBondMaturityDate1,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg1 = new List<CashFlow>{new SimpleCashFlow(100.0, zeroCpnBondRedemption1)};
             Bond zeroCpnBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate1, zeroCpnBondStartDate1, zeroCpnBondLeg1);
             zeroCpnBond1.setPricingEngine(bondEngine);

             double zeroCpnBondImpliedValue1 = zeroCpnBond1.cleanPrice();
             Date zeroCpnBondSettlementDate1= zeroCpnBond1.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double zeroCpnBondCleanPrice1 =
            BondFunctions.cleanPrice(zeroCpnBond1,
                                 vars.termStructure,
                                 vars.spread,
                                 new Actual365Fixed(),
                                 vars.compounding, Frequency.Annual,
                                 zeroCpnBondSettlementDate1);
             double error13 = Math.Abs(zeroCpnBondImpliedValue1-zeroCpnBondCleanPrice1);
             if (error13>tolerance) {
            Assert.Fail("wrong clean price for zero coupon bond:"
                        + "\n  zero cpn implied value: " +
                        zeroCpnBondImpliedValue1
                        + "\n  zero cpn price: " + zeroCpnBondCleanPrice1
                        + "\n  error:                 " + error13
                        + "\n  tolerance:             " + tolerance);
             }

             // Zero Coupon bond (Isin: IT0001200390 ISPIM 0 02/17/28)
             // maturity occurs on a business day

             Date zeroCpnBondStartDate2 = new Date(17,Month.February,1998);
             Date zeroCpnBondMaturityDate2 = new Date(17,Month.February,2028);
             Date zerocpbondRedemption2 = bondCalendar.adjust(zeroCpnBondMaturityDate2,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg2 = new List<CashFlow>{new SimpleCashFlow(100.0, zerocpbondRedemption2)};
             Bond zeroCpnBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate2, zeroCpnBondStartDate2, zeroCpnBondLeg2);
             zeroCpnBond2.setPricingEngine(bondEngine);

             double zeroCpnBondImpliedValue2 = zeroCpnBond2.cleanPrice();
             Date zeroCpnBondSettlementDate2= zeroCpnBond2.settlementDate();
             // standard market conventions:
             // bond's frequency + coumpounding and daycounter of the YieldCurve
             double zeroCpnBondCleanPrice2 =
            BondFunctions.cleanPrice(zeroCpnBond2,
                                 vars.termStructure,
                                 vars.spread,
                                 new Actual365Fixed(),
                                 vars.compounding, Frequency.Annual,
                                 zeroCpnBondSettlementDate2);
             double error15 = Math.Abs(zeroCpnBondImpliedValue2-zeroCpnBondCleanPrice2);
             if (error15>tolerance) {
            Assert.Fail("wrong clean price for zero coupon bond:"
                        + "\n  zero cpn implied value: " +
                        zeroCpnBondImpliedValue2
                        + "\n  zero cpn price: " + zeroCpnBondCleanPrice2
                        + "\n  error:                 " + error15
                        + "\n  tolerance:             " + tolerance);
             }
        }
示例#30
0
 public static double accrualPeriod(Bond bond) {
   double ret = NQuantLibcPINVOKE.BondFunctions_accrualPeriod__SWIG_1(Bond.getCPtr(bond));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#31
0
        public static double yieldValueBasisPoint(Bond bond, InterestRate yield)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_yieldValueBasisPoint__SWIG_1(Bond.getCPtr(bond), InterestRate.getCPtr(yield));

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#32
0
 public static double atmRate(Bond bond, YieldTermStructure discountCurve, Date settlementDate, double cleanPrice) {
   double ret = NQuantLibcPINVOKE.BondFunctions_atmRate__SWIG_0(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve), Date.getCPtr(settlementDate), cleanPrice);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#33
0
        private static void AddMolecule(dynamic data, Model newModel)
        {
            Dictionary <int, string> atoms = new Dictionary <int, string>();
            var         newMol             = new Molecule();
            ElementBase ce        = Globals.PeriodicTable.C;
            int         atomCount = 0;

            // GitHub: Issue #13 https://github.com/Chem4Word/Version3/issues/13
            if (data.a != null)
            {
                foreach (AtomJSON a in data.a)
                {
                    if (!string.IsNullOrEmpty(a.l))
                    {
                        ElementBase eb;
                        var         ok = AtomHelpers.TryParse(a.l, out eb);
                        if (ok)
                        {
                            if (eb is Element element)
                            {
                                ce = element;
                            }

                            if (eb is FunctionalGroup functionalGroup)
                            {
                                ce = functionalGroup;
                            }
                        }
                    }
                    else
                    {
                        ce = Globals.PeriodicTable.C;
                    }

                    Atom atom = new Atom()
                    {
                        Element  = ce,
                        Position = new Point(a.x, a.y)
                    };

                    if (a.c != null)
                    {
                        atom.FormalCharge = a.c.Value;
                    }

                    atoms.Add(atomCount++, atom.InternalId);
                    newMol.AddAtom(atom);
                    atom.Parent = newMol;
                }
            }

            if (data.b != null)
            {
                foreach (BondJSON b in data.b)
                {
                    string o;
                    if (b.o != null)
                    {
                        o = Globals.OrderValueToOrder(double.Parse(b.o.ToString()));
                    }
                    else
                    {
                        o = Globals.OrderSingle;
                    }

                    Globals.BondStereo s;
                    if (!string.IsNullOrEmpty(b.s))
                    {
                        if (o == Globals.OrderDouble)
                        {
                            if (b.s.Equals(Ambiguous))
                            {
                                s = Globals.BondStereo.Indeterminate;
                            }
                            else
                            {
                                s = Globals.BondStereo.None;
                            }
                        }
                        else
                        {
                            if (b.s.Equals(Recessed))
                            {
                                s = Globals.BondStereo.Hatch;
                            }
                            else if (b.s.Equals(Protruding))
                            {
                                s = Globals.BondStereo.Wedge;
                            }
                            else if (b.s.Equals(Ambiguous))
                            {
                                s = Globals.BondStereo.Indeterminate;
                            }
                            else
                            {
                                s = Globals.BondStereo.None;
                            }
                        }
                    }
                    else
                    {
                        s = Globals.BondStereo.None;
                    }

                    var  sa      = atoms[b.b.Value];
                    var  ea      = atoms[b.e.Value];
                    Bond newBond = new Bond()
                    {
                        StartAtomInternalId = sa,
                        EndAtomInternalId   = ea,
                        Stereo = s,
                        Order  = o
                    };
                    newMol.AddBond(newBond);
                    newBond.Parent = newMol;
                }
            }

            newModel.AddMolecule(newMol);
            newMol.Parent = newModel;
        }
示例#34
0
 public static double yield(Bond bond, double cleanPrice, DayCounter dayCounter, Compounding compounding, Frequency frequency, Date settlementDate, double accuracy) {
   double ret = NQuantLibcPINVOKE.BondFunctions_yield__SWIG_2(Bond.getCPtr(bond), cleanPrice, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, Date.getCPtr(settlementDate), accuracy);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#35
0
        public IHttpActionResult addBondss(Bond c)
        {
            int changeLine = BondsDao.addBond(c);

            return(Ok(changeLine));
        }
示例#36
0
 public static double duration(Bond bond, InterestRate yield) {
   double ret = NQuantLibcPINVOKE.BondFunctions_duration__SWIG_2(Bond.getCPtr(bond), InterestRate.getCPtr(yield));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#37
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal?adjustment)
        {
            const string rateQuotationType       = PriceableSimpleRateAsset.RateQuotationType;
            const string volatilityQuotationType = PriceableCapRateAsset.VolatilityQuotationType;
            Asset        underlyingAsset;
            decimal      addtional = 0.0m;

            if (adjustment != null)
            {
                addtional = (decimal)adjustment;
            }
            var listBasicQuotations = new List <BasicQuotation>();
            var properties          = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            //This is in place to handle volatility curves where the tenor is the expiry.
            case AssetTypesEnum.Period:
            {
                //There is no underlying asset.
                underlyingAsset = null;
                listBasicQuotations.Add(BasicQuotationHelper.Create(instrumentId, value, volatilityQuotationType, "LognormalVolatility"));
                break;
            }

            case AssetTypesEnum.ZeroRate:
            {
                underlyingAsset = new Cash {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Caplet:
            case AssetTypesEnum.Floorlet:
            case AssetTypesEnum.BillCaplet:
            case AssetTypesEnum.BillFloorlet:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(addtional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                underlyingAsset = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)      //TODO this restricts the perios to be the same!!!
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Swaption:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(addtional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(addtional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRCallFutureOption:
            case AssetTypesEnum.IRPutFutureOption:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(addtional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFuture:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(addtional, "Volatility", "LognormalVolatility"));
                }
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                underlyingAsset = new FxRateAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "FxRate"));
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                underlyingAsset = new EquityAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                underlyingAsset = new Commodity {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + addtional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                underlyingAsset = new Bond {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));        //Changed from DirtyPrice.
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            var id = underlyingAsset?.id;

            if (underlyingAsset == null)
            {
                id = listBasicQuotations[0].id;
            }
            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(id, listBasicQuotations.ToArray())));
        }
示例#38
0
        /// <summary>
        /// Creates the lines for a bond
        /// </summary>
        /// <param name="wordprocessingGroup1">Where to add the bond lines</param>
        /// <param name="bond"></param>
        public void CreateLines(Bond bond)
        {
            //Debug.WriteLine("Bond: " + bond.Id);

            //IEnumerable<Atom> bondatoms = bond.GetAtoms();
            IEnumerable <Ring> rings = bond.Rings;
            int ringCount            = 0;

            foreach (Ring r in rings)
            {
                ringCount++;
            }
            //Debug.WriteLine("  Ring Count: " + ringCount);

            Point bondStart = bond.StartAtom.Position;

            Point bondEnd = bond.EndAtom.Position;

            //IEnumerable<CmlBond> toAtomBonds = toAtom.GetLigandBonds();
            //int toAtomBondCount = toAtomBonds.ToArray<CmlBond>().Length;

            //Debug.WriteLine("    From : " + fromAtom.ElementType + " [" + fromAtom.Id + "] at " + bondStart.X + ", " + bondStart.Y);
            //Debug.WriteLine("      To : " + toAtom.ElementType + " [" + toAtom.Id + "] at " + bondEnd.X + ", " + bondEnd.Y);

            #region Create Bond Line objects

            switch (bond.Order)
            {
            case Bond.OrderZero:
            case "unknown":
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Dotted, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                break;

            case Bond.OrderPartial01:
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Dashed, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                break;

            case "1":
            case Bond.OrderSingle:
                switch (bond.Stereo)
                {
                case BondStereo.None:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    break;

                case BondStereo.Hatch:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Hatch, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    break;

                case BondStereo.Wedge:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Wedge, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    break;

                case BondStereo.Indeterminate:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Wavy, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    break;

                default:

                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    break;
                }
                break;

            case Bond.OrderPartial12:
            case Bond.OrderAromatic:
                BondLine a = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                m_BondLines.Add(a.GetParallel(-(BondOffset() / 2)));
                BondLine a1        = a.GetParallel(BondOffset() / 2);
                Point    newStarta = new Point(a1.Start.X, a1.Start.Y);
                Point    newEnda   = new Point(a1.End.X, a1.End.Y);
                CoordinateTool.AdjustLineAboutMidpoint(ref newStarta, ref newEnda, -(BondOffset() / 1.75));
                a1 = new BondLine(newStarta, newEnda, BondLineStyle.Dashed, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                m_BondLines.Add(a1);
                break;

            case Bond.OrderDouble:
                if (bond.Stereo == BondStereo.Indeterminate)     //crossing bonds
                {
                    // Crossed lines
                    BondLine d  = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                    BondLine d1 = d.GetParallel(-(BondOffset() / 2));
                    BondLine d2 = d.GetParallel(BondOffset() / 2);
                    m_BondLines.Add(new BondLine(new Point(d1.Start.X, d1.Start.Y), new Point(d2.End.X, d2.End.Y), BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                    m_BondLines.Add(new BondLine(new Point(d2.Start.X, d2.Start.Y), new Point(d1.End.X, d1.End.Y), BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                }
                else
                {
                    bool shifted = false;
                    if (ringCount == 0)
                    {
                        if (bond.StartAtom.Element as Element == Globals.PeriodicTable.C && bond.EndAtom.Element as Element == Globals.PeriodicTable.C)
                        {
                            shifted = false;
                        }
                        else
                        {
                            shifted = true;
                        }
                    }

                    if (bond.StartAtom.Degree == 1 | bond.EndAtom.Degree == 1)
                    {
                        shifted = true;
                    }

                    if (shifted)
                    {
                        BondLine d = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                        m_BondLines.Add(d.GetParallel(-(BondOffset() / 2)));
                        m_BondLines.Add(d.GetParallel(BondOffset() / 2));
                    }
                    else
                    {
                        //Debug.WriteLine($"bond.Placement {bond.Placement}");
                        Point outIntersectP1;
                        Point outIntersectP2;
                        bool  linesIntersect;
                        bool  segmentsIntersect;
                        Point centre;

                        switch (bond.Placement)
                        {
                        case BondDirection.Anticlockwise:
                            BondLine da = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                            m_BondLines.Add(da);

                            BondLine bla         = da.GetParallel(-BondOffset());
                            Point    startPointa = bla.Start;
                            Point    endPointa   = bla.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointa, endPointa, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointa, endPointa, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointa, ref endPointa, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointa, endPointa, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                            }
                            break;

                        case BondDirection.Clockwise:
                            BondLine dc = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                            m_BondLines.Add(dc);

                            BondLine blc         = dc.GetParallel(+BondOffset());
                            Point    startPointc = blc.Start;
                            Point    endPointc   = blc.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointc, endPointc, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointc, endPointc, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointc, ref endPointc, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointc, endPointc, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                            }
                            break;

                        default:
                            switch (bond.Stereo)
                            {
                            case BondStereo.Cis:
                                BondLine dcc = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                                m_BondLines.Add(dcc);
                                BondLine blnewc      = dcc.GetParallel(+BondOffset());
                                Point    startPointn = blnewc.Start;
                                Point    endPointn   = blnewc.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointn, ref endPointn, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointn, endPointn, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                                break;

                            case BondStereo.Trans:
                                BondLine dtt = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                                m_BondLines.Add(dtt);
                                BondLine blnewt      = dtt.GetParallel(+BondOffset());
                                Point    startPointt = blnewt.Start;
                                Point    endPointt   = blnewt.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointt, ref endPointt, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointt, endPointt, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                                break;

                            default:
                                BondLine dp = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                                m_BondLines.Add(dp.GetParallel(-(BondOffset() / 2)));
                                m_BondLines.Add(dp.GetParallel(BondOffset() / 2));
                                break;
                            }
                            break;
                        }
                    }
                }
                break;

            case "3":
            case "T":
                // Draw main bond line
                BondLine t = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id);
                m_BondLines.Add(t);
                m_BondLines.Add(t.GetParallel(BondOffset()));
                m_BondLines.Add(t.GetParallel(-BondOffset()));
                break;

            default:
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id, bond.Parent.Id, bond.StartAtom.Id, bond.EndAtom.Id));
                break;
            }

            #endregion Create Bond Line objects
        }
示例#39
0
 public static Date accrualEndDate(Bond bond, Date settlementDate) {
   Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_accrualEndDate__SWIG_0(Bond.getCPtr(bond), Date.getCPtr(settlementDate)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#40
0
        protected override void Run()
        {
            // the network lock and the connection.expectDisruption will be cleared in clean()

            new_bonds = new List <NewBond>();
            network   = null;
            Connection.ExpectDisruption = true;
            int    inc         = 100 / (Connection.Cache.HostCount * 2 + 1);
            string network_ref = CreateNetwork(0, inc);

            try
            {
                network        = Connection.WaitForCache(new XenRef <XenAPI.Network>(network_ref));
                network.Locked = true;
                XenAPI.Network.remove_from_other_config(Session, network_ref, XenAPI.Network.CREATE_IN_PROGRESS);

                int lo = inc;
                foreach (Host host in GetHostsMasterLast())
                {
                    List <PIF> pifs = PIFs[host].FindAll(x => x.physical).ToList();

                    List <XenRef <PIF> > pif_refs = new List <XenRef <PIF> >();
                    foreach (PIF pif in pifs)
                    {
                        pif_refs.Add(new XenRef <PIF>(pif.opaque_ref));
                    }

                    log.DebugFormat("Creating bond on {0} with {1} PIFs...", Helpers.GetName(host), pifs.Count);

                    Dictionary <string, string> bondProperties = new Dictionary <string, string>();
                    if (bondMode == bond_mode.lacp)
                    {
                        bondProperties.Add("hashing_algorithm", Bond.HashingAlgoritmToString(hashingAlgoritm));
                    }

                    RelatedTask = Bond.async_create(Session, network_ref, pif_refs, "", bondMode, bondProperties);

                    PollToCompletion(lo, lo + inc);
                    lo += inc;
                    log.DebugFormat("Creating bond on {0} done: bond is {1}.", Helpers.GetName(host), Result);

                    Bond new_bond = Connection.WaitForCache(new XenRef <Bond>(Result));
                    if (new_bond == null)
                    {
                        throw new Failure(Failure.INTERNAL_ERROR, "Bond didn't appear in our cache!");
                    }

                    PIF new_master = Connection.Resolve(new_bond.master);
                    if (new_master == null)
                    {
                        throw new Failure(Failure.INTERNAL_ERROR, "Bond master didn't appear in our cache!");
                    }

                    new_bonds.Add(new NewBond(new_bond, new_master, pifs));

                    new_bond.Locked   = true;
                    new_master.Locked = true;
                }

                foreach (NewBond new_bond in new_bonds)
                {
                    lo += inc;
                    ReconfigureManagementInterfaces(new_bond.slaves, new_bond.master, lo);
                }
            }
            catch (Exception)
            {
                foreach (NewBond new_bond in new_bonds)
                {
                    RevertManagementInterfaces(new_bond);
                    DestroyBond(new_bond.bond);
                }

                DestroyNetwork(network_ref);
                throw;
            }

            Description = string.Format(Messages.ACTION_CREATE_BOND_DONE, name_label);
        }
示例#41
0
 public static int accrualDays(Bond bond) {
   int ret = NQuantLibcPINVOKE.BondFunctions_accrualDays__SWIG_1(Bond.getCPtr(bond));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#42
0
 internal NewBond(Bond bond, PIF master, List <PIF> slaves)
 {
     this.bond   = bond;
     this.master = master;
     this.slaves = slaves;
 }
示例#43
0
 public static double atmRate(Bond bond, YieldTermStructure discountCurve) {
   double ret = NQuantLibcPINVOKE.BondFunctions_atmRate__SWIG_2(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#44
0
        protected sealed override void ExecuteCore(SelectedItemCollection selection)
        {
            //It only supports one item selected for now
            Trace.Assert(selection.Count == 1);

            XenAPI.Network network = (XenAPI.Network)selection.FirstAsXenObject;
            List <PIF>     pifs    = network.Connection.ResolveAll(network.PIFs);

            if (pifs.Count == 0)
            {
                // Should never happen as long as the caller is enabling the button correctly, but
                // it's possible in a tiny window across disconnecting.
                log.Error("Network has no PIFs");
                return;
            }

            // We just want one, so that we can name it.
            PIF pif = pifs[0];

            string msg = string.Format(Messages.DELETE_BOND_MESSAGE, pif.Name());

            bool will_disturb_primary   = NetworkingHelper.ContainsPrimaryManagement(pifs);
            bool will_disturb_secondary = NetworkingHelper.ContainsSecondaryManagement(pifs);

            if (will_disturb_primary)
            {
                Pool pool = Helpers.GetPool(network.Connection);
                if (pool != null && pool.ha_enabled)
                {
                    using (var dlg = new ErrorDialog(string.Format(Messages.BOND_DELETE_HA_ENABLED, pif.Name(), pool.Name()))
                    {
                        WindowTitle = Messages.DELETE_BOND
                    })
                    {
                        dlg.ShowDialog(Parent);
                    }
                    return;
                }

                string message = string.Format(will_disturb_secondary ? Messages.BOND_DELETE_WILL_DISTURB_BOTH : Messages.BOND_DELETE_WILL_DISTURB_PRIMARY, msg);

                DialogResult result;
                using (var dlg = new WarningDialog(message,
                                                   new ThreeButtonDialog.TBDButton(Messages.BOND_DELETE_CONTINUE, DialogResult.OK),
                                                   ThreeButtonDialog.ButtonCancel)
                {
                    HelpNameSetter = "NetworkingConfigWarning",
                    WindowTitle = Messages.DELETE_BOND
                })
                {
                    result = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != result)
                {
                    return;
                }
            }
            else if (will_disturb_secondary)
            {
                DialogResult dialogResult;
                using (var dlg = new WarningDialog(string.Format(Messages.BOND_DELETE_WILL_DISTURB_SECONDARY, msg),
                                                   ThreeButtonDialog.ButtonOK,
                                                   ThreeButtonDialog.ButtonCancel))
                {
                    dialogResult = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != dialogResult)
                {
                    return;
                }
            }
            else
            {
                DialogResult dialogResult;
                using (var dlg = new WarningDialog(msg,
                                                   new ThreeButtonDialog.TBDButton(Messages.OK, DialogResult.OK, selected: true),
                                                   ThreeButtonDialog.ButtonCancel))
                {
                    dialogResult = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != dialogResult)
                {
                    return;
                }
            }

            // The UI shouldn't offer deleting a bond in this case, but let's make sure we've
            // done the right thing and that the bond hasn't been deleted in the meantime. (CA-27436).
            Bond bond = pif.BondMasterOf();

            if (bond != null)
            {
                new Actions.DestroyBondAction(bond).RunAsync();
            }
        }
示例#45
0
 public static double duration(Bond bond, InterestRate yield, Duration.Type type, Date settlementDate) {
   double ret = NQuantLibcPINVOKE.BondFunctions_duration__SWIG_0(Bond.getCPtr(bond), InterestRate.getCPtr(yield), (int)type, Date.getCPtr(settlementDate));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#46
0
        public static double yieldValueBasisPoint(Bond bond, double yield, DayCounter dayCounter, Compounding compounding, Frequency frequency)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_yieldValueBasisPoint__SWIG_3(Bond.getCPtr(bond), yield, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#47
0
 public static double duration(Bond bond, double yield, DayCounter dayCounter, Compounding compounding, Frequency frequency, Duration.Type type) {
   double ret = NQuantLibcPINVOKE.BondFunctions_duration__SWIG_4(Bond.getCPtr(bond), yield, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, (int)type);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#48
0
        public static double previousCashFlowAmount(Bond bond)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_previousCashFlowAmount__SWIG_1(Bond.getCPtr(bond));

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#49
0
 public static double basisPointValue(Bond bond, double yield, DayCounter dayCounter, Compounding compounding, Frequency frequency, Date settlementDate) {
   double ret = NQuantLibcPINVOKE.BondFunctions_basisPointValue__SWIG_2(Bond.getCPtr(bond), yield, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, Date.getCPtr(settlementDate));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#50
0
        public static Date accrualStartDate(Bond bond, Date settlementDate)
        {
            Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_accrualStartDate__SWIG_0(Bond.getCPtr(bond), Date.getCPtr(settlementDate)), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#51
0
 public static double yieldValueBasisPoint(Bond bond, double yield, DayCounter dayCounter, Compounding compounding, Frequency frequency) {
   double ret = NQuantLibcPINVOKE.BondFunctions_yieldValueBasisPoint__SWIG_3(Bond.getCPtr(bond), yield, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#52
0
        public static Date accrualEndDate(Bond bond)
        {
            Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_accrualEndDate__SWIG_1(Bond.getCPtr(bond)), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#53
0
 public static Date previousCashFlowDate(Bond bond, Date refDate) {
   Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_previousCashFlowDate__SWIG_0(Bond.getCPtr(bond), Date.getCPtr(refDate)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#54
0
        public static double yieldFalsePosition(FalsePosition solver, Bond bond, double cleanPrice, DayCounter dayCounter, Compounding compounding, Frequency frequency, Date settlementDate, double accuracy, double guess)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_yieldFalsePosition__SWIG_0(FalsePosition.getCPtr(solver), Bond.getCPtr(bond), cleanPrice, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, Date.getCPtr(settlementDate), accuracy, guess);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#55
0
 public static double previousCashFlowAmount(Bond bond) {
   double ret = NQuantLibcPINVOKE.BondFunctions_previousCashFlowAmount__SWIG_1(Bond.getCPtr(bond));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
示例#56
0
        public static double yieldRidder(Ridder solver, Bond bond, double cleanPrice, DayCounter dayCounter, Compounding compounding, Frequency frequency, Date settlementDate)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_yieldRidder__SWIG_2(Ridder.getCPtr(solver), Bond.getCPtr(bond), cleanPrice, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, Date.getCPtr(settlementDate));

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#57
0
        public void testSpecializedBondVsGenericBondUsingAsw()
        {
            // Testing asset-swap prices and spreads for specialized bond against equivalent generic bond...
             CommonVars vars = new CommonVars();

             Calendar bondCalendar = new TARGET();
             int settlementDays = 3;
             int fixingDays = 2;
             bool payFixedRate = true;
             bool parAssetSwap = true;
             bool inArrears = false;

             // Fixed bond (Isin: DE0001135275 DBR 4 01/04/37)
             // maturity doesn't occur on a business day
             Date fixedBondStartDate1 = new Date(4,Month.January,2005);
             Date fixedBondMaturityDate1 = new Date(4,Month.January,2037);
             Schedule fixedBondSchedule1 = new Schedule(fixedBondStartDate1,
                                    fixedBondMaturityDate1,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg1 = new FixedRateLeg(fixedBondSchedule1)
            .withCouponRates(0.04, new ActualActual(ActualActual.Convention.ISDA))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption1 = bondCalendar.adjust(fixedBondMaturityDate1, BusinessDayConvention.Following);
             fixedBondLeg1.Add(new SimpleCashFlow(100.0, fixedbondRedemption1));
             // generic bond
             Bond fixedBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  fixedBondMaturityDate1, fixedBondStartDate1, fixedBondLeg1);
             IPricingEngine bondEngine = new DiscountingBondEngine(vars.termStructure);
             IPricingEngine swapEngine = new DiscountingSwapEngine(vars.termStructure);
             fixedBond1.setPricingEngine(bondEngine);

             // equivalent specialized fixed rate bond
             Bond fixedSpecializedBond1 = new FixedRateBond(settlementDays, vars.faceAmount, fixedBondSchedule1,
                           new List<double>{0.04},
                           new ActualActual(ActualActual.Convention.ISDA), BusinessDayConvention.Following,
                           100.0, new Date(4,Month.January,2005));
             fixedSpecializedBond1.setPricingEngine(bondEngine);

             double fixedBondPrice1 = fixedBond1.cleanPrice();
             double fixedSpecializedBondPrice1 = fixedSpecializedBond1.cleanPrice();
             AssetSwap fixedBondAssetSwap1 = new AssetSwap(payFixedRate,
                                       fixedBond1, fixedBondPrice1,
                                       vars.iborIndex, vars.nonnullspread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             fixedBondAssetSwap1.setPricingEngine(swapEngine);
             AssetSwap fixedSpecializedBondAssetSwap1 = new AssetSwap(payFixedRate,
                                                fixedSpecializedBond1,
                                                fixedSpecializedBondPrice1,
                                                vars.iborIndex,
                                                vars.nonnullspread,
                                                null,
                                                vars.iborIndex.dayCounter(),
                                                parAssetSwap);
             fixedSpecializedBondAssetSwap1.setPricingEngine(swapEngine);
             double fixedBondAssetSwapPrice1 = fixedBondAssetSwap1.fairCleanPrice();
             double fixedSpecializedBondAssetSwapPrice1 =
            fixedSpecializedBondAssetSwap1.fairCleanPrice();
             double tolerance = 1.0e-13;
             double error1 =
            Math.Abs(fixedBondAssetSwapPrice1-fixedSpecializedBondAssetSwapPrice1);
             if (error1>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  generic  fixed rate bond's  clean price: "
                        + fixedBondAssetSwapPrice1
                        + "\n  equivalent specialized bond's clean price: "
                        + fixedSpecializedBondAssetSwapPrice1
                        + "\n  error:                 " + error1
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double fixedBondMktPrice1= 91.832;
             AssetSwap fixedBondASW1 = new AssetSwap(payFixedRate,
                                 fixedBond1, fixedBondMktPrice1,
                                 vars.iborIndex, vars.spread,
                                 null,
                                 vars.iborIndex.dayCounter(),
                                 parAssetSwap);
             fixedBondASW1.setPricingEngine(swapEngine);
             AssetSwap fixedSpecializedBondASW1 = new AssetSwap(payFixedRate,
                                          fixedSpecializedBond1,
                                          fixedBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             fixedSpecializedBondASW1.setPricingEngine(swapEngine);
             double fixedBondASWSpread1 = fixedBondASW1.fairSpread();
             double fixedSpecializedBondASWSpread1 = fixedSpecializedBondASW1.fairSpread();
             double error2 = Math.Abs(fixedBondASWSpread1-fixedSpecializedBondASWSpread1);
             if (error2>tolerance) {
            Assert.Fail("wrong asw spread  for fixed bond:"
                        + "\n  generic  fixed rate bond's  asw spread: "
                        + fixedBondASWSpread1
                        + "\n  equivalent specialized bond's asw spread: "
                        + fixedSpecializedBondASWSpread1
                        + "\n  error:                 " + error2
                        + "\n  tolerance:             " + tolerance);
             }

             //Fixed bond (Isin: IT0006527060 IBRD 5 02/05/19)
             //maturity occurs on a business day

             Date fixedBondStartDate2 = new Date(5,Month.February,2005);
             Date fixedBondMaturityDate2 = new Date(5,Month.February,2019);
             Schedule fixedBondSchedule2= new Schedule(fixedBondStartDate2,
                                    fixedBondMaturityDate2,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg2 = new FixedRateLeg(fixedBondSchedule2)
            .withCouponRates(0.05, new Thirty360(Thirty360.Thirty360Convention.BondBasis))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption2 = bondCalendar.adjust(fixedBondMaturityDate2, BusinessDayConvention.Following);
             fixedBondLeg2.Add(new SimpleCashFlow(100.0, fixedbondRedemption2));

             // generic bond
             Bond fixedBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  fixedBondMaturityDate2, fixedBondStartDate2, fixedBondLeg2);
             fixedBond2.setPricingEngine(bondEngine);

             // equivalent specialized fixed rate bond
             Bond fixedSpecializedBond2 = new FixedRateBond(settlementDays, vars.faceAmount, fixedBondSchedule2,
                           new List<double>{ 0.05},
                           new Thirty360(Thirty360.Thirty360Convention.BondBasis), BusinessDayConvention.Following,
                           100.0, new Date(5,Month.February,2005));
             fixedSpecializedBond2.setPricingEngine(bondEngine);

             double fixedBondPrice2 = fixedBond2.cleanPrice();
             double fixedSpecializedBondPrice2 = fixedSpecializedBond2.cleanPrice();
             AssetSwap fixedBondAssetSwap2 = new AssetSwap(payFixedRate,
                                       fixedBond2, fixedBondPrice2,
                                       vars.iborIndex, vars.nonnullspread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             fixedBondAssetSwap2.setPricingEngine(swapEngine);
             AssetSwap fixedSpecializedBondAssetSwap2 = new AssetSwap(payFixedRate,
                                                fixedSpecializedBond2,
                                                fixedSpecializedBondPrice2,
                                                vars.iborIndex,
                                                vars.nonnullspread,
                                                null,
                                                vars.iborIndex.dayCounter(),
                                                parAssetSwap);
             fixedSpecializedBondAssetSwap2.setPricingEngine(swapEngine);
             double fixedBondAssetSwapPrice2 = fixedBondAssetSwap2.fairCleanPrice();
             double fixedSpecializedBondAssetSwapPrice2 = fixedSpecializedBondAssetSwap2.fairCleanPrice();

             double error3 = Math.Abs(fixedBondAssetSwapPrice2-fixedSpecializedBondAssetSwapPrice2);
             if (error3>tolerance) {
            Assert.Fail("wrong clean price for fixed bond:"
                        + "\n  generic  fixed rate bond's clean price: "
                        + fixedBondAssetSwapPrice2
                        + "\n  equivalent specialized  bond's clean price: "
                        + fixedSpecializedBondAssetSwapPrice2
                        + "\n  error:                 " + error3
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double fixedBondMktPrice2= 102.178;
             AssetSwap fixedBondASW2 = new AssetSwap(payFixedRate,
                                 fixedBond2, fixedBondMktPrice2,
                                 vars.iborIndex, vars.spread,
                                 null,
                                 vars.iborIndex.dayCounter(),
                                 parAssetSwap);
             fixedBondASW2.setPricingEngine(swapEngine);
             AssetSwap fixedSpecializedBondASW2 = new AssetSwap(payFixedRate,
                                          fixedSpecializedBond2,
                                          fixedBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             fixedSpecializedBondASW2.setPricingEngine(swapEngine);
             double fixedBondASWSpread2 = fixedBondASW2.fairSpread();
             double fixedSpecializedBondASWSpread2 = fixedSpecializedBondASW2.fairSpread();
             double error4 = Math.Abs(fixedBondASWSpread2-fixedSpecializedBondASWSpread2);
             if (error4>tolerance) {
            Assert.Fail("wrong asw spread for fixed bond:"
                        + "\n  generic  fixed rate bond's  asw spread: "
                        + fixedBondASWSpread2
                        + "\n  equivalent specialized bond's asw spread: "
                        + fixedSpecializedBondASWSpread2
                        + "\n  error:                 " + error4
                        + "\n  tolerance:             " + tolerance);
             }

             //FRN bond (Isin: IT0003543847 ISPIM 0 09/29/13)
             //maturity doesn't occur on a business day
             Date floatingBondStartDate1 = new Date(29,Month.September,2003);
             Date floatingBondMaturityDate1 = new Date(29,Month.September,2013);
             Schedule floatingBondSchedule1= new Schedule(floatingBondStartDate1,
                                       floatingBondMaturityDate1,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg1 = new IborLeg(floatingBondSchedule1, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0056)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption1 = bondCalendar.adjust(floatingBondMaturityDate1, BusinessDayConvention.Following);
             floatingBondLeg1.Add(new SimpleCashFlow(100.0, floatingbondRedemption1));
             // generic bond
             Bond floatingBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  floatingBondMaturityDate1, floatingBondStartDate1, floatingBondLeg1);
             floatingBond1.setPricingEngine(bondEngine);

             // equivalent specialized floater
             Bond floatingSpecializedBond1 = new FloatingRateBond(settlementDays, vars.faceAmount,
                                 floatingBondSchedule1,
                                 vars.iborIndex, new Actual360(),
                                 BusinessDayConvention.Following, fixingDays,
                                 new List<double>{1},
                                 new List<double>{0.0056},
                                 new List<double>(), new List<double>(),
                                 inArrears,
                                 100.0, new Date(29,Month.September,2003));
             floatingSpecializedBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond1.cashflows(), vars.pricer);
             Utils.setCouponPricer(floatingSpecializedBond1.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(27,Month.March,2007), 0.0402);
             double floatingBondPrice1 = floatingBond1.cleanPrice();
             double floatingSpecializedBondPrice1= floatingSpecializedBond1.cleanPrice();
             AssetSwap floatingBondAssetSwap1= new AssetSwap(payFixedRate,
                                          floatingBond1, floatingBondPrice1,
                                          vars.iborIndex, vars.nonnullspread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             floatingBondAssetSwap1.setPricingEngine(swapEngine);
             AssetSwap floatingSpecializedBondAssetSwap1= new AssetSwap(payFixedRate,
                                                   floatingSpecializedBond1,
                                                   floatingSpecializedBondPrice1,
                                                   vars.iborIndex,
                                                   vars.nonnullspread,
                                                   null,
                                                   vars.iborIndex.dayCounter(),
                                                   parAssetSwap);
             floatingSpecializedBondAssetSwap1.setPricingEngine(swapEngine);
             double floatingBondAssetSwapPrice1 = floatingBondAssetSwap1.fairCleanPrice();
             double floatingSpecializedBondAssetSwapPrice1 =
            floatingSpecializedBondAssetSwap1.fairCleanPrice();

             double error5 =
            Math.Abs(floatingBondAssetSwapPrice1-floatingSpecializedBondAssetSwapPrice1);
             if (error5>tolerance) {
            Assert.Fail("wrong clean price for frnbond:"
                        + "\n  generic frn rate bond's clean price: "
                        + floatingBondAssetSwapPrice1
                        + "\n  equivalent specialized  bond's price: "
                        + floatingSpecializedBondAssetSwapPrice1
                        + "\n  error:                 " + error5
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double floatingBondMktPrice1= 101.33;
             AssetSwap floatingBondASW1= new AssetSwap(payFixedRate,
                                    floatingBond1, floatingBondMktPrice1,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             floatingBondASW1.setPricingEngine(swapEngine);
             AssetSwap floatingSpecializedBondASW1= new AssetSwap(payFixedRate,
                                             floatingSpecializedBond1,
                                             floatingBondMktPrice1,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             floatingSpecializedBondASW1.setPricingEngine(swapEngine);
             double floatingBondASWSpread1 = floatingBondASW1.fairSpread();
             double floatingSpecializedBondASWSpread1 =
            floatingSpecializedBondASW1.fairSpread();
             double error6 =
            Math.Abs(floatingBondASWSpread1-floatingSpecializedBondASWSpread1);
             if (error6>tolerance) {
            Assert.Fail("wrong asw spread for fixed bond:"
                        + "\n  generic  frn rate bond's  asw spread: "
                        + floatingBondASWSpread1
                        + "\n  equivalent specialized bond's asw spread: "
                        + floatingSpecializedBondASWSpread1
                        + "\n  error:                 " + error6
                        + "\n  tolerance:             " + tolerance);
             }
             //FRN bond (Isin: XS0090566539 COE 0 09/24/18)
             //maturity occurs on a business day
             Date floatingBondStartDate2 = new Date(24,Month.September,2004);
             Date floatingBondMaturityDate2 = new Date(24,Month.September,2018);
             Schedule floatingBondSchedule2= new Schedule(floatingBondStartDate2,
                                       floatingBondMaturityDate2,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg2 = new IborLeg(floatingBondSchedule2, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0025)
            .inArrears(inArrears)
            .withPaymentAdjustment(BusinessDayConvention.ModifiedFollowing)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption2 = bondCalendar.adjust(floatingBondMaturityDate2, BusinessDayConvention.ModifiedFollowing);
             floatingBondLeg2.Add(new SimpleCashFlow(100.0, floatingbondRedemption2));
             // generic bond
             Bond floatingBond2 = new  Bond(settlementDays, bondCalendar, vars.faceAmount,
                  floatingBondMaturityDate2, floatingBondStartDate2,floatingBondLeg2);
             floatingBond2.setPricingEngine(bondEngine);

             // equivalent specialized floater
             Bond floatingSpecializedBond2 = new FloatingRateBond(settlementDays, vars.faceAmount,
                              floatingBondSchedule2,
                              vars.iborIndex, new Actual360(),
                              BusinessDayConvention.ModifiedFollowing, fixingDays,
                              new List<double>{1},
                              new List<double>{0.0025},
                              new List<double>(), new List<double>(),
                              inArrears,
                              100.0, new Date(24,Month.September,2004));
             floatingSpecializedBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond2.cashflows(), vars.pricer);
             Utils.setCouponPricer(floatingSpecializedBond2.cashflows(), vars.pricer);

             vars.iborIndex.addFixing(new Date(22,Month.March,2007), 0.04013);

             double floatingBondPrice2 = floatingBond2.cleanPrice();
             double floatingSpecializedBondPrice2= floatingSpecializedBond2.cleanPrice();
             AssetSwap floatingBondAssetSwap2= new AssetSwap(payFixedRate,
                                          floatingBond2, floatingBondPrice2,
                                          vars.iborIndex, vars.nonnullspread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             floatingBondAssetSwap2.setPricingEngine(swapEngine);
             AssetSwap floatingSpecializedBondAssetSwap2= new AssetSwap(payFixedRate,
                                                   floatingSpecializedBond2,
                                                   floatingSpecializedBondPrice2,
                                                   vars.iborIndex,
                                                   vars.nonnullspread,
                                                   null,
                                                   vars.iborIndex.dayCounter(),
                                                   parAssetSwap);
             floatingSpecializedBondAssetSwap2.setPricingEngine(swapEngine);
             double floatingBondAssetSwapPrice2 = floatingBondAssetSwap2.fairCleanPrice();
             double floatingSpecializedBondAssetSwapPrice2 =
            floatingSpecializedBondAssetSwap2.fairCleanPrice();
             double error7 =
            Math.Abs(floatingBondAssetSwapPrice2-floatingSpecializedBondAssetSwapPrice2);
             if (error7>tolerance) {
            Assert.Fail("wrong clean price for frnbond:"
                        + "\n  generic frn rate bond's clean price: "
                        + floatingBondAssetSwapPrice2
                        + "\n  equivalent specialized frn  bond's price: "
                        + floatingSpecializedBondAssetSwapPrice2
                        + "\n  error:                 " + error7
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double floatingBondMktPrice2 = 101.26;
             AssetSwap floatingBondASW2= new AssetSwap(payFixedRate,
                                    floatingBond2, floatingBondMktPrice2,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             floatingBondASW2.setPricingEngine(swapEngine);
             AssetSwap floatingSpecializedBondASW2= new AssetSwap(payFixedRate,
                                             floatingSpecializedBond2,
                                             floatingBondMktPrice2,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             floatingSpecializedBondASW2.setPricingEngine(swapEngine);
             double floatingBondASWSpread2 = floatingBondASW2.fairSpread();
             double floatingSpecializedBondASWSpread2 =
            floatingSpecializedBondASW2.fairSpread();
             double error8 =
            Math.Abs(floatingBondASWSpread2-floatingSpecializedBondASWSpread2);
             if (error8>tolerance) {
            Assert.Fail("wrong asw spread for frn bond:"
                        + "\n  generic  frn rate bond's  asw spread: "
                        + floatingBondASWSpread2
                        + "\n  equivalent specialized bond's asw spread: "
                        + floatingSpecializedBondASWSpread2
                        + "\n  error:                 " + error8
                        + "\n  tolerance:             " + tolerance);
             }

             // CMS bond (Isin: XS0228052402 CRDIT 0 8/22/20)
             // maturity doesn't occur on a business day
             Date cmsBondStartDate1 = new Date(22,Month.August,2005);
             Date cmsBondMaturityDate1 = new Date(22,Month.August,2020);
             Schedule cmsBondSchedule1= new Schedule(cmsBondStartDate1,
                                 cmsBondMaturityDate1,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg1 = new CmsLeg(cmsBondSchedule1, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withCaps(0.055)
            .withFloors(0.025)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption1 = bondCalendar.adjust(cmsBondMaturityDate1, BusinessDayConvention.Following);
             cmsBondLeg1.Add(new SimpleCashFlow(100.0, cmsbondRedemption1));
             // generic cms bond
             Bond cmsBond1 = new  Bond(settlementDays, bondCalendar, vars.faceAmount,
                  cmsBondMaturityDate1, cmsBondStartDate1, cmsBondLeg1);
             cmsBond1.setPricingEngine(bondEngine);

             // equivalent specialized cms bond
             Bond cmsSpecializedBond1 = new CmsRateBond(settlementDays, vars.faceAmount, cmsBondSchedule1,
                     vars.swapIndex, new Thirty360(),
                     BusinessDayConvention.Following, fixingDays,
                     new List<double>{1.0}, new List<double>{0.0},
                     new List<double>{0.055}, new List<double>{0.025},
                     inArrears,
                     100.0, new Date(22,Month.August,2005));
             cmsSpecializedBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond1.cashflows(), vars.cmspricer);
             Utils.setCouponPricer(cmsSpecializedBond1.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(18,Month.August,2006), 0.04158);
             double cmsBondPrice1 = cmsBond1.cleanPrice();
             double cmsSpecializedBondPrice1 = cmsSpecializedBond1.cleanPrice();
             AssetSwap cmsBondAssetSwap1= new AssetSwap(payFixedRate,cmsBond1, cmsBondPrice1,
                                    vars.iborIndex, vars.nonnullspread,
                                    null,vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             cmsBondAssetSwap1.setPricingEngine(swapEngine);
             AssetSwap cmsSpecializedBondAssetSwap1= new AssetSwap(payFixedRate,cmsSpecializedBond1,
                                                cmsSpecializedBondPrice1,
                                                vars.iborIndex,
                                                vars.nonnullspread,
                                                null,
                                                vars.iborIndex.dayCounter(),
                                                parAssetSwap);
             cmsSpecializedBondAssetSwap1.setPricingEngine(swapEngine);
             double cmsBondAssetSwapPrice1 = cmsBondAssetSwap1.fairCleanPrice();
             double cmsSpecializedBondAssetSwapPrice1 =
            cmsSpecializedBondAssetSwap1.fairCleanPrice();
             double error9 =
            Math.Abs(cmsBondAssetSwapPrice1-cmsSpecializedBondAssetSwapPrice1);
             if (error9>tolerance) {
            Assert.Fail("wrong clean price for cmsbond:"
                        + "\n  generic bond's clean price: "
                        + cmsBondAssetSwapPrice1
                        + "\n  equivalent specialized cms rate bond's price: "
                        + cmsSpecializedBondAssetSwapPrice1
                        + "\n  error:                 " + error9
                        + "\n  tolerance:             " + tolerance);
             }
             double cmsBondMktPrice1 = 87.02;// market executable price as of 4th sept 2007
             AssetSwap cmsBondASW1= new AssetSwap(payFixedRate,
                              cmsBond1, cmsBondMktPrice1,
                              vars.iborIndex, vars.spread,
                              null,
                              vars.iborIndex.dayCounter(),
                              parAssetSwap);
             cmsBondASW1.setPricingEngine(swapEngine);
             AssetSwap cmsSpecializedBondASW1= new AssetSwap(payFixedRate,
                                          cmsSpecializedBond1,
                                          cmsBondMktPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             cmsSpecializedBondASW1.setPricingEngine(swapEngine);
             double cmsBondASWSpread1 = cmsBondASW1.fairSpread();
             double cmsSpecializedBondASWSpread1 = cmsSpecializedBondASW1.fairSpread();
             double error10 = Math.Abs(cmsBondASWSpread1-cmsSpecializedBondASWSpread1);
             if (error10>tolerance) {
            Assert.Fail("wrong asw spread for cm bond:"
                        + "\n  generic cms rate bond's  asw spread: "
                        + cmsBondASWSpread1
                        + "\n  equivalent specialized bond's asw spread: "
                        + cmsSpecializedBondASWSpread1
                        + "\n  error:                 " + error10
                        + "\n  tolerance:             " + tolerance);
             }

             //CMS bond (Isin: XS0218766664 ISPIM 0 5/6/15)
             //maturity occurs on a business day
             Date cmsBondStartDate2 = new Date(06,Month.May,2005);
             Date cmsBondMaturityDate2 = new Date(06,Month.May,2015);
             Schedule cmsBondSchedule2= new Schedule(cmsBondStartDate2,
                                 cmsBondMaturityDate2,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg2 = new CmsLeg(cmsBondSchedule2, vars.swapIndex)
            .withPaymentDayCounter(new Thirty360())
            .withFixingDays(fixingDays)
            .withGearings(0.84)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption2 = bondCalendar.adjust(cmsBondMaturityDate2,
                                                      BusinessDayConvention.Following);
             cmsBondLeg2.Add(new SimpleCashFlow(100.0, cmsbondRedemption2));
             // generic bond
             Bond cmsBond2 = new  Bond(settlementDays, bondCalendar, vars.faceAmount,
                  cmsBondMaturityDate2, cmsBondStartDate2, cmsBondLeg2);
             cmsBond2.setPricingEngine(bondEngine);

             // equivalent specialized cms bond
             Bond cmsSpecializedBond2 = new  CmsRateBond(settlementDays, vars.faceAmount, cmsBondSchedule2,
                     vars.swapIndex, new Thirty360(),
                     BusinessDayConvention.Following, fixingDays,
                     new List<double>{0.84}, new List<double>{0.0},
                     new List<double>(), new List<double>(),
                     inArrears,
                     100.0, new Date(06,Month.May,2005));
             cmsSpecializedBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond2.cashflows(), vars.cmspricer);
             Utils.setCouponPricer(cmsSpecializedBond2.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(04,Month.May,2006), 0.04217);
             double cmsBondPrice2 = cmsBond2.cleanPrice();
             double cmsSpecializedBondPrice2 = cmsSpecializedBond2.cleanPrice();
             AssetSwap cmsBondAssetSwap2= new AssetSwap(payFixedRate,cmsBond2, cmsBondPrice2,
                                    vars.iborIndex, vars.nonnullspread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             cmsBondAssetSwap2.setPricingEngine(swapEngine);
             AssetSwap cmsSpecializedBondAssetSwap2= new AssetSwap(payFixedRate,cmsSpecializedBond2,
                                                cmsSpecializedBondPrice2,
                                                vars.iborIndex,
                                                vars.nonnullspread,
                                                null,
                                                vars.iborIndex.dayCounter(),
                                                parAssetSwap);
             cmsSpecializedBondAssetSwap2.setPricingEngine(swapEngine);
             double cmsBondAssetSwapPrice2 = cmsBondAssetSwap2.fairCleanPrice();
             double cmsSpecializedBondAssetSwapPrice2 =
            cmsSpecializedBondAssetSwap2.fairCleanPrice();
             double error11 =
            Math.Abs(cmsBondAssetSwapPrice2-cmsSpecializedBondAssetSwapPrice2);
             if (error11>tolerance) {
            Assert.Fail("wrong clean price for cmsbond:"
                        + "\n  generic  bond's clean price: "
                        + cmsBondAssetSwapPrice2
                        + "\n  equivalent specialized cms rate bond's price: "
                        + cmsSpecializedBondAssetSwapPrice2
                        + "\n  error:                 " + error11
                        + "\n  tolerance:             " + tolerance);
             }
             double cmsBondMktPrice2 = 94.35;// market executable price as of 4th sept 2007
             AssetSwap cmsBondASW2= new AssetSwap(payFixedRate,
                              cmsBond2, cmsBondMktPrice2,
                              vars.iborIndex, vars.spread,
                              null,
                              vars.iborIndex.dayCounter(),
                              parAssetSwap);
             cmsBondASW2.setPricingEngine(swapEngine);
             AssetSwap cmsSpecializedBondASW2= new AssetSwap(payFixedRate,
                                          cmsSpecializedBond2,
                                          cmsBondMktPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             cmsSpecializedBondASW2.setPricingEngine(swapEngine);
             double cmsBondASWSpread2 = cmsBondASW2.fairSpread();
             double cmsSpecializedBondASWSpread2 = cmsSpecializedBondASW2.fairSpread();
             double error12 = Math.Abs(cmsBondASWSpread2-cmsSpecializedBondASWSpread2);
             if (error12>tolerance) {
            Assert.Fail("wrong asw spread for cm bond:"
                        + "\n  generic cms rate bond's  asw spread: "
                        + cmsBondASWSpread2
                        + "\n  equivalent specialized bond's asw spread: "
                        + cmsSpecializedBondASWSpread2
                        + "\n  error:                 " + error12
                        + "\n  tolerance:             " + tolerance);
             }

              //  Zero-Coupon bond (Isin: DE0004771662 IBRD 0 12/20/15)
              //  maturity doesn't occur on a business day
             Date zeroCpnBondStartDate1 = new Date(19,Month.December,1985);
             Date zeroCpnBondMaturityDate1 = new Date(20,Month.December,2015);
             Date zeroCpnBondRedemption1 = bondCalendar.adjust(zeroCpnBondMaturityDate1,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg1 = new List<CashFlow>{new SimpleCashFlow(100.0, zeroCpnBondRedemption1)};
             // generic bond
             Bond zeroCpnBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate1, zeroCpnBondStartDate1, zeroCpnBondLeg1);
             zeroCpnBond1.setPricingEngine(bondEngine);

             // specialized zerocpn bond
             Bond zeroCpnSpecializedBond1= new ZeroCouponBond(settlementDays, bondCalendar, vars.faceAmount,
                     new Date(20,Month.December,2015),
                     BusinessDayConvention.Following,
                     100.0, new Date(19,Month.December,1985));
             zeroCpnSpecializedBond1.setPricingEngine(bondEngine);

             double zeroCpnBondPrice1 = zeroCpnBond1.cleanPrice();
             double zeroCpnSpecializedBondPrice1 = zeroCpnSpecializedBond1.cleanPrice();
             AssetSwap zeroCpnBondAssetSwap1= new AssetSwap(payFixedRate,zeroCpnBond1,
                                       zeroCpnBondPrice1,
                                       vars.iborIndex, vars.nonnullspread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             zeroCpnBondAssetSwap1.setPricingEngine(swapEngine);
             AssetSwap zeroCpnSpecializedBondAssetSwap1= new AssetSwap(payFixedRate,
                                                   zeroCpnSpecializedBond1,
                                                   zeroCpnSpecializedBondPrice1,
                                                   vars.iborIndex,
                                                   vars.nonnullspread,
                                                   null,
                                                   vars.iborIndex.dayCounter(),
                                                   parAssetSwap);
             zeroCpnSpecializedBondAssetSwap1.setPricingEngine(swapEngine);
             double zeroCpnBondAssetSwapPrice1 = zeroCpnBondAssetSwap1.fairCleanPrice();
             double zeroCpnSpecializedBondAssetSwapPrice1 =
            zeroCpnSpecializedBondAssetSwap1.fairCleanPrice();
             double error13 =
            Math.Abs(zeroCpnBondAssetSwapPrice1-zeroCpnSpecializedBondAssetSwapPrice1);
             if (error13>tolerance) {
            Assert.Fail("wrong clean price for zerocpn bond:"
                        + "\n  generic zero cpn bond's clean price: "
                        + zeroCpnBondAssetSwapPrice1
                        + "\n  specialized equivalent bond's price: "
                        + zeroCpnSpecializedBondAssetSwapPrice1
                        + "\n  error:                 " + error13
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double zeroCpnBondMktPrice1 = 72.277;
             AssetSwap zeroCpnBondASW1= new AssetSwap(payFixedRate,
                                 zeroCpnBond1,zeroCpnBondMktPrice1,
                                 vars.iborIndex, vars.spread,
                                 null,
                                 vars.iborIndex.dayCounter(),
                                 parAssetSwap);
             zeroCpnBondASW1.setPricingEngine(swapEngine);
             AssetSwap zeroCpnSpecializedBondASW1= new AssetSwap(payFixedRate,
                                             zeroCpnSpecializedBond1,
                                             zeroCpnBondMktPrice1,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             zeroCpnSpecializedBondASW1.setPricingEngine(swapEngine);
             double zeroCpnBondASWSpread1 = zeroCpnBondASW1.fairSpread();
             double zeroCpnSpecializedBondASWSpread1 =
            zeroCpnSpecializedBondASW1.fairSpread();
             double error14 =
            Math.Abs(zeroCpnBondASWSpread1-zeroCpnSpecializedBondASWSpread1);
             if (error14>tolerance) {
            Assert.Fail("wrong asw spread for zeroCpn bond:"
                        + "\n  generic zeroCpn bond's  asw spread: "
                        + zeroCpnBondASWSpread1
                        + "\n  equivalent specialized bond's asw spread: "
                        + zeroCpnSpecializedBondASWSpread1
                        + "\n  error:                 " + error14
                        + "\n  tolerance:             " + tolerance);
             }

              //  Zero Coupon bond (Isin: IT0001200390 ISPIM 0 02/17/28)
              //  maturity doesn't occur on a business day
             Date zeroCpnBondStartDate2 = new Date(17,Month.February,1998);
             Date zeroCpnBondMaturityDate2 = new Date(17,Month.February,2028);
             Date zerocpbondRedemption2 = bondCalendar.adjust(zeroCpnBondMaturityDate2,
                                                         BusinessDayConvention.Following);
             List<CashFlow> zeroCpnBondLeg2 = new List<CashFlow>{new SimpleCashFlow(100.0, zerocpbondRedemption2)};
             // generic bond
             Bond zeroCpnBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate2, zeroCpnBondStartDate2, zeroCpnBondLeg2);
             zeroCpnBond2.setPricingEngine(bondEngine);

             // specialized zerocpn bond
             Bond zeroCpnSpecializedBond2 = new ZeroCouponBond(settlementDays, bondCalendar, vars.faceAmount,
                        new Date(17,Month.February,2028),
                        BusinessDayConvention.Following,
                        100.0, new Date(17,Month.February,1998));
             zeroCpnSpecializedBond2.setPricingEngine(bondEngine);

             double zeroCpnBondPrice2 = zeroCpnBond2.cleanPrice();
             double zeroCpnSpecializedBondPrice2 = zeroCpnSpecializedBond2.cleanPrice();

             AssetSwap zeroCpnBondAssetSwap2= new AssetSwap(payFixedRate,zeroCpnBond2,
                                       zeroCpnBondPrice2,
                                       vars.iborIndex, vars.nonnullspread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             zeroCpnBondAssetSwap2.setPricingEngine(swapEngine);
             AssetSwap zeroCpnSpecializedBondAssetSwap2= new AssetSwap(payFixedRate,
                                                   zeroCpnSpecializedBond2,
                                                   zeroCpnSpecializedBondPrice2,
                                                   vars.iborIndex,
                                                   vars.nonnullspread,
                                                   null,
                                                   vars.iborIndex.dayCounter(),
                                                   parAssetSwap);
             zeroCpnSpecializedBondAssetSwap2.setPricingEngine(swapEngine);
             double zeroCpnBondAssetSwapPrice2 = zeroCpnBondAssetSwap2.fairCleanPrice();
             double zeroCpnSpecializedBondAssetSwapPrice2 =
                                    zeroCpnSpecializedBondAssetSwap2.fairCleanPrice();
             double error15 = Math.Abs(zeroCpnBondAssetSwapPrice2
                                 -zeroCpnSpecializedBondAssetSwapPrice2);
             if (error15>tolerance) {
            Assert.Fail("wrong clean price for zerocpn bond:"
                        + "\n  generic zero cpn bond's clean price: "
                        + zeroCpnBondAssetSwapPrice2
                        + "\n  equivalent specialized bond's price: "
                        + zeroCpnSpecializedBondAssetSwapPrice2
                        + "\n  error:                 " + error15
                        + "\n  tolerance:             " + tolerance);
             }
             // market executable price as of 4th sept 2007
             double zeroCpnBondMktPrice2 = 72.277;
             AssetSwap zeroCpnBondASW2= new AssetSwap(payFixedRate,
                                 zeroCpnBond2,zeroCpnBondMktPrice2,
                                 vars.iborIndex, vars.spread,
                                 null,
                                 vars.iborIndex.dayCounter(),
                                 parAssetSwap);
             zeroCpnBondASW2.setPricingEngine(swapEngine);
             AssetSwap zeroCpnSpecializedBondASW2= new AssetSwap(payFixedRate,
                                             zeroCpnSpecializedBond2,
                                             zeroCpnBondMktPrice2,
                                             vars.iborIndex, vars.spread,
                                             null,
                                             vars.iborIndex.dayCounter(),
                                             parAssetSwap);
             zeroCpnSpecializedBondASW2.setPricingEngine(swapEngine);
             double zeroCpnBondASWSpread2 = zeroCpnBondASW2.fairSpread();
             double zeroCpnSpecializedBondASWSpread2 =
            zeroCpnSpecializedBondASW2.fairSpread();
             double error16 =
            Math.Abs(zeroCpnBondASWSpread2-zeroCpnSpecializedBondASWSpread2);
             if (error16>tolerance) {
            Assert.Fail("wrong asw spread for zeroCpn bond:"
                        + "\n  generic zeroCpn bond's  asw spread: "
                        + zeroCpnBondASWSpread2
                        + "\n  equivalent specialized bond's asw spread: "
                        + zeroCpnSpecializedBondASWSpread2
                        + "\n  error:                 " + error16
                        + "\n  tolerance:             " + tolerance);
             }
        }
示例#58
0
        public static double yieldSecant(Secant solver, Bond bond, double cleanPrice, DayCounter dayCounter, Compounding compounding, Frequency frequency)
        {
            double ret = NQuantLibcPINVOKE.BondFunctions_yieldSecant__SWIG_3(Secant.getCPtr(solver), Bond.getCPtr(bond), cleanPrice, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#59
0
        public void testGenericBondImplied()
        {
            // Testing implied generic-bond value against asset-swap fair price with null spread...

             CommonVars vars = new CommonVars();

             Calendar bondCalendar = new TARGET();
             int settlementDays = 3;
             int fixingDays = 2;
             bool payFixeddouble = true;
             bool parAssetSwap = true;
             bool inArrears = false;

             // Fixed Underlying bond (Isin: DE0001135275 DBR 4 01/04/37)
             // maturity doesn't occur on a business day
             Date fixedBondStartDate1 =new Date(4,Month.January,2005);
             Date fixedBondMaturityDate1 =new Date(4,Month.January,2037);
             Schedule fixedBondSchedule1 = new Schedule(fixedBondStartDate1,
                                    fixedBondMaturityDate1,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg1 = new FixedRateLeg(fixedBondSchedule1)
            .withCouponRates(0.04, new ActualActual(ActualActual.Convention.ISDA))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption1 = bondCalendar.adjust(fixedBondMaturityDate1,
                                                         BusinessDayConvention.Following);
             fixedBondLeg1.Add((new SimpleCashFlow(100.0, fixedbondRedemption1)));
             Bond fixedBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  fixedBondMaturityDate1, fixedBondStartDate1, fixedBondLeg1);
             IPricingEngine bondEngine = new DiscountingBondEngine(vars.termStructure);
             IPricingEngine swapEngine= new DiscountingSwapEngine(vars.termStructure);
             fixedBond1.setPricingEngine(bondEngine);

             double fixedBondPrice1 = fixedBond1.cleanPrice();
             AssetSwap fixedBondAssetSwap1 = new AssetSwap(payFixeddouble,
                                       fixedBond1, fixedBondPrice1,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             fixedBondAssetSwap1.setPricingEngine(swapEngine);
             double fixedBondAssetSwapPrice1 = fixedBondAssetSwap1.fairCleanPrice();
             double tolerance = 1.0e-13;
             double error1 = Math.Abs(fixedBondAssetSwapPrice1-fixedBondPrice1);

             if (error1>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for fixed bond:"
                        + "\n  bond's clean price:    " + fixedBondPrice1
                        + "\n  asset swap fair price: " + fixedBondAssetSwapPrice1
                        + "\n  error:                 " + error1
                        + "\n  tolerance:             " + tolerance);
             }

             // Fixed Underlying bond (Isin: IT0006527060 IBRD 5 02/05/19)
             // maturity occurs on a business day
             Date fixedBondStartDate2 =new Date(5,Month.February,2005);
             Date fixedBondMaturityDate2 =new Date(5,Month.February,2019);
             Schedule fixedBondSchedule2= new Schedule(fixedBondStartDate2,
                                    fixedBondMaturityDate2,
                                    new Period(Frequency.Annual), bondCalendar,
                                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                    DateGeneration.Rule.Backward, false);
             List<CashFlow> fixedBondLeg2 = new FixedRateLeg(fixedBondSchedule2)
            .withCouponRates(0.05, new Thirty360(Thirty360.Thirty360Convention.BondBasis))
            .withNotionals(vars.faceAmount);
             Date fixedbondRedemption2 = bondCalendar.adjust(fixedBondMaturityDate2,BusinessDayConvention.Following);
             fixedBondLeg2.Add(new SimpleCashFlow(100.0, fixedbondRedemption2));
             Bond fixedBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  fixedBondMaturityDate2, fixedBondStartDate2, fixedBondLeg2);
             fixedBond2.setPricingEngine(bondEngine);

             double fixedBondPrice2 = fixedBond2.cleanPrice();
             AssetSwap fixedBondAssetSwap2= new AssetSwap(payFixeddouble,
                                       fixedBond2, fixedBondPrice2,
                                       vars.iborIndex, vars.spread,
                                       null,
                                       vars.iborIndex.dayCounter(),
                                       parAssetSwap);
             fixedBondAssetSwap2.setPricingEngine(swapEngine);
             double fixedBondAssetSwapPrice2 = fixedBondAssetSwap2.fairCleanPrice();
             double error2 = Math.Abs(fixedBondAssetSwapPrice2-fixedBondPrice2);

             if (error2>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for fixed bond:"
                        + "\n  bond's clean price:    " + fixedBondPrice2
                        + "\n  asset swap fair price: " + fixedBondAssetSwapPrice2
                        + "\n  error:                 " + error2
                        + "\n  tolerance:             " + tolerance);
             }

             // FRN Underlying bond (Isin: IT0003543847 ISPIM 0 09/29/13)
             // maturity doesn't occur on a business day
             Date floatingBondStartDate1 =new Date(29,Month.September,2003);
             Date floatingBondMaturityDate1 =new Date(29,Month.September,2013);
             Schedule floatingBondSchedule1 = new Schedule(floatingBondStartDate1,
                                       floatingBondMaturityDate1,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg1 = new IborLeg(floatingBondSchedule1, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0056)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date floatingbondRedemption1 =
            bondCalendar.adjust(floatingBondMaturityDate1, BusinessDayConvention.Following);
             floatingBondLeg1.Add(new SimpleCashFlow(100.0, floatingbondRedemption1));
             Bond floatingBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  floatingBondMaturityDate1, floatingBondStartDate1, floatingBondLeg1);
             floatingBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond1.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(27,Month.March,2007), 0.0402);
             double floatingBondPrice1 = floatingBond1.cleanPrice();
             AssetSwap floatingBondAssetSwap1= new AssetSwap(payFixeddouble,
                                          floatingBond1, floatingBondPrice1,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             floatingBondAssetSwap1.setPricingEngine(swapEngine);
             double floatingBondAssetSwapPrice1 = floatingBondAssetSwap1.fairCleanPrice();
             double error3 = Math.Abs(floatingBondAssetSwapPrice1-floatingBondPrice1);

             if (error3>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for floater:"
                        + "\n  bond's clean price:    " + floatingBondPrice1
                        + "\n  asset swap fair price: " +
                        floatingBondAssetSwapPrice1
                        + "\n  error:                 " + error3
                        + "\n  tolerance:             " + tolerance);
             }

             // FRN Underlying bond (Isin: XS0090566539 COE 0 09/24/18)
             // maturity occurs on a business day
             Date floatingBondStartDate2 =new Date(24,Month.September,2004);
             Date floatingBondMaturityDate2 =new Date(24,Month.September,2018);
             Schedule floatingBondSchedule2 = new Schedule(floatingBondStartDate2,
                                       floatingBondMaturityDate2,
                                       new Period(Frequency.Semiannual), bondCalendar,
                                       BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                       DateGeneration.Rule.Backward, false);
             List<CashFlow> floatingBondLeg2 = new IborLeg(floatingBondSchedule2, vars.iborIndex)
            .withPaymentDayCounter(new Actual360())
            .withFixingDays(fixingDays)
            .withSpreads(0.0025)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount)
            .withPaymentAdjustment(BusinessDayConvention.ModifiedFollowing);
             Date floatingbondRedemption2 =
            bondCalendar.adjust(floatingBondMaturityDate2, BusinessDayConvention.ModifiedFollowing);
             floatingBondLeg2.Add(new SimpleCashFlow(100.0, floatingbondRedemption2));
             Bond floatingBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  floatingBondMaturityDate2, floatingBondStartDate2, floatingBondLeg2);
             floatingBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(floatingBond2.cashflows(), vars.pricer);
             vars.iborIndex.addFixing(new Date(22,Month.March,2007), 0.04013);
             double currentCoupon=0.04013+0.0025;
             double floatingCurrentCoupon= floatingBond2.nextCouponRate();
             double error4= Math.Abs(floatingCurrentCoupon-currentCoupon);
             if (error4>tolerance) {
            Assert.Fail("wrong current coupon is returned for floater bond:"
                        + "\n  bond's calculated current coupon:      " +
                        currentCoupon
                        + "\n  current coupon asked to the bond: " +
                        floatingCurrentCoupon
                        + "\n  error:                 " + error4
                        + "\n  tolerance:             " + tolerance);
             }

             double floatingBondPrice2 = floatingBond2.cleanPrice();
             AssetSwap floatingBondAssetSwap2= new AssetSwap(payFixeddouble,
                                          floatingBond2, floatingBondPrice2,
                                          vars.iborIndex, vars.spread,
                                          null,
                                          vars.iborIndex.dayCounter(),
                                          parAssetSwap);
             floatingBondAssetSwap2.setPricingEngine(swapEngine);
             double floatingBondAssetSwapPrice2 = floatingBondAssetSwap2.fairCleanPrice();
             double error5 = Math.Abs(floatingBondAssetSwapPrice2-floatingBondPrice2);

             if (error5>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for floater:"
                        + "\n  bond's clean price:    " + floatingBondPrice2
                        + "\n  asset swap fair price: " +
                        floatingBondAssetSwapPrice2
                        + "\n  error:                 " + error5
                        + "\n  tolerance:             " + tolerance);
             }

             // CMS Underlying bond (Isin: XS0228052402 CRDIT 0 8/22/20)
             // maturity doesn't occur on a business day
             Date cmsBondStartDate1 =new Date(22,Month.August,2005);
             Date cmsBondMaturityDate1 =new Date(22,Month.August,2020);
             Schedule cmsBondSchedule1= new Schedule(cmsBondStartDate1,
                                 cmsBondMaturityDate1,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg1 = new CmsLeg(cmsBondSchedule1, vars.swapIndex)
            .withFixingDays(fixingDays)
            .withPaymentDayCounter(new Thirty360())
            .withCaps(0.055)
            .withFloors(0.025)
            .inArrears(inArrears)
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption1 = bondCalendar.adjust(cmsBondMaturityDate1, BusinessDayConvention.Following);
             cmsBondLeg1.Add( new SimpleCashFlow(100.0, cmsbondRedemption1));
             Bond cmsBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  cmsBondMaturityDate1, cmsBondStartDate1, cmsBondLeg1);
             cmsBond1.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond1.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(18,Month.August,2006), 0.04158);
             double cmsBondPrice1 = cmsBond1.cleanPrice();
             AssetSwap cmsBondAssetSwap1 = new AssetSwap(payFixeddouble,
                                    cmsBond1, cmsBondPrice1,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             cmsBondAssetSwap1.setPricingEngine(swapEngine);
             double cmsBondAssetSwapPrice1 = cmsBondAssetSwap1.fairCleanPrice();
             double error6 = Math.Abs(cmsBondAssetSwapPrice1-cmsBondPrice1);

             if (error6>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for cms bond:"
                        + "\n  bond's clean price:    " + cmsBondPrice1
                        + "\n  asset swap fair price: " + cmsBondAssetSwapPrice1
                        + "\n  error:                 " + error6
                        + "\n  tolerance:             " + tolerance);
             }

             // CMS Underlying bond (Isin: XS0218766664 ISPIM 0 5/6/15)
             // maturity occurs on a business day
             Date cmsBondStartDate2 =new Date(06,Month.May,2005);
             Date cmsBondMaturityDate2 =new Date(06,Month.May,2015);
             Schedule cmsBondSchedule2= new Schedule(cmsBondStartDate2,
                                 cmsBondMaturityDate2,
                                 new Period(Frequency.Annual), bondCalendar,
                                 BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                 DateGeneration.Rule.Backward, false);
             List<CashFlow> cmsBondLeg2 = new CmsLeg(cmsBondSchedule2, vars.swapIndex)
            .withFixingDays(fixingDays)
            .withGearings(0.84)
            .inArrears(inArrears)
            .withPaymentDayCounter(new Thirty360())
            .withNotionals(vars.faceAmount);
             Date cmsbondRedemption2 = bondCalendar.adjust(cmsBondMaturityDate2,BusinessDayConvention.Following);
             cmsBondLeg2.Add(new SimpleCashFlow(100.0, cmsbondRedemption2));
             Bond cmsBond2 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  cmsBondMaturityDate2, cmsBondStartDate2, cmsBondLeg2);
             cmsBond2.setPricingEngine(bondEngine);

             Utils.setCouponPricer(cmsBond2.cashflows(), vars.cmspricer);
             vars.swapIndex.addFixing(new Date(04,Month.May,2006), 0.04217);
             double cmsBondPrice2 = cmsBond2.cleanPrice();
             AssetSwap cmsBondAssetSwap2= new AssetSwap(payFixeddouble,
                                    cmsBond2, cmsBondPrice2,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             cmsBondAssetSwap2.setPricingEngine(swapEngine);
             double cmsBondAssetSwapPrice2 = cmsBondAssetSwap2.fairCleanPrice();
             double error7 = Math.Abs(cmsBondAssetSwapPrice2-cmsBondPrice2);

             if (error7>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for cms bond:"
                        + "\n  bond's clean price:    " + cmsBondPrice2
                        + "\n  asset swap fair price: " + cmsBondAssetSwapPrice2
                        + "\n  error:                 " + error7
                        + "\n  tolerance:             " + tolerance);
             }

             // Zero Coupon bond (Isin: DE0004771662 IBRD 0 12/20/15)
             // maturity doesn't occur on a business day
             Date zeroCpnBondStartDate1 =new Date(19,Month.December,1985);
             Date zeroCpnBondMaturityDate1 =new Date(20,Month.December,2015);
             Date zeroCpnBondRedemption1 = bondCalendar.adjust(zeroCpnBondMaturityDate1,BusinessDayConvention.Following);
             List<CashFlow>zeroCpnBondLeg1 = new List<CashFlow>{new SimpleCashFlow(100.0, zeroCpnBondRedemption1)};
             Bond zeroCpnBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate1, zeroCpnBondStartDate1, zeroCpnBondLeg1);
             zeroCpnBond1.setPricingEngine(bondEngine);

             double zeroCpnBondPrice1 = zeroCpnBond1.cleanPrice();
             AssetSwap zeroCpnAssetSwap1 = new AssetSwap(payFixeddouble,
                                    zeroCpnBond1, zeroCpnBondPrice1,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             zeroCpnAssetSwap1.setPricingEngine(swapEngine);
             double zeroCpnBondAssetSwapPrice1 = zeroCpnAssetSwap1.fairCleanPrice();
             double error8 = Math.Abs(zeroCpnBondAssetSwapPrice1-zeroCpnBondPrice1);

             if (error8>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for zero cpn bond:"
                        + "\n  bond's clean price:    " + zeroCpnBondPrice1
                        + "\n  asset swap fair price: " + zeroCpnBondAssetSwapPrice1
                        + "\n  error:                 " + error8
                        + "\n  tolerance:             " + tolerance);
             }

             // Zero Coupon bond (Isin: IT0001200390 ISPIM 0 02/17/28)
             // maturity occurs on a business day
             Date zeroCpnBondStartDate2 =new Date(17,Month.February,1998);
             Date zeroCpnBondMaturityDate2 =new Date(17,Month.February,2028);
             Date zerocpbondRedemption2 = bondCalendar.adjust(zeroCpnBondMaturityDate2,BusinessDayConvention.Following);
             List<CashFlow>zeroCpnBondLeg2 = new List<CashFlow>{new SimpleCashFlow(100.0, zerocpbondRedemption2)};
             Bond zeroCpnBond2 = new  Bond(settlementDays, bondCalendar, vars.faceAmount,
                  zeroCpnBondMaturityDate2, zeroCpnBondStartDate2, zeroCpnBondLeg2);
             zeroCpnBond2.setPricingEngine(bondEngine);

             double zeroCpnBondPrice2 = zeroCpnBond2.cleanPrice();
             AssetSwap zeroCpnAssetSwap2= new AssetSwap(payFixeddouble,
                                    zeroCpnBond2, zeroCpnBondPrice2,
                                    vars.iborIndex, vars.spread,
                                    null,
                                    vars.iborIndex.dayCounter(),
                                    parAssetSwap);
             zeroCpnAssetSwap2.setPricingEngine(swapEngine);
             double zeroCpnBondAssetSwapPrice2 = zeroCpnAssetSwap2.fairCleanPrice();
             double error9 = Math.Abs(cmsBondAssetSwapPrice2-cmsBondPrice2);

             if (error9>tolerance) {
            Assert.Fail("wrong zero spread asset swap price for zero cpn bond:"
                        + "\n  bond's clean price:    " + zeroCpnBondPrice2
                        + "\n  asset swap fair price: " + zeroCpnBondAssetSwapPrice2
                        + "\n  error:                 " + error9
                        + "\n  tolerance:             " + tolerance);
             }
        }
示例#60
0
        public static Date previousCashFlowDate(Bond bond, Date refDate)
        {
            Date ret = new Date(NQuantLibcPINVOKE.BondFunctions_previousCashFlowDate__SWIG_0(Bond.getCPtr(bond), Date.getCPtr(refDate)), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }