#include #include Instrument::Instrument(Type type) : mPrice(0.00), mType(type) { } Instrument::Instrument(const Instrument &instrument) { *this=instrument; } Instrument::~Instrument() { } BOOL Instrument::operator==(const Instrument &instrument)const { return (price()==instrument.price()&& coupon()==instrument.coupon()&& type()==instrument.type()); } Instrument &Instrument::operator=(const Instrument &instrument) { price(instrument.price()); coupon(instrument.coupon()); type(instrument.type()); return *this; } double Instrument::price(void)const { return mPrice; } void Instrument::price(double price) { mPrice=price; } const Coupon &Instrument::coupon(void)const { return mCoupon; } void Instrument::coupon(const Coupon &coupon) { mCoupon=coupon; } Instrument::Type Instrument::type(void)const { return mType; } void Instrument::type(Type type) { mType=type; } // **** virtuals double Instrument::par(void)const { return 0.00; } BOOL Instrument::cashflows(GlobalData &cashflows) { cashflows.size(0); return cashflows.size(); } double Instrument::fv(int periods) { Coupon ac(mCoupon); ac.makeAnnual(); return price()*::pow(1.00+(ac.rate()/100.00)/ac.frequency(),ac.frequency()*periods); } double Instrument::discount(double fv,int periods) { Coupon ac(mCoupon); ac.makeAnnual(); price(fv*(1.00/::pow(1+ac.rate()/100.00,periods))); return price(); }