本文整理汇总了C#中Bond.cashflows方法的典型用法代码示例。如果您正苦于以下问题:C# Bond.cashflows方法的具体用法?C# Bond.cashflows怎么用?C# Bond.cashflows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bond
的用法示例。
在下文中一共展示了Bond.cashflows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: previousCashFlow
public static CashFlow previousCashFlow(Bond bond, Date refDate = null)
{
if (refDate == null)
refDate = bond.settlementDate();
return CashFlows.previousCashFlow(bond.cashflows(), false, refDate);
}
示例2: nextCashFlowDate
public static Date nextCashFlowDate(Bond bond, Date refDate = null)
{
if (refDate == null)
refDate = bond.settlementDate();
return CashFlows.nextCashFlowDate(bond.cashflows(), false, refDate);
}
示例3: accrualPeriod
public static double accrualPeriod(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.accrualPeriod(bond.cashflows(), false, settlementDate);
}
示例4: duration
public static double duration(Bond bond, InterestRate yield, Duration.Type type = Duration.Type.Modified,
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.duration(bond.cashflows(), yield, type, false, settlementDate);
}
示例5: maturityDate
public static Date maturityDate(Bond bond)
{
return CashFlows.maturityDate(bond.cashflows());
}
示例6: referencePeriodStart
public static Date referencePeriodStart(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.referencePeriodStart(bond.cashflows(), false, settlementDate);
}
示例7: 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);
}
示例8: 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);
}
示例9: testZSpreadWithGenericBond
//.........这里部分代码省略.........
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)
示例10: nextCouponRate
public static double nextCouponRate(Bond bond, Date settlementDate = null)
{
if (settlementDate == null)
settlementDate = bond.settlementDate();
return CashFlows.nextCouponRate(bond.cashflows(), false, settlementDate);
}
示例11: AssetSwap
public AssetSwap(bool parAssetSwap,
Bond bond,
double bondCleanPrice,
double nonParRepayment,
double gearing,
IborIndex iborIndex,
double spread = 0.0,
DayCounter floatingDayCount = null,
Date dealMaturity = null,
bool payBondCoupon = false)
: base(2)
{
bond_ = bond;
bondCleanPrice_ = bondCleanPrice;
nonParRepayment_ = nonParRepayment;
spread_ = spread;
parSwap_ = parAssetSwap;
Schedule tempSch = new Schedule(bond_.settlementDate(),
bond_.maturityDate(),
iborIndex.tenor(),
iborIndex.fixingCalendar(),
iborIndex.businessDayConvention(),
iborIndex.businessDayConvention(),
DateGeneration.Rule.Backward,
false); // endOfMonth
if (dealMaturity == null)
dealMaturity = bond_.maturityDate();
Utils.QL_REQUIRE( dealMaturity <= tempSch.dates().Last(), () =>
"deal maturity " + dealMaturity +
" cannot be later than (adjusted) bond maturity " +
tempSch.dates().Last());
Utils.QL_REQUIRE( dealMaturity > tempSch.dates()[0], () =>
"deal maturity " + dealMaturity +
" must be later than swap start date " +
tempSch.dates()[0]);
// the following might become an input parameter
BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;
Date finalDate = tempSch.calendar().adjust(dealMaturity, paymentAdjustment);
Schedule schedule = tempSch.until(finalDate);
// 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)
.withGearings(gearing)
.withNotionals(notional)
.withPaymentAdjustment(paymentAdjustment);
else
legs_[1] = new IborLeg(schedule, iborIndex)
.withSpreads(spread)
.withGearings(gearing)
.withPaymentDayCounter(floatingDayCount)
.withNotionals(notional)
.withPaymentAdjustment(paymentAdjustment);
foreach (CashFlow c in legs_[1])
c.registerWith(update);
List<CashFlow> bondLeg = bond_.cashflows();
// skip bond redemption
int i;
for (i = 0; i < bondLeg.Count && bondLeg[i].date() <= dealMaturity; ++i)
{
// whatever might be the choice for the discounting engine
// bond flows on upfrontDate_ must be discarded
bool upfrontDateBondFlows = false;
if (!bondLeg[i].hasOccurred(upfrontDate_, upfrontDateBondFlows))
legs_[0].Add(bondLeg[i]);
}
// if the first skipped cashflow is not the redemption
// and it is a coupon then add the accrued coupon
if (i < bondLeg.Count - 1)
{
Coupon c = bondLeg[i] as Coupon;
if (c != null)
{
CashFlow accruedCoupon = new SimpleCashFlow(c.accruedAmount(dealMaturity), finalDate);
legs_[0].Add(accruedCoupon);
}
}
// add the nonParRepayment_
CashFlow nonParRepaymentFlow = new SimpleCashFlow(nonParRepayment_, finalDate);
legs_[0].Add(nonParRepaymentFlow);
//.........这里部分代码省略.........
示例12: testMASWWithGenericBond
//.........这里部分代码省略.........
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);
示例13: dirtyPrice
public static double dirtyPrice(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;
}
示例14: 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);
}
示例15: bps
public static double bps(Bond bond, YieldTermStructure discountCurve, 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.bps(bond.cashflows(), discountCurve, false, settlementDate) * 100.0 / bond.notional(settlementDate);
}