// Copyright (C) 2009 Bojan Nikolic <bojan@bnikolic.co.uk>
//
// LICENSE TERMS
//
// Licensor of this file is BN Algorithms Limited, UK. Licensed for
// on-screen viewing on your computer only. Distribution
// prohibited. This file is provided "as-is", without warranty of any
// kind, either expressed or implied, including, without limitation,
// warranties that the program is free of defects, merchantable, fit
// for a particular purpose or non-infringing. The entire risk as to
// the quality of the documentation is with you. Should this file
// prove defective in any respect, you (not the licensor) assume the
// cost of any necessary correction. This disclaimer of warranty
// constitutes an essential part of this license.
//
#include <iostream>
#include <boost/format.hpp>
#include <boost/array.hpp>
#include "bncds/cds.hpp"
#include "bncds/irconstr.hpp"
#include "bncds/spread.hpp"
#include "bncds/discount.hpp"
#include "bncds/pricing.hpp"
#include "isda/ldate.h"
void example(std::ostream &os)
{
const TDate baseDate = JpmcdsDate(2008, 1, 3);
const TDate today = JpmcdsDate(2008, 2, 1);
const TDate valueDate = JpmcdsDate(2008, 2, 1);
const TDate startDate = JpmcdsDate(2008, 2, 8);
const TDate endDate = JpmcdsDate(2008, 2, 12);
const TDate stepinDate = JpmcdsDate(2008, 2, 9);
const double notional = 1e7;
BNCDS::Spread spread(3600.0/1e4,
0.4);
BNCDS::jw::Curve flatzero(BNCDS::mkStdFlatCurve(baseDate,
1e-9));
BNCDS::Discount discount(flatzero);
BNCDS::SimpleStdCDS cds(startDate,
endDate,
0);
boost::array<double,3> coupons = { { 0, 3600, 7200 } };
for (size_t i=0; i < coupons.size(); ++i)
{
cds.couponr=coupons[i]/1e4;
const double charge = BNCDS::PV(today,
valueDate,
stepinDate,
cds,
spread,
discount);
std::cout<<std::endl
<<boost::format("Upfront charge @ cpn = %ibps = %f")
% coupons[i]
% (charge * notional);
}
std::cout<<std::endl<<std::endl;
}
int main(int argc,
char** argv)
{
example(std::cout);
}