Initial
This commit is contained in:
60
analytic/ZBOND.CPP
Normal file
60
analytic/ZBOND.CPP
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <analytic/zbond.hpp>
|
||||
#include <common/math.hpp>
|
||||
|
||||
ZeroCouponBond::ZeroCouponBond(void)
|
||||
{
|
||||
type(Instrument::ZeroCouponBond);
|
||||
}
|
||||
|
||||
ZeroCouponBond::ZeroCouponBond(const ZeroCouponBond &zeroCouponBond)
|
||||
{
|
||||
*this=zeroCouponBond;
|
||||
}
|
||||
|
||||
ZeroCouponBond::ZeroCouponBond(double par,const Coupon &coupon,int ytm)
|
||||
: Bond(par,coupon,ytm)
|
||||
{
|
||||
type(Instrument::ZeroCouponBond);
|
||||
}
|
||||
|
||||
ZeroCouponBond::~ZeroCouponBond()
|
||||
{
|
||||
}
|
||||
|
||||
ZeroCouponBond &ZeroCouponBond::operator=(const ZeroCouponBond &zeroCouponBond)
|
||||
{
|
||||
(Bond&)*this=(Bond&)zeroCouponBond;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOL ZeroCouponBond::operator==(const ZeroCouponBond &zeroCouponBond)const
|
||||
{
|
||||
return (Bond&)*this==(Bond&)zeroCouponBond;
|
||||
}
|
||||
|
||||
// virtuals
|
||||
|
||||
double ZeroCouponBond::discount(Rate /*yield*/)
|
||||
{
|
||||
return discount();
|
||||
}
|
||||
|
||||
double ZeroCouponBond::discount(void)
|
||||
{
|
||||
Coupon coupon(coupon());
|
||||
double bondPrice;
|
||||
int periods;
|
||||
|
||||
coupon.makeSemiAnnual();
|
||||
periods=coupon.frequency()*ytm();
|
||||
bondPrice=par()/::pow(1.00+coupon.decimalRate(),periods);
|
||||
price(bondPrice);
|
||||
return price();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user