Debug Quantlib Source code - c++

I recently started to use Quantlib in Visual Studio. I have succesfully got Quantlib installed and working. I also managed to use Quantlib to price some products such as Swap and Swaption. The Swap prices match my own VBA calculator quite well (<0.5% difference). For Swaption prices, there are some difference (around 5%). So I want to check through all the intermediate results in Quantlib to see where does this 5% difference comes from. However, I cannot debug through the Quantlib source code in my project. I think this is because my project only include the pre-built Quantlib libary and boost libary, so I can see the header files only in my project. But, I cannot put break points in the header files to debug.
Although I can manually locate the source file in the Quantlib installation folder, it doesn't help with debugging. So my question is that is there any way I can step through the Quantlib source code in my project?
For example, I am currently interested in the detail calculation steps in BlackSwaptionEngine. I just need to set up the swaption and pricing engine, and use the Quantlib NPV function to get the result:
boost::shared_ptr<Exercise> europeanExercise(new EuropeanExercise(expiryDate));
Swaption testSwaption(swap, europeanExercise);
boost::shared_ptr<PricingEngine> swaptionEngine(new BlackSwaptionEngine(forwardingTermStructure, Vol));
testSwaption.setPricingEngine(swaptionEngine);
double res = testSwaption.NPV();
Yes, I can get result. But I also want to know the intermediate result inside the BlackSwaptionEngine. So step through the source code seems to be a good way to find this out. How can I include the Quantlib source code in my project to debug?
Any help is appreciated. Many thanks.

I have managed to debug into the Quantlib source code in the end. As Luigi suggested, we need to build Quantlib in Debug mode, and then link the library and directory as this link:
quantlib.org/install/vc10.shtml
Then, we can step into the source code of Quantlib in the application project.

Related

How to use the GLOP Linear Solver with Visual Studio 2017 [C++]

I've been trying to get this to work for a while but cant figure it out for the life of me.
Here's my situation right now:
I have a Visual Studio project (and solution) up and running, and would like to modify it as little as possible. I now feel the need to use GLOP Linear solver within my project, and was wondering how I'd go about doing this.
The code that I've written that uses GLOP works perfectly as a standalone .cpp file :
[ this .cpp file is placed in the same directory as the resources for GLOP, and compiles and runs perfectly after creating and using the make command as mentioned here https://developers.google.com/optimization/introduction/cpp
]
I would now like include this code in my project, and run it as a part of my project rather than as standalone code. As I'm currently using MSVS 2017, I was wondering how I'd go about doing this as the current tricks I've used (copying and pasting all the resources for GLOP in the project folder, among other things) don't seem to be working and my error list keeps growing, and using the make commands is obviously not an option as the code needs to embedded amongst other code.
Please explain to me like I'm five years old - what files are supposed to go where, what linkages am I supposed to perform and what other.
I suppose you have already downloaded and extracted the binary archive:
or-tools_VisualStudio2017-64bit_v6.8.5452.zip
When running the make rcc command to build a C++ example, you should have spotted the needed flags to use in your project.
First you need to configure your project to add the include directory:
Configuration Properties>>VC++ Directories>>Include Directories
Then you must add some preprocessor flags e.g. -DUSE_GLOP
note: you can find here what we use in the Makefile:
Configuration Properties>>C/C++>>Preprocessor>>Preprocessor Definitions
Then add the static library libortools.lib to your linker:
Configuration Properties>>Linker>>Input
Note: Images come from various sites on the internet please adapt it.

Solving DL4J compilation error

I am trying to download DL4J source without error.
https://github.com/deeplearning4j/deeplearning4j
I cloned https://github.com/deeplearning4j/deeplearning4j.git
and imported using existing Maven project in Eclipse.
Tons of dependencies are downloaded but it's bombarded with errors.
Anyone who knows which branch version is free of compile error?
The site says 0.9.1 is most stable version, but it still generates errors.
So there's a few things here:
No major open source project in today's day and age operates without a build system. This can be maven,gradle,sbt,..
You ignored all of our docs about building from source and the like. You don't need to do that. Use the build system like it's intended.
My suggestion here:
Learn what the rest of the java world did and use maven:
Our quick start is here: http://deeplearning4j.org/quickstart
Follow our examples for the latest versions:
https://github.com/deeplearning4j/dl4j-examples
Chances are you do not need to build from source (this involves 5 other projects you probably do not want to do that) - but if you absolutely must be prepared to use c++ among other things.
The guide for that can be found here:
https://deeplearning4j.org/devguide

How to set up wxWidgets 3.1.0 with Visual Studio 2015

I am somewhat of a beginner when it comes to open source libraries. I have tried to compile from source and use the pre-built binaries, but in both cases I get a ton of errors when I try to run the simple 'Hello World' program on the tutorial section of the wxWidgets website. After playing around for quite some time, the closest I have got to compiling is by building the libraries from source, but I still have 2 errors remaining:
"_w64 can only be specified on int, long, and pointer types" file: defs.h
"cannot open file 'wxbase31ud.lib" - LINK
It seems strange to me that the header file provided by wx would have an error such as that one, so I imagine both errors are because of something I am doing. I am hoping that someone here can do one of the following for me:
Help me solve these errors
Provide instructions for building libraries from source and subsequently linking my program to the correct directories
Some additional info: I am working on x64 Windows 7, my target will also be x64 exclusively. I do not have admin privileges, so no editing the system PATH for me.
Thanks for your help!
The simplest way to start working with the library is this:
Grab the sources.
Unpack the sources.
Open VS IDE.
Open \build\msw\wx-vc14.sln (adjust as necessary.)
Go to "Build->Batch Build...", click "Select All", "Build".
Go drink some coffee or watch TV.
After the build finishes, open wxWidgets/samples/minimal/minimal_vc9.sln.
Let MSVC convert the solution to become an appropriate format.
Build and run the sample.
If you will acquire any issue during those steps, let us know.
The library build in step 5 should build without any issues and then all you will need is to build the minimal sample.
The next step is to copy the samples\minimal folder somewhere and start writing the code. All you will need to do is to change the Include and Lib search path.
[EDIT]
If you can build the 32-bit libraries (which are default in the provided solutions) all you will need is to convert them to be 64-bit and rebuild.
There is no changes to the $PATH or any environmental variable involved. Moreover you shouldn't build anything with the admin priviledges.
Also as Thomas pointed out you library build has to match whatever sample you are trying to build.
[/EDIT]

