Sunday, January 24, 2016

QuantLib in C++

QuantLib is an open-source C++ Library for quantitative analysis in Finance, and the QuantLib project was started by a few Quants in 2000. Now QuantLib project is Luigi Ballabio and ferninando Ametrano.

Secondly, QuantLib has been ported to other languages:

    R: RQuantLib
    Python: PyQL
    Java: JQuantLib
    Excel: QuantLibXL provides a very good API Doc, but you may still want to take a look at other sources for API documents. The following is a short list of links for QuantLib API Docs.

QuantLib SourceCodeBrowser
QuantLib Java API Docs
QuantLib API Docs generated by Doxygen(v0.3.4)
Implementing QuantLib
C++ Design Patterns and Derivatives Pricing 2e
QuantLib on YouTube

In addition, some commercial software products are also available: QRM, FinCAD, Numerix, SunGard-FastVal, Savvysoft, Quantifi, Pricing Partners Cie, Bloomberg, Intex.

Saturday, January 9, 2016

Print a float or double in C++?

#include <iostream>
#include <bitset>
#include <cassert>

using namespace std;

int main(void)
const int n = sizeof(float)* 8; //32 bits
float f = 975.75;
unsigned int u;
assert(sizeof(f) == sizeof(u));
std::memcpy(&u, &f, sizeof(f));
std::cout << n << ": " << bitset<n>(u) << endl;
//32: 01000100011100111111000000000000

const int nd = sizeof(double)* 8;
double d = 975.75;
unsigned long long ull;
assert(sizeof(d) == sizeof(ull));
std::memcpy(&ull, &d, sizeof(d));
std::cout << nd << ": " << bitset<nd>(ull) << endl;
//64: 0100000010001110011111100000000000000000000000000000000000000000

return 0;

To confirm the conversion, please check out: