Update of /cvsroot/quantlibaddin/QuantLibAddin/qlo
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv21901/qlo
Modified Files:
capfloor.cpp capfloor.hpp couponvectors.cpp couponvectors.hpp
swap.cpp swap.hpp
Log Message:
BPS, NPV, analysis functions/methods for Swap, VanillaSwap, and CashFlowStream
Index: couponvectors.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/couponvectors.hpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** couponvectors.hpp 12 Oct 2006 10:51:30 -0000 1.26
--- couponvectors.hpp 18 Oct 2006 20:11:37 -0000 1.27
***************
*** 22,58 ****
#include <oh/objhandler.hpp>
#include <qlo/schedule.hpp>
#include <qlo/index.hpp>
! #include <ql/CashFlows/cashflowvectors.hpp>
! #include <ql/CashFlows/simplecashflow.hpp>
! #include <ql/CashFlows/cmscoupon.hpp>
#include <ql/CashFlows/conundrumpricer.hpp>
- #include <ql/CashFlows/analysis.hpp>
namespace QuantLibAddin {
! typedef std::vector<boost::shared_ptr<QuantLib::CashFlow> > Leg;
!
! std::vector<std::vector<boost::any> > flowAnalysis(Leg);
!
! class LegWrapper : public ObjHandler::Object {
! public:
! double getBPS(
! const QuantLib::Handle<QuantLib::YieldTermStructure>& h) const;
const Leg& getVector();
- const std::vector<std::vector<boost::any> > getLeg()
- {
- return flowAnalysis(cashFlowVector_);
- }
protected:
Leg cashFlowVector_;
};
! class SimpleCashFlow : public LegWrapper {
public:
SimpleCashFlow(double amount, const QuantLib::Date& date);
};
! class SimpleCashFlowVector : public LegWrapper {
public:
SimpleCashFlowVector(const std::vector<double> amounts,
--- 22,50 ----
#include <oh/objhandler.hpp>
+
#include <qlo/schedule.hpp>
#include <qlo/index.hpp>
! #include <qlo/analysis.hpp>
!
#include <ql/CashFlows/conundrumpricer.hpp>
namespace QuantLibAddin {
! class CashFlowStream : public ObjHandler::Object {
! public:
! QuantLib::Real npv(const QuantLib::Handle<QuantLib::YieldTermStructure>&) const;
! QuantLib::Real bps(const QuantLib::Handle<QuantLib::YieldTermStructure>&) const;
! std::vector<std::vector<boost::any> > analysis() const;
const Leg& getVector();
protected:
Leg cashFlowVector_;
};
! class SimpleCashFlow : public CashFlowStream {
public:
SimpleCashFlow(double amount, const QuantLib::Date& date);
};
! class SimpleCashFlowVector : public CashFlowStream {
public:
SimpleCashFlowVector(const std::vector<double> amounts,
***************
*** 60,64 ****
};
! class FixedRateCouponVector : public LegWrapper {
public:
FixedRateCouponVector(
--- 52,56 ----
};
! class FixedRateCouponVector : public CashFlowStream {
public:
FixedRateCouponVector(
***************
*** 70,74 ****
};
! class FloatingRateCouponVector : public LegWrapper {
public:
FloatingRateCouponVector(
--- 62,66 ----
};
! class FloatingRateCouponVector : public CashFlowStream {
public:
FloatingRateCouponVector(
***************
*** 95,99 ****
};
! class CMSCouponVector : public LegWrapper {
public:
CMSCouponVector(
--- 87,91 ----
};
! class CMSCouponVector : public CashFlowStream {
public:
CMSCouponVector(
***************
*** 114,118 ****
};
! class CMSZeroCouponVector : public LegWrapper {
public:
CMSZeroCouponVector(
--- 106,110 ----
};
! class CMSZeroCouponVector : public CashFlowStream {
public:
CMSZeroCouponVector(
***************
*** 133,137 ****
};
! class CMSInArrearsCouponVector : public LegWrapper {
public:
CMSInArrearsCouponVector(
--- 125,129 ----
};
! class CMSInArrearsCouponVector : public CashFlowStream {
public:
CMSInArrearsCouponVector(
***************
*** 155,157 ****
#endif
-
--- 147,148 ----
Index: couponvectors.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/couponvectors.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** couponvectors.cpp 13 Oct 2006 10:53:59 -0000 1.37
--- couponvectors.cpp 18 Oct 2006 20:11:37 -0000 1.38
***************
*** 27,166 ****
#include <qlo/typefactory.hpp>
! #include <ql/CashFlows/fixedratecoupon.hpp>
! #include <ql/CashFlows/floatingratecoupon.hpp>
! #include <ql/CashFlows/parcoupon.hpp>
!
namespace QuantLibAddin {
! std::vector<std::vector<boost::any> > flowAnalysis(Leg cashflows)
! {
! std::vector<std::vector<boost::any> > flowAnalysis_;
!
! QuantLib::Size numberOfColumn = 20;
!
! std::vector<boost::any> headings(numberOfColumn);
! headings[0]=std::string("Payment Date");
! headings[1]=std::string("Amount");
!
! headings[2]=std::string("Nominal");
! headings[3]=std::string("Accrual Start Date");
! headings[4]=std::string("Accrual End Date");
! headings[5]=std::string("Accrual Days");
! headings[6]=std::string("Day Counter");
! headings[7]=std::string("Accrual Period");
! headings[8]=std::string("Effective Rate");
!
! headings[ 9]=std::string("Fixing Days");
! headings[10]=std::string("Fixing Dates");
! headings[11]=std::string("Index");
! headings[12]=std::string("Floor");
! headings[13]=std::string("Gearing");
! headings[14]=std::string("Index Fixing");
! headings[15]=std::string("Conv. Adj.");
! headings[16]=std::string("Spread");
! headings[17]=std::string("Cap");
! headings[18]=std::string("---");
! headings[19]=std::string("---");
!
! flowAnalysis_.push_back(headings);
!
! for(QuantLib::Size i=0; i<cashflows.size(); i++)
! {
! std::vector<boost::any> cf(numberOfColumn, std::string("N/A"));
! cf[0]=cashflows[i]->date().serialNumber();
! try {
! cf[1]=cashflows[i]->amount();
! } catch(...) {
! }
! boost::shared_ptr<QuantLib::SimpleCashFlow> simpleCashFlow =
! boost::dynamic_pointer_cast<QuantLib::SimpleCashFlow>(cashflows[i]);
! if (simpleCashFlow) {
! flowAnalysis_.push_back(cf);
! continue;
! }
!
! boost::shared_ptr<QuantLib::Coupon> c =
! boost::dynamic_pointer_cast<QuantLib::Coupon>(cashflows[i]);
! QL_REQUIRE(c, "error processing cash flow vector - unable to convert item #" << i <<
! " to an object of class QuantLib::Coupon")
! cf[2]=c->nominal();
! cf[3]=c->accrualStartDate().serialNumber();
! cf[4]=c->accrualEndDate().serialNumber();
! cf[5]=c->accrualDays();
! cf[6]=c->dayCounter().name();
! cf[7]=c->accrualPeriod();
! try {
! cf[8]=c->rate();
! } catch(...) {
! }
! boost::shared_ptr<QuantLib::FloatingRateCoupon> floatingCoupon =
! boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon>(
! cashflows[i]);
! boost::shared_ptr<QuantLib::CMSCoupon> cmsCoupon =
! boost::dynamic_pointer_cast<QuantLib::CMSCoupon>(
! cashflows[i]);
! if (cmsCoupon!=0) {
! cf[ 9]=cmsCoupon->fixingDays();
! cf[10]=cmsCoupon->fixingDate().serialNumber();
! cf[11]=cmsCoupon->index()->name();
! cf[12]=cmsCoupon->floor();
! cf[13]=cmsCoupon->gearing();
! try {
! cf[14]=cmsCoupon->indexFixing();
! } catch(...) {
! }
! try {
! cf[15]=cmsCoupon->convexityAdjustment();
! }
! catch(...) {
! }
! cf[16]=cmsCoupon->spread();
! cf[17]=cmsCoupon->cap();
! } else if (floatingCoupon!=0) {
! cf[ 9]=floatingCoupon->fixingDays();
! cf[10]=floatingCoupon->fixingDate().serialNumber();
! cf[11]=floatingCoupon->index()->name();
! cf[12]=std::string("N/A");
! cf[13]=floatingCoupon->gearing();
! try {
! cf[14]=floatingCoupon->indexFixing();
! } catch(...) {
! }
! try {
! cf[15]=floatingCoupon->convexityAdjustment();
! } catch(...) {
! }
! cf[16]=floatingCoupon->spread();
! cf[17]=std::string("N/A");
! }
! flowAnalysis_.push_back(cf);
! }
! return flowAnalysis_;
}
! double LegWrapper::getBPS(const QuantLib::Handle<
! QuantLib::YieldTermStructure>& hYTS) const
! {
return QuantLib::Cashflows::bps(cashFlowVector_, hYTS);
}
! const Leg& LegWrapper::getVector()
! {
return cashFlowVector_;
}
!
! SimpleCashFlow::SimpleCashFlow(double amount, const QuantLib::Date& date)
! {
! cashFlowVector_.push_back(boost::shared_ptr<QuantLib::CashFlow>(new QuantLib::SimpleCashFlow(amount,date)));
}
! SimpleCashFlowVector::SimpleCashFlowVector(const std::vector<double> amounts,
const std::vector<QuantLib::Date>& dates)
{
for (QuantLib::Size i=0; i < amounts.size(); i++) {
cashFlowVector_.push_back(boost::shared_ptr<QuantLib::CashFlow>(
! new QuantLib::SimpleCashFlow(amounts[i],dates[i])));
}
}
--- 27,63 ----
#include <qlo/typefactory.hpp>
! #include <ql/CashFlows/cashflowvectors.hpp>
! #include <ql/CashFlows/simplecashflow.hpp>
! #include <ql/CashFlows/cmscoupon.hpp>
namespace QuantLibAddin {
! double CashFlowStream::npv(const QuantLib::Handle< QuantLib::YieldTermStructure>& hYTS) const {
! return QuantLib::Cashflows::bps(cashFlowVector_, hYTS);
}
! double CashFlowStream::bps(const QuantLib::Handle< QuantLib::YieldTermStructure>& hYTS) const {
return QuantLib::Cashflows::bps(cashFlowVector_, hYTS);
}
+ std::vector<std::vector<boost::any> > CashFlowStream::analysis() const {
+ return flowAnalysis(cashFlowVector_);
+ }
! const Leg& CashFlowStream::getVector() {
return cashFlowVector_;
}
!
! SimpleCashFlow::SimpleCashFlow(double amount, const QuantLib::Date& date) {
! cashFlowVector_.push_back(boost::shared_ptr<QuantLib::CashFlow>(new
! QuantLib::SimpleCashFlow(amount,date)));
}
! SimpleCashFlowVector::SimpleCashFlowVector(const std::vector<double> amounts,
const std::vector<QuantLib::Date>& dates)
{
for (QuantLib::Size i=0; i < amounts.size(); i++) {
cashFlowVector_.push_back(boost::shared_ptr<QuantLib::CashFlow>(
! new QuantLib::SimpleCashFlow(amounts[i],dates[i])));
}
}
***************
*** 172,176 ****
const std::vector<double>& couponRates,
const QuantLib::DayCounter& dayCount)
! {
cashFlowVector_ = QuantLib::FixedRateCouponVector(*schedule,
convention,
--- 69,73 ----
const std::vector<double>& couponRates,
const QuantLib::DayCounter& dayCount)
! {
cashFlowVector_ = QuantLib::FixedRateCouponVector(*schedule,
convention,
Index: capfloor.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/capfloor.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** capfloor.cpp 13 Oct 2006 18:41:48 -0000 1.10
--- capfloor.cpp 18 Oct 2006 20:11:37 -0000 1.11
***************
*** 28,32 ****
CapFloor::CapFloor(
QuantLib::CapFloor::Type type,
! const boost::shared_ptr<LegWrapper>& floatingLegWrapper,
const std::vector<QuantLib::Rate>& strikes,
const QuantLib::Handle<QuantLib::YieldTermStructure>& termStructure,
--- 28,32 ----
CapFloor::CapFloor(
QuantLib::CapFloor::Type type,
! const boost::shared_ptr<CashFlowStream>& floatingLegWrapper,
const std::vector<QuantLib::Rate>& strikes,
const QuantLib::Handle<QuantLib::YieldTermStructure>& termStructure,
Index: capfloor.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/capfloor.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** capfloor.hpp 13 Oct 2006 18:41:48 -0000 1.9
--- capfloor.hpp 18 Oct 2006 20:11:37 -0000 1.10
***************
*** 29,33 ****
public:
CapFloor(QuantLib::CapFloor::Type type,
! const boost::shared_ptr<LegWrapper>& floatingLegWrapper,
const std::vector<QuantLib::Rate>& strikes,
const QuantLib::Handle<QuantLib::YieldTermStructure>& termStructure,
--- 29,33 ----
public:
CapFloor(QuantLib::CapFloor::Type type,
! const boost::shared_ptr<CashFlowStream>& floatingLegWrapper,
const std::vector<QuantLib::Rate>& strikes,
const QuantLib::Handle<QuantLib::YieldTermStructure>& termStructure,
Index: swap.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/swap.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** swap.cpp 5 Oct 2006 14:42:51 -0000 1.15
--- swap.cpp 18 Oct 2006 20:11:37 -0000 1.16
***************
*** 29,34 ****
namespace QuantLibAddin {
! Swap::Swap(const boost::shared_ptr<LegWrapper>& paidLegWrapper,
! const boost::shared_ptr<LegWrapper>& recvLegWrapper,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS)
{
--- 29,34 ----
namespace QuantLibAddin {
! Swap::Swap(const boost::shared_ptr<CashFlowStream>& paidLegWrapper,
! const boost::shared_ptr<CashFlowStream>& recvLegWrapper,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS)
{
***************
*** 39,43 ****
}
! Swap::Swap(const std::vector<boost::shared_ptr<LegWrapper> >& legWrappers,
const std::vector<bool>& payer,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS) {
--- 39,43 ----
}
! Swap::Swap(const std::vector<boost::shared_ptr<CashFlowStream> >& legWrappers,
const std::vector<bool>& payer,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS) {
***************
*** 54,60 ****
boost::shared_ptr<QuantLib::Swap> temp;
getLibraryObject(temp);
! const std::vector<boost::shared_ptr<QuantLib::CashFlow> >& cashflows =
! temp->leg(i);
! return flowAnalysis(cashflows);
}
--- 54,58 ----
boost::shared_ptr<QuantLib::Swap> temp;
getLibraryObject(temp);
! return flowAnalysis(temp->leg(i));
}
Index: swap.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/swap.hpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** swap.hpp 5 Oct 2006 14:42:51 -0000 1.12
--- swap.hpp 18 Oct 2006 20:11:37 -0000 1.13
***************
*** 30,37 ****
class Swap : public Instrument {
public:
! Swap(const boost::shared_ptr<LegWrapper>& paidLegWrapper,
! const boost::shared_ptr<LegWrapper>& recvLegWrapper,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS);
! Swap(const std::vector<boost::shared_ptr<LegWrapper> >& legWrappers,
const std::vector<bool>& payer,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS);
--- 30,37 ----
class Swap : public Instrument {
public:
! Swap(const boost::shared_ptr<CashFlowStream>& paidLegWrapper,
! const boost::shared_ptr<CashFlowStream>& recvLegWrapper,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS);
! Swap(const std::vector<boost::shared_ptr<CashFlowStream> >& legWrappers,
const std::vector<bool>& payer,
const QuantLib::Handle<QuantLib::YieldTermStructure>& hYTS);
|