ArUco program from scratch

I'm using the ArUco library with OpenCV (more information here) but I can't find a way to build and run a program from scratch.
Once I installed the library I have access to different examples but if I want for instance to create a new file and add the library headers inside it, how can I compile and run it ? (with a command line or IDE, anything is fine)
Thank you
I sent and email to the library's author and he added clear instructions at the end of the project webpage :)
It seems you need to learn how to use your IDE's, compilation tools and general compilation basic stuff. This is not a question related to Aruco, or mostly any other tags you have set.
Try to lean CMake first, 'cause Aruco compilation is based on CMake: http://www.cmake.org/
You can start by just editing the aruco_simple example.
For a IDE that works right away with CMake you can try either Qt Creator >3.1 or KDevelop. Both free.

C++ Logging Library Setup

I've been trying for about 2 weeks now to get a logging library to work with. I've tried Log4cxx, Log4cpp, log4cplus and boost.log. The problem isn't that none of these work for me, it's that I can't figure out how to get them to work at all. I would really like to use log4cxx since I'm working with log4j/logback at work, but I haven't been able to get any of the libraries based on log4j to build. I've been able to build and use the boost library, but boost.log gives me all kinds of linker errors no matter what I try. If anyone could direct me to a step-by-step guide to get one of these libraries working I would greatly appreciate it. Also, I'm using eclipse as my IDE if that matters.
Did you ever get this working? Log4cxx definitely works on Win7. Maybe you could post some of your build errors. Just guessing, perhaps you didn't configure your eclipse project to link with a log4cxx static lib.
Boost.Log works for me quite well (Linux and Windows). It is not a header only library, there is a compiled part that you need to link against. See instructions here.
It also depends on other, non-header, Boost libraries:
The logging library uses several other Boost libraries that need
building too. These are Boost.Filesystem, Boost.System,
Boost.DateTime, Boost.Thread and Boost.Regex. Refer to their
documentation for detailed instructions on the building procedure.
Depending on your platform there may be pre-built versions of the Boost libraries. Otherwise building it yourself is straightforward if you follow the instructions. If you get stuck update your question with where exactly you got stuck and what you're seeing.
I'd recommend Pantheios. It takes some time to build everything when you first download - type make build test and go have lunch - and you have to select the output streams (Pantheios calls them "back ends") at link time, but for coding, it is really simple, e.g.
std::string name;
int age;
pantheios::log_DEBUG("name=", name, " age=", pantheios::integer(age));
It's designed from the ground up for speed - the age won't be converted into a string unless the "DEBUG" level is switched on - and robustness - which is why you can't pass fundamental types directly, and use "inserters" (e.g. pantheios::integer). See this recent blog post by Pantheios' author for more information.
I managed to get log4cxx to work, this was done in Visual Studios 2013 running on Windows 7 OS.
This following is what I did, step by step:
Download the log4cxx ZIP package extract its contents, http://logging.apache.org/log4cxx/download.html
Download apr and apr-util ZIP packages, http://apr.apache.org/download.cgi
Then
manually extract this zip apr-1.2.11-win32-src.zip (the
extracted folder should be named 'apr', if it is not manually rename
it)
manually extract this zip apr-util-1.2.10-win32-src.zip (the
extracted folder should be named 'apr-util', if it is not manually
rename it)
open a command prompt and run the following: cd
apache-log4cxx-0.10.0 configure (this
will execute configure.bat)
We will need to disable to use of the APR ICONV and LDAP support.
In order to do so, we will append the following files manually:
Open apr-util\include\apu.hw. Find the line starting with “#define
APU_HAVE_APR_ICONV”. Change the value to 0 and save.
Open apr-util\include\apr_ldap.hw. Find the line starting with
“#define APR_HAS_LDAP” Change the value to 0 and save.
We need to build the log4cxx.dll, to do so convert *.dsw
to *.cxproj.
Launch Visual Studio 2013 and open log4cxx.dsw.
VS will ask if you like to convert everything. Simply click Yes.
There may be some warnings in the migration report, but nothing that
should prevent the solution from opening.
> The projects xml, apr, and apr-util should build successfully.
If you try compiling the log4cxx project it will most
likely fail with hundreds of errors. This is due to a bug in VC++
which can be worked around.
Move all macros outside (above) the class they are in.
LOG4CXX_LIST_DEF macro is used to define classes. All macros reported in error C2252 will need to move out of any classes. This
may also include moving definitions which are used in the macro.
Next, change all LoggingEvent::KeySet to KeySet (this is no longer nested in a parent class)
> Following this, the log4cxx project should now compile
successfully on your machine.