本文整理汇总了C++中CurveState类的典型用法代码示例。如果您正苦于以下问题:C++ CurveState类的具体用法?C++ CurveState怎么用?C++ CurveState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CurveState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fwdCorr
CotSwapFromFwdCorrelation::CotSwapFromFwdCorrelation(
const boost::shared_ptr<PiecewiseConstantCorrelation>& fwdCorr,
const CurveState& curveState,
Spread displacement)
: fwdCorr_(fwdCorr),
numberOfRates_(fwdCorr->numberOfRates()),
swapCorrMatrices_(fwdCorr->correlations().size())
{
QL_REQUIRE(numberOfRates_==curveState.numberOfRates(),
"mismatch between number of rates in fwdCorr (" <<
numberOfRates_ << ") and curveState (" <<
curveState.numberOfRates() << ")");
Matrix zed = SwapForwardMappings::coterminalSwapZedMatrix(
curveState, displacement);
Matrix zedT = transpose(zed);
const std::vector<Matrix>& fwdCorrMatrices = fwdCorr->correlations();
for (Size k = 0; k<fwdCorrMatrices.size(); ++k) {
swapCorrMatrices_[k] = CovarianceDecomposition(
zed * fwdCorrMatrices[k] * zedT).correlationMatrix();
// zero expired rates' correlation coefficients
const std::vector<Time>& rateTimes = curveState.rateTimes();
const std::vector<Time>& corrTimes = fwdCorr_->times();
for (Size i=0; i<numberOfRates_; ++i)
for (Size j=0; j<=i; ++j)
if (corrTimes[k]>rateTimes[j])
swapCorrMatrices_[k][i][j] =
swapCorrMatrices_[k][j][i] = 0.0;
}
}
示例2: nextTimeStep
bool MultiStepSwaption::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows)
{
if (currentIndex_ == startIndex_)
{
genCashFlows[0][0].timeIndex = 0;
Rate swapRate = currentState.cmSwapRate(startIndex_,endIndex_-startIndex_);
Real annuity = currentState.cmSwapAnnuity(startIndex_,startIndex_,endIndex_-startIndex_);
genCashFlows[0][0].amount =
(*payoff_)(swapRate) * annuity;
numberCashFlowsThisStep[0] =genCashFlows[0][0].amount != 0.0 ? 1 : 0 ;
return true;
}
else
{
numberCashFlowsThisStep[0] =0;
++currentIndex_;
return false;
}
}
示例3: nextTimeStep
bool MultiStepSwaption::nextTimeStep(
const CurveState ¤tState,
std::vector<Size> &numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> > &
genCashFlows) {
if (currentIndex_ == startIndex_) {
genCashFlows[0][0].timeIndex = 0;
// Rate swapRate =
// currentState.cmSwapRate(startIndex_,endIndex_-startIndex_);
// Real annuity =
// currentState.cmSwapAnnuity(startIndex_,startIndex_,endIndex_-startIndex_);
Rate swapRate =
currentState.swapRate(startIndex_, endIndex_, step_);
Real annuity = currentState.swapAnnuity(startIndex_, startIndex_,
endIndex_, step_);
genCashFlows[0][0].amount = (*payoff_)(swapRate) * annuity;
// std::max(swapRate-payoff_->strike(),0.0) * annuity; // test
numberCashFlowsThisStep[0] =
genCashFlows[0][0].amount != 0.0 ? 1 : 0;
} else {
numberCashFlowsThisStep[0] = 0;
}
++currentIndex_;
return currentIndex_ > startIndex_;
}
示例4: values
void SwapBasisSystem::values(const CurveState& currentState,
std::vector<Real>& results) const {
Size rateIndex = rateIndex_[currentIndex_-1];
results.reserve(3);
results.resize(2);
results[0] = 1.0;
results[1] = currentState.forwardRate(rateIndex);
if (rateIndex < rateTimes_.size()-2)
results.push_back(currentState.coterminalSwapRate(rateIndex+1));
}
示例5: nextStep
void BermudanSwaptionExerciseValue::nextStep(const CurveState& state) {
const Payoff& p = (*payoffs_[currentIndex_]);
Real value = state.coterminalSwapAnnuity(currentIndex_, currentIndex_) *
p(state.coterminalSwapRate(currentIndex_));
// value /= state.discountRatios()[currentIndex_];
value = std::max(value, 0.0);
cf_.timeIndex = currentIndex_;
cf_.amount = value;
++currentIndex_;
}
示例6: nextTimeStep
bool OneStepCoterminalSwaps::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows) {
std::fill(numberCashFlowsThisStep.begin(),
numberCashFlowsThisStep.end(),0);
for (Size indexOfTime=0;indexOfTime<lastIndex_;indexOfTime++) {
Rate liborRate = currentState.forwardRate(indexOfTime);
for (Size i=0;i<=indexOfTime;i++) {
genCashFlows[i][(indexOfTime-i)*2].timeIndex = indexOfTime;
genCashFlows[i][(indexOfTime-i)*2].amount =
-fixedRate_*fixedAccruals_[indexOfTime];
genCashFlows[i][(indexOfTime-i)*2+1].timeIndex = indexOfTime;
genCashFlows[i][(indexOfTime-i)*2+1].amount =
liborRate*floatingAccruals_[indexOfTime];
numberCashFlowsThisStep[i] += 2;
}
}
return true ;
}
示例7: nextTimeStep
bool MultiStepTarn::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows)
{
Rate liborRate = currentState.forwardRate(currentIndex_);
numberCashFlowsThisStep[0] =2;
genCashFlows[0][0].amount = (liborRate+floatingSpreads_[currentIndex_])*accrualsFloating_[currentIndex_];
genCashFlows[0][0].timeIndex = lastIndex_ + currentIndex_;
genCashFlows[0][1].timeIndex = currentIndex_;
Real obviousCoupon = std::max(strikes_[currentIndex_] - multipliers_[currentIndex_]*liborRate,0.0)*accruals_[currentIndex_];
couponPaid_+= obviousCoupon;
++currentIndex_;
if (couponPaid_ < totalCoupon_ && currentIndex_ < lastIndex_ )
{
genCashFlows[0][1].amount = - obviousCoupon;
return false;
}
Real coupon = obviousCoupon +(totalCoupon_ -couponPaid_);
genCashFlows[0][1].amount = - coupon;
return true;
}
示例8: nextTimeStep
bool MultiStepVolSwap::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >& genCashFlows)
{
//std::cout << "currentIndex=" << currentIndex_ << std::endl;
Rate referenceRate = currentState.swapRate(referenceRateIndices_.first, referenceRateIndices_.second, referenceRateStep_ );
for(Size i=8; i>=1; i--) referenceRateFixings_[i] = referenceRateFixings_[i-1];
referenceRateFixings_[0] = referenceRate;
Size noCf=0;
if(currentIndex_ == floatingFixingIndices_[currentFloatingIndex_]) {
Rate liborRate = currentState.forwardRate(currentFloatingIndex_);
//std::cout << "generate float payment @" << floatingPaymentIndices_[currentFloatingIndex_] << std::endl;
genCashFlows[0][noCf].timeIndex = floatingPaymentIndices_[currentFloatingIndex_];
genCashFlows[0][noCf].amount = (payer_ ? 1.0 : -1.0)*liborRate*floatingAccruals_[currentFloatingIndex_];
noCf++;
currentFloatingIndex_++;
}
if(currentIndex_ == structuredFixingIndices_[currentStructuredIndex_]) {
//std::cout << "generate structured payment @" << paymentTimes_[structuredPaymentIndices_[currentStructuredIndex_]] << std::endl;
Real volIdx = (fabs(referenceRateFixings_[1]-referenceRateFixings_[5])+
fabs(referenceRateFixings_[2]-referenceRateFixings_[6])+
fabs(referenceRateFixings_[3]-referenceRateFixings_[7])+
fabs(referenceRateFixings_[4]-referenceRateFixings_[8])) / 4.0;
genCashFlows[0][noCf].timeIndex = structuredPaymentIndices_[currentStructuredIndex_];
genCashFlows[0][noCf].amount = ( (currentStructuredIndex_== (Size)filterStructuredIndex_ || filterStructuredIndex_== -1) ? 1.0 : 0.0)*(payer_ ? -1.0 : 1.0)*structuredAccruals_[currentStructuredIndex_]*std::max(floor_,fixedRate_+multiplier_*volIdx);
//genCashFlows[0][noCf].amount = (currentIndex_==structuredFixingIndices_[0] ? 1.0 : 0.0)*std::max(referenceRate-fixedRate_,0.0)*currentState.swapAnnuity(12,12,52,2); // TEST (plain vanilla swaption payoff)
noCf++;
currentStructuredIndex_++;
}
numberCashFlowsThisStep[0] = noCf;
++currentIndex_;
bool done = (floatingFixingIndices_[currentFloatingIndex_] == QL_MAX_INTEGER && structuredFixingIndices_[currentStructuredIndex_] == QL_MAX_INTEGER );
//std::cout << "ok, finished = " << done << std::endl;
return done;
}
示例9: nextTimeStep
bool MultiStepCoterminalSwaptions::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows)
{
genCashFlows[currentIndex_][0].timeIndex = currentIndex_;
Rate swapRate = currentState.coterminalSwapRate(currentIndex_);
Real annuity = currentState.coterminalSwapAnnuity(currentIndex_, currentIndex_);
genCashFlows[currentIndex_][0].amount =
(*payoffs_[currentIndex_])(swapRate) * annuity;
std::fill(numberCashFlowsThisStep.begin(),
numberCashFlowsThisStep.end(),0);
numberCashFlowsThisStep[currentIndex_] = 1;
++currentIndex_;
return (currentIndex_ == lastIndex_);
}
示例10: nextTimeStep
bool MultiStepForwards::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows) {
Rate liborRate = currentState.forwardRate(currentIndex_);
genCashFlows[currentIndex_][0].timeIndex = currentIndex_;
genCashFlows[currentIndex_][0].amount =
(liborRate-strikes_[currentIndex_])*accruals_[currentIndex_];
std::fill(numberCashFlowsThisStep.begin(),
numberCashFlowsThisStep.end(),0);
numberCashFlowsThisStep[currentIndex_] = 1;
++currentIndex_;
return (currentIndex_ == strikes_.size());
}
示例11: values
void CustomBasisSystem::values(const CurveState& currentState,
std::vector<Real>& results) const {
results.reserve(startByCurrentIndex_.size()+1);
results.resize(1);
results[0] = 1.0;
// std::cout << "Custom basis system:" << std::endl;
for(Size i=0;i<startByCurrentIndex_.size();i++) {
results.push_back(currentState.swapRate(startByCurrentIndex_[i](currentIndex_),
endByCurrentIndex_[i](currentIndex_),
step_));
// std::cout << "rate (" << startByCurrentIndex_[i](currentIndex_) << ";" <<
// endByCurrentIndex_[i](currentIndex_) << ";" << step_ << ") " << results.back() << std::endl;
}
}
示例12: nextTimeStep
bool OneStepOptionlets::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows) {
std::fill(numberCashFlowsThisStep.begin(),
numberCashFlowsThisStep.end(), 0);
for (Size i=0; i<payoffs_.size(); ++i) {
Rate liborRate = currentState.forwardRate(i);
Real payoff = (*payoffs_[i])(liborRate);
if (payoff>0.0) {
numberCashFlowsThisStep[i] = 1;
genCashFlows[i][0].timeIndex = i;
genCashFlows[i][0].amount = payoff*accruals_[i];
}
}
return true;
}
示例13: nextStep
void LongstaffSchwartzExerciseStrategy::nextStep(
const CurveState& currentState) {
principalInNumerairePortfolio_ = newPrincipal_;
if (isRebateTime_[currentIndex_])
exercise_->nextStep(currentState);
if (isControlTime_[currentIndex_])
control_->nextStep(currentState);
if (isBasisTime_[currentIndex_])
basisSystem_->nextStep(currentState);
if (currentIndex_ < numeraires_.size()-1) {
Size numeraire = numeraires_[currentIndex_];
Size nextNumeraire = numeraires_[currentIndex_+1];
newPrincipal_ *=
currentState.discountRatio(numeraire, nextNumeraire);
}
++currentIndex_;
}
示例14: nextTimeStep
bool MarketModelPathwiseSwap::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelPathwiseMultiProduct::CashFlow> >& cashFlowsGenerated)
{
Rate liborRate = currentState.forwardRate(currentIndex_);
cashFlowsGenerated[0][0].timeIndex = currentIndex_+1;
cashFlowsGenerated[0][0].amount[0] =
(liborRate-strikes_[currentIndex_])*accruals_[currentIndex_]*multiplier_;
numberCashFlowsThisStep[0] = 1;
for (Size i=1; i <= numberRates_; ++i)
cashFlowsGenerated[0][0].amount[i] =0;
cashFlowsGenerated[0][0].amount[currentIndex_+1] = accruals_[currentIndex_]*multiplier_;
++currentIndex_;
return (currentIndex_ == strikes_.size());
}
示例15: nextTimeStep
bool MultiStepRatchet::nextTimeStep(
const CurveState& currentState,
std::vector<Size>& numberCashFlowsThisStep,
std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
genCashFlows)
{
Rate liborRate = currentState.forwardRate(currentIndex_);
Real currentCoupon = std::max(gearingOfFloor_* floor_ + spreadOfFloor_,
gearingOfFixing_* liborRate + spreadOfFixing_);
genCashFlows[0][0].timeIndex = currentIndex_;
genCashFlows[0][0].amount =
multiplier_* accruals_[currentIndex_]*currentCoupon;
//floor_ = liborRate; //StepRatchet
floor_ = currentCoupon; //FullRatchet
numberCashFlowsThisStep[0] = 1;
++currentIndex_;
return (currentIndex_ == lastIndex_);
}