本文整理汇总了C#中Bond.accruedAmount方法的典型用法代码示例。如果您正苦于以下问题:C# Bond.accruedAmount方法的具体用法?C# Bond.accruedAmount怎么用?C# Bond.accruedAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bond
的用法示例。
在下文中一共展示了Bond.accruedAmount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testSpecializedBondVsGenericBond
public void testSpecializedBondVsGenericBond()
{
// Testing clean and dirty prices for specialized bond against equivalent generic bond...
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));
// generic bond
Bond fixedBond1 = new Bond(settlementDays, bondCalendar, vars.faceAmount,
fixedBondMaturityDate1, fixedBondStartDate1, fixedBondLeg1);
IPricingEngine bondEngine = new DiscountingBondEngine(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 fixedBondTheoValue1 = fixedBond1.cleanPrice();
double fixedSpecializedBondTheoValue1 = fixedSpecializedBond1.cleanPrice();
double tolerance = 1.0e-13;
double error1 = Math.Abs(fixedBondTheoValue1-fixedSpecializedBondTheoValue1);
if (error1>tolerance) {
Assert.Fail("wrong clean price for fixed bond:"
+ "\n specialized fixed rate bond's theo clean price: "
+ fixedBondTheoValue1
+ "\n generic equivalent bond's theo clean price: "
+ fixedSpecializedBondTheoValue1
+ "\n error: " + error1
+ "\n tolerance: " + tolerance);
}
double fixedBondTheoDirty1 = fixedBondTheoValue1+fixedBond1.accruedAmount();
double fixedSpecializedTheoDirty1 = fixedSpecializedBondTheoValue1+
fixedSpecializedBond1.accruedAmount();
double error2 = Math.Abs(fixedBondTheoDirty1-fixedSpecializedTheoDirty1);
if (error2>tolerance) {
Assert.Fail("wrong dirty price for fixed bond:"
+ "\n specialized fixed rate bond's theo dirty price: "
+ fixedBondTheoDirty1
+ "\n generic equivalent bond's theo dirty price: "
+ fixedSpecializedTheoDirty1
+ "\n error: " + error2
+ "\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));
// 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 fixedBondTheoValue2 = fixedBond2.cleanPrice();
double fixedSpecializedBondTheoValue2 = fixedSpecializedBond2.cleanPrice();
double error3 = Math.Abs(fixedBondTheoValue2-fixedSpecializedBondTheoValue2);
if (error3>tolerance) {
Assert.Fail("wrong clean price for fixed bond:"
+ "\n specialized fixed rate bond's theo clean price: "
+ fixedBondTheoValue2
//.........这里部分代码省略.........
示例2: AssetSwap
public AssetSwap(bool payBondCoupon,
Bond bond,
double bondCleanPrice,
IborIndex iborIndex,
double spread,
Schedule floatSchedule = null,
DayCounter floatingDayCount = null,
bool parAssetSwap = true)
: base(2)
{
bond_ = bond;
bondCleanPrice_ = bondCleanPrice;
nonParRepayment_ = 100;
spread_ = spread;
parSwap_ = parAssetSwap;
Schedule schedule = floatSchedule;
if (floatSchedule == null)
schedule = new Schedule(bond_.settlementDate(),
bond_.maturityDate(),
iborIndex.tenor(),
iborIndex.fixingCalendar(),
iborIndex.businessDayConvention(),
iborIndex.businessDayConvention(),
DateGeneration.Rule.Backward,
false); // endOfMonth
// the following might become an input parameter
BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;
Date finalDate = schedule.calendar().adjust(schedule.endDate(), paymentAdjustment);
Date adjBondMaturityDate = schedule.calendar().adjust(bond_.maturityDate(), paymentAdjustment);
Utils.QL_REQUIRE( finalDate == adjBondMaturityDate, () =>
"adjusted schedule end date (" +
finalDate +
") must be equal to adjusted bond maturity date (" +
adjBondMaturityDate + ")");
// bondCleanPrice must be the (forward) clean price
// at the floating schedule start date
upfrontDate_ = schedule.startDate();
double dirtyPrice = bondCleanPrice_ +
bond_.accruedAmount(upfrontDate_);
double notional = bond_.notional(upfrontDate_);
/* In the market asset swap, the bond is purchased in return for
payment of the full price. The notional of the floating leg is
then scaled by the full price. */
if (!parSwap_)
notional *= dirtyPrice / 100.0;
if (floatingDayCount == null)
legs_[1] = new IborLeg(schedule, iborIndex)
.withSpreads(spread)
.withNotionals(notional)
.withPaymentAdjustment(paymentAdjustment);
else
legs_[1] = new IborLeg(schedule, iborIndex)
.withSpreads(spread)
.withPaymentDayCounter(floatingDayCount)
.withNotionals(notional)
.withPaymentAdjustment(paymentAdjustment);
foreach (CashFlow c in legs_[1])
c.registerWith(update);
List<CashFlow> bondLeg = bond_.cashflows();
foreach (CashFlow c in bondLeg)
{
// whatever might be the choice for the discounting engine
// bond flows on upfrontDate_ must be discarded
bool upfrontDateBondFlows = false;
if (!(c.hasOccurred(upfrontDate_, upfrontDateBondFlows)))
legs_[0].Add(c);
}
Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg to start with" );
// special flows
if (parSwap_)
{
// upfront on the floating leg
double upfront = (dirtyPrice - 100.0) / 100.0 * notional;
CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
legs_[1].Insert(0, upfrontCashFlow);
// backpayment on the floating leg
// (accounts for non-par redemption, if any)
double backPayment = notional;
CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
legs_[1].Add(backPaymentCashFlow);
}
else
{
// final notional exchange
CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
legs_[1].Add(finalCashFlow);
}
Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg" );
//.........这里部分代码省略.........
示例3: testMASWWithGenericBond
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(),
//.........这里部分代码省略.........
示例4: zSpread
public static double zSpread(Bond bond, double cleanPrice, YieldTermStructure discount, DayCounter dayCounter, Compounding compounding,
Frequency frequency, Date settlementDate = null, double accuracy = 1.0e-10, int maxIterations = 100,
double guess = 0.0)
{
if (settlementDate == null)
settlementDate = bond.settlementDate();
Utils.QL_REQUIRE( BondFunctions.isTradable( bond, settlementDate ), () =>
"non tradable at " + settlementDate +
" (maturity being " + bond.maturityDate() + ")");
double dirtyPrice = cleanPrice + bond.accruedAmount(settlementDate);
dirtyPrice /= 100.0 / bond.notional(settlementDate);
return CashFlows.zSpread(bond.cashflows(),
discount,
dirtyPrice,
dayCounter, compounding, frequency,
false, settlementDate, settlementDate,
accuracy, maxIterations, guess);
}
示例5: cleanPrice
public static double cleanPrice(Bond bond, YieldTermStructure discount, double zSpread, DayCounter dayCounter, Compounding compounding,
Frequency frequency, Date settlementDate = null)
{
if (settlementDate == null)
settlementDate = bond.settlementDate();
Utils.QL_REQUIRE( BondFunctions.isTradable( bond, settlementDate ), () =>
"non tradable at " + settlementDate +
" (maturity being " + bond.maturityDate() + ")");
double dirtyPrice = CashFlows.npv(bond.cashflows(), discount, zSpread, dayCounter, compounding, frequency, false, settlementDate) *
100.0 / bond.notional(settlementDate);
return dirtyPrice - bond.accruedAmount(settlementDate);
}
示例6: atmRate
public static double atmRate(Bond bond, YieldTermStructure discountCurve, Date settlementDate = null, double? cleanPrice = null)
{
if (settlementDate == null)
settlementDate = bond.settlementDate();
Utils.QL_REQUIRE( BondFunctions.isTradable( bond, settlementDate ), () =>
"non tradable at " + settlementDate +
" (maturity being " + bond.maturityDate() + ")");
double? dirtyPrice = cleanPrice == null ? null : cleanPrice + bond.accruedAmount(settlementDate);
double currentNotional = bond.notional(settlementDate);
double? npv = dirtyPrice / 100.0 * currentNotional;
return CashFlows.atmRate(bond.cashflows(), discountCurve, false, settlementDate, settlementDate, npv);
}
示例7: cleanPrice
public static double cleanPrice(Bond bond, InterestRate yield, Date settlementDate = null)
{
if (settlementDate == null)
settlementDate = bond.settlementDate();
Utils.QL_REQUIRE(BondFunctions.isTradable(bond, settlementDate),
"non tradable at " + settlementDate +
" (maturity being " + bond.maturityDate() + ")");
double dirtyPrice = CashFlows.npv(bond.cashflows(), yield, false, settlementDate) *
100.0 / bond.notional(settlementDate);
return dirtyPrice - bond.accruedAmount(settlementDate);
}