http://www.bnikolic.co.uk/blog/blogBojan's Blog
A blog on various computing related items by Bojan Nikolic. See
http://www.bnikolic.co.uk/blog/index.html .
2012-04-23T09:28:37ZBojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/ql-fx-option-simple.htmlA simple FX-Option Example in QuantLib<paragraph>Here is a simple, bare-bones example of pricing an American FX vanilla
option in QuantLib:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-05T20:48:50Zhttp://www.bnikolic.co.uk/blog/website-comments-disqus.htmlComments now available on this blog<paragraph>I have added a commenting capability on this blog, using the <reference name="disqus" refuri="http://www.disqus.com">disqus</reference> system. Initially the comments will be
un-moderated. Hopefully they will be useful and there won't be too
much spam. I look forward to hearing from the readers!</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-10-23T19:01:05Zhttp://www.bnikolic.co.uk/blog/ql-fitting-with-constraints.htmlConstrained fitting in QuantLib<paragraph>Below is a short example illustrating fitting of a function to
observables, demonstrating also how to put some constraints on the
parameters. Placing such constraints is useful when, for example, a
model is well defined for certain values of the parameters.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/gprs-e61-linux-greece.htmlAccessing Internet in Greece using Linux, Nokia E61, and a Vodafone data plan contract<paragraph>The aim is to be able to connect my laptop to the Internet over the
cellular/wireless networks in Greece at a reasonable price and speed.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-02-05T22:16:52Zhttp://www.bnikolic.co.uk/blog/cpp-lazy-expression-templ.htmlLazy Code Generation (LzCG) and C++ Expression Templates<paragraph>I've been thinking recently about strategies for writing fast
numerical codes based on C++. One of the ideas I have been pursuing is
generating the code for the some of the performance critical sections
after the compilation of the main body of the code. The summary of the
idea is:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/ql-ontop-bzr.htmlManaging QuantLib source using Bazaar<paragraph><reference name="QuantLib" refuri="http://quantlib.org">QuantLib</reference> is an open source project providing a comprehensive
software framework for quantitative finance. It is developed in an
open way by discussion on mailing lists and the source code is manged
in a centralised <reference name="QuantLib SVN repository" refuri="http://quantlib.svn.sourceforge.net/viewvc/quantlib/">QuantLib SVN repository</reference>. In this article I discuss
how to efficiently manage non-public modifications to the source code
tree of this project. These modifications could, for example, be
patches that are not yet ready for a public review and integration in
the central source code tree; or they could be modifications intended
as permanently private extensions of the QuantLib functionality.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-05-23T11:36:55Zhttp://www.bnikolic.co.uk/blog/boostcon2011-reports.htmlBoostCon 2011 Report<paragraph>I've just got back from the <reference name="BoostCon 2011" refuri="http://boostcon.boost.org/">BoostCon 2011</reference> meeting at Aspen, CO. It was my first
time at this conference and I was very impressed by the high quality
of presentations and discussions at the conference.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-02-04T05:00:24Zhttp://www.bnikolic.co.uk/blog/cpp-map-interp.htmlMaking use of std::map<> ordered property: interpolation<paragraph>The <reference name="Map" refuri="http://www.sgi.com/tech/stl/Map.html">Map</reference> container of the
C++ Standard template library is an <emphasis>ordered</emphasis> associative
container. Often it is used simply for associative property, i.e., to
look up a value based on a key. However, the ordered property can
often be useful to and the classic example is in one-dimensional
interpolation.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-boost-rand-normal.htmlGenerating Normally Distributed Random Numbers Using Boost<paragraph>One of my <reference name="previous" refuri="cpp-rr-rand-normal.html">previous</reference> posts describes a very minimal program that
generates a normally distributed random number using <reference name="Boost" refuri="http://www.boost.org/doc/libs">Boost</reference>. However,
I've realised from the number of people visiting that this example may
indeed be a bit too short and simple, and lead people to not exactly
the best practises. So here is a longer post with more pointers.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-04-20T17:15:20Zhttp://www.bnikolic.co.uk/blog/cpp-expression-minimal.htmlA Simple, Minimal, Example of C++ Expression Templates<paragraph>I am preparing a lecture on efficient numerical computation in C++ and
this obviously touches upon the technique expression template. I came
up with the following, very stripped-down, example which still manages
to illustrate expression templates are in general far more efficient
than normal C++ value semantics.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/python-tips-switch.htmlPython: To Switch or not to Switch<paragraph>It is easy to fall into the trap of writing <literal>switch</literal> like statements
in any programing language. (<literal>switch</literal> is a construct in C and C++;
in python it can be replicated by a string of <literal>elif</literal> statements.)
Often, for example, this occurs at the interface between applications
and libraries. In Python these look something like the following
frivolous example:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/python-windows-setup.htmlSetting up Python on Win32 platform<paragraph>Here are just the links... this is work in progress:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-05-17T16:56:49Zhttp://www.bnikolic.co.uk/blog/boostcon2011-hybrid-mpi-openmp.htmlFrom BoostCon 2011 -- Bulk Synchronous Parallelism using Hybrid MPI+OpenMP<paragraph>An interesting approach to implementing structured parallel algorithms
in C++ presented today by Joel Falcou. The performance appears to be
close to hand-coded algorithms and it should be reasonably easy to
use. However, it currently needs at an external analysis stage based
on a plug-in to clang.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-04-05T14:28:36Zhttp://www.bnikolic.co.uk/blog/inmin-runtimecompile-r.htmlRuntime compilation in InMin of functions to be minimised<paragraph>With help from the <reference name="tinycc" refuri="http://repo.or.cz/w/tinycc.git">tinycc</reference>
compiler project, the InMin library can now compile, at-runtime, a
function to minimise from its string representation in a C-like
language.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-about.htmlRR: About the Random Review Series<paragraph>The aim of the <emphasis>random review</emphasis> series articles is to do a sort of
public code-review of C++ code, generally in the field of numerical
algorithms. I do not publish the names of original codes to which
review articles relate because the hope is that they will be
applicable much more widely than the original codes.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-05-17T16:50:33Zhttp://www.bnikolic.co.uk/blog/boostcon2011-geneva-library.htmlFrom BoostCon 2011 -- The Geneva Optimisation library<paragraph>The library was presented here at the conference -- it allows
parametric optimisation using evolutionary and particle swarm
algorithms using efficient parallel execution across many cores and
nodes. The only external dependency is Boost!</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-derived-class-assignment.htmlDerived classes still have a default assignment operator<paragraph>If a class does not declare an explicit assignment operator
(<literal>operator=()</literal>), a default operator will be created by the C++
compiler which will copy over each of the data members of the class. A
class can (and often they do) override this behaviour by declaring the
assignment operator. If a class derives from a base class with a
non-default assignment operator, but does not have an assignment
operator <emphasis>itself</emphasis>, the C++ compiler will still create a default
operator which copies the members of the derived (but <emphasis>not</emphasis> the base)
class.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-15T18:24:30Zhttp://www.bnikolic.co.uk/blog/ql-java-clojure-loader.htmlUsing QuantLib from Clojure<paragraph>We've recently begun developing applications in the <reference name="Clojure" refuri="http://clojure.org">Clojure</reference> language that make use of the QuantLib
libraries through the Java bindings (see for example <reference name="here" refuri="http://www.bnikolic.co.uk/ql/java.html">here</reference>). Using Clojure has
substantial advantages about which I hope to write more about later,
but in the mean time here is how to overcome an initial problem.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-08-20T00:52:47Zhttp://www.bnikolic.co.uk/blog/ql-heston-implementation.htmlImplementation of the Heston model in QuantLib<paragraph>The <reference name="QuantLib" refuri="http://quantlib.org/index.shtml">QuantLib</reference> derivatives pricing
library provides an algorithm for "analytic" pricing of European-style
options under the Heston model. The description "analytic" is
conventional but not very precise as the algorithm in fact involves
numerical evaluation of an integral. There is however no stepping in
time in this algorithm, and so it is certainly distinct from the
finite-difference methods that are used to price path-dependent
options.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-boost-simple-parse.htmlSimple input parsing using Boost<paragraph>Inexperienced programmers often get stuck getting data into their C++
program and with output out of their program. Somewhat more
experienced programmers often use clunky routines from the Standard C
library such as <literal>strtok</literal>, <literal>atof</literal> and friends. I think pretty much
everybody agrees that plain C++ does not provide for elegant parsing
of simple input data. Fortunately the Boost libraries provide lots of
tools to tackle this, and here is a very simple example.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/ql-brownian-bridge.htmlUsing QuantLib to generate a Brownian Bridge<paragraph>This is a very short article illustrating how to use the QuantLib
library Brownian bridge code. The reason there can be some confusion
is that the code takes a sequence of random variates as input for the
bridge construction code. The first variate in this sequence is taken
to represent the global step of the bridge, i.e., how much the value
of the underlying changes over the entire period (for bridge of length
of <strong>unit</strong> time only). If the first variate is set to zero, then the
standard Brownian bridge that begins and ends at zero will be created.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-memory-vector.htmlRR: std::vector<> instead of new[]<paragraph>One of the trickiest concepts for beginners in C++ (and other
languages with low-level capability) is memory management, i.e.,
correct allocation and de-allocation of memory. I already discussed
that in some cases memory management can be <reference name="avoided" refuri="cpp-rr-memory-alloc1.html">avoided</reference>, but of course at
some point in the program memory allocation does need to be made. Here
I discuss using the standard library <literal>std::vector<></literal> container
instead of the plain <literal>new[]</literal> and the advantages this approach gives.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-11-06T18:59:16Zhttp://www.bnikolic.co.uk/blog/bn-internships-2011.htmlOpportunities for (remote-working) internships with BN Algorithms<paragraph>We are currently looking to take on one or two interns to work with us
for a period ranging from six weeks to six months. We are looking for
people with following skills:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-09-15T16:03:58Zhttp://www.bnikolic.co.uk/blog/inmin-v01-announce.htmlVersion 0.1 of InMin library<paragraph>Version 0.1 of the InMin library has just been <reference name="released" refuri="../inmin/inmin-library.html">released</reference>.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-07-05T16:24:35Zhttp://www.bnikolic.co.uk/blog/cpp-swig-pointeraccess.htmlC++ & SWIG: using data pointed to by a pointer<paragraph><reference name="SWIG" refuri="http://www.swig.org/">SWIG</reference> is an excellent, widely used, tool for
wrapping C and C++ libraries for use in higher level
languages. Learning how to best use SWIG is, as is true with all
programming languages, <reference name="not trivial" refuri="http://norvig.com/21-days.html">not trivial</reference>.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-01-06T20:23:43Zhttp://www.bnikolic.co.uk/blog/inmin-v02-announce.htmlVersion 0.2 of InMin library<paragraph>I am happy to announce version 0.2 of the InMin library (<reference name="see" refuri="../inmin/inmin-library.html">see</reference>).</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-07-26T09:00:12Zhttp://www.bnikolic.co.uk/blog/ql-bumping-curve.htmlBumping Interest Rate Curves in QuantLib<paragraph>The QuantLib library implements the <literal>Observer</literal> pattern in many of
its data structures and functions. This means that a link to data used
to build objects such as interest curves is retained and if this input
data is changed after the construction of the curve the curve itself
is automatically updated. This means that bumping the curve is
easy since it is not necessary to explicitly rebuild the curves.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-boost-uniform01.htmlA potential pitfall when using boost::uniform_01<paragraph>The <reference name="Boost" refuri="http://www.boost.org/doc/libs/1_35_0">Boost</reference> library collection has a highly useful <reference name="random number library (Boost.Random)" refuri="http://www.boost.org/doc/libs/1_35_0/libs/random/index.html">random number
library (Boost.Random)</reference>. One
of the classes in this library, <literal>boost::uniform_01</literal>, does however
present a potential pitfall which I will briefly describe in this
post. This pitfall is mentioned briefly in the library documentation
but this post expands on this substantially.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-10-25T18:42:54Zhttp://www.bnikolic.co.uk/blog/nqm-project.htmlNumerical and Quantitative methods in C++ project<paragraph>I've started on a new long-term project which not only by its nature
can not be finished, but it is likely to progress quite slowly: a
web-book which gives solutions to some popular numerical/quantitative
problems in C++.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/website-atom.htmlGenerating Atom feeds using Python and KID<paragraph>The <reference name="Atom" refuri="http://tools.ietf.org/html/rfc4287">Atom</reference> syndication format is the standard way of making others
aware of changes to your web-site, in particular to new content on the
website. <reference name="Atom" refuri="http://tools.ietf.org/html/rfc4287">Atom</reference> is based on XML and <reference name="Atom" refuri="http://tools.ietf.org/html/rfc4287">Atom</reference> feeds can be produced very
simply and conveniently using <reference name="Kid" refuri="http://www.kid-templating.org/index.html">Kid</reference> and of course Python. Here is on
outline on how to do it.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rand-parallel.htmlGenerating Random in Parallel<paragraph>The classic requirement for this a large Monte-Carlo simulation which
you'd like to be able to run across many threads in production, but at
the same time would always like to get exactly the same answer
regardless of the number of threads that are used. In other words,
the exact numerical answer should be exactly the same across multiple
runs and independently of the number of threads.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/website-simple.htmlCreating simple websites<paragraph>This website is written primarily in <reference name="re-structured text" refuri="http://docutils.sourceforge.net/rst.html">re-structured text</reference><target ids="re-structured-text" names="re-structured\ text" refuri="http://docutils.sourceforge.net/rst.html" />, a simple text markup
language. It is produced to final html form using the following tools:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-05-13T15:02:26Zhttp://www.bnikolic.co.uk/blog/ql-date-io-simple.htmlSimple examples of Date input/output in QuantLib<paragraph>Following a discussion on the QuantLib users mailing list, here is a
quick and very short program illustrating input and output of Date
objects in QuantLib:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-07-17T20:15:16Zhttp://www.bnikolic.co.uk/blog/ql-heston-simple.htmlPricing options using the Heston model using QuantLib<paragraph>Bellow is a simple command line program which uses the Heston model
implementation in QuantLib to price equity options. The various
parameters of the Heston model can be adjusted through the command
line. For a list of these, run the program with the ''--help'' option:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-07T16:20:38Zhttp://www.bnikolic.co.uk/blog/cpp-swig-featureinheritance.htmlFeature inheritance in SWIG -- doesn't apply to classes...<paragraph>The excellent <reference name="SWIG" refuri="http://www.swig.org/">SWIG</reference> package has a number of
mechanisms for modifying the interfaces which are generated by initial
parse of the original C/C++. One of these mechanism are <emphasis>features</emphasis>
(see <reference name="here" refuri="http://www.swig.org/Doc2.0/Customization.html#Customization_features">here</reference>
for basic explanation). Various output language modules know about
different <emphasis>features</emphasis> that the user can specify and they interpret them
in a particular way that is appropriate for that language.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-boost-bind-not-struct-error.htmlErrors like "is not a class, struct, or union type" when using <paragraph>Decoding compile-time errors when using complex template libraries
(like <reference name="Boost" refuri="http://www.boost.org/doc/libs/1_35_0">Boost</reference>) can be a bit involved with the current generation of c++
compilers. Hopefully this will improve as the compilers are improved
but in the meantime it is useful to keep track of the type of errors
that you get and why. Here is an example of one of those non-obvious
errors.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-epsilon.htmlRR: Small numerical values in C++<paragraph>In numerical programs, financial codes included, there is often a
requirement to use very small numerical values in the algorithm,
perhaps for ensuring all operations are in a valid domain. In a code
published as an accompaniment to a book there is a line:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/heston-calibration-s.htmlHeston Model Calibration<paragraph>Here are some quick graphs from recent experiments in calibration of a
Heston model to observed option prices (in this case options on the
DAX index). They are offered with only the briefest of explanations
below for the time being, but there should be more coming soon; or if
you wish, get in touch with me at <reference refuri="mailto:webs@bnikolic.co.uk">webs@bnikolic.co.uk</reference>.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-05-25T20:51:39Zhttp://www.bnikolic.co.uk/blog/ql-handle-1-ex.htmlRelinking Handles<paragraph>Very simple example showing how to relink a Handle object in QuantLib:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2011-08-10T21:32:07Zhttp://www.bnikolic.co.uk/blog/ql-fitting-curves.htmlFitting a Curve in QuantLib<paragraph>Here is a simple example of fitting a curve in QuantLib, reworked from
the original CurveFitting.cpp file and adjusted to compile with the
current versions of QuantLib:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/python-running-cline.htmlRunning Python Programs from the Command-line<paragraph>Typical ways of running python programs are discussed on the <reference name="Running Python" refuri="python-running.html">Running
Python</reference> page, including introduction to
running from the command line. Here are some tips on more efficiently
running python from the command line.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-01-21T22:42:18Zhttp://www.bnikolic.co.uk/blog/cpp-inmin-consrainedlm.htmlConstrained Levenberg-Marquardt using the InMin library<paragraph>This is the equivalent program to the own shown in this <reference name="old blog post" refuri="http://www.bnikolic.co.uk/blog/cpp-lm-lourakis.html">old blog post</reference>, but
implemented using the new <reference name="InMin library" refuri="http://www.bnikolic.co.uk/inmin/inmin-library.html">InMin library</reference>. The program
demonstrates Levenberg-Marquardt fitting of a function with a box
constraint on the parameters.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-memory-alloc1.htmlRR: Avoiding Memory Allocation<paragraph>The C++ language has a range of excellent tools for managing
allocation and de-allocation of memory. They are an essential part of
writing effective and efficient programs. The first strategy, however,
for dealing with memory allocation should be to avoid it. If that is
not possible, you should try to separate the logic of what you are
trying to achieve from the memory allocation routines.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-12-16T15:10:22Zhttp://www.bnikolic.co.uk/blog/python-excel-integ.htmlPython/Microsoft Excel Integration<paragraph>There are several ways of doing this, such as communicating via a
(XML-)RPC-like protocol or using COM. However, the traditional way of
integrating outside code into Excel has been through the Add-in
mechanism.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/website-rst-atom.htmlConverting a Directory of ReSTructured files to Atom feed<paragraph>In one of the previous posts I sketched out how to <reference name="generate an Atom feed using Python and Kid" refuri="website-atom.html">generate an Atom
feed using Python and Kid</reference>. Here I show a
complete script that can convert a directory of restructured text
files into an Atom feed -- great for writing blogs using restructured
text.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-04-20T12:35:46Zhttp://www.bnikolic.co.uk/blog/bn-internships-2012.htmlOpportunities for (remote-working) internships with BN Algorithms in 2012<paragraph>We are currently looking to take on one or two interns to work with us
for a period ranging from six weeks to six months. We are looking for
people with following skills:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-05-24T17:20:34Zhttp://www.bnikolic.co.uk/blog/cpp-khachiyan-min-cov-ellipsoid.htmlC++ implementation of Khachiyan algorithm for the minimum enclosing (or covering) ellipsoid<paragraph>The problem in this case consists of computing the hyper-ellipsoid
(potentially in a space of high-dimensionality) such that it has the
minimum volume but still encloses all of the points in a supplied
set. The ellipsoid is specified by it's centre and a matrix describing
it's axes.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-rand-normal.htmlSimple normally distributed random number generation<paragraph>Here is a very simple program that illustrates how to generate
normally distributed random numbers using boost.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/ql-american-disc-dividend.htmlExample of Pricing an American Option on a Dividend Paying Stock in QuantLib<paragraph>Here is a quick, bare-bones, example on how to price an option on a
stock that pays dividend on arbitrary but known dates:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-04-23T09:28:20Zhttp://www.bnikolic.co.uk/blog/linux-ld-debug.htmlThe LD_DEBUG environment variable<paragraph>Development of large systems using many shared (dynamically) loaded
libraries can sometimes lead to some frustrating bugs that are
difficult to diagnose. These bugs often arise because there a few
different versions of libraries on the system and the "wrong" version
gets loaded instead of the one the developer used wanted.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-rand.htmlRR: Basic random number generation<paragraph>Many, many codes and books use the standard C function <literal>rand()</literal> to
generate uniformly distributed random numbers. What are the potential
pitfalls of using this function? What are the alternatives?</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-lm-lourakis.htmlUsing the Lourakis constrained Levenberg-Marquardt library<paragraph>Here is a very quickly prepared example of how to use the Lourakis
library to do constrained minimisation in n-dimensions. This shows
simple fitting of a second degree polynomial to a handful of observed
points. The box constraint is used and it is set so that it does not
contain the maximum likelihood point -- this shows off the constraint
feature.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/python-running-emacs.htmlRunning Python Programs from Emacs<paragraph>Tips on running python from Emacs.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-01-19T19:05:01Zhttp://www.bnikolic.co.uk/blog/gnu-ld-as-needed.htmlThe new "--as-needed" option to the GNU linker<paragraph>Recently I upgraded one of my machines to a version of the GNU linker
which by default uses the "--as-needed" option.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2010-12-03T10:09:33Zhttp://www.bnikolic.co.uk/blog/cpp-boost-ser-conflict.html"Pointer Conflict" Errors in the Boost Serialization Library<paragraph>The Boost <reference name="Serialization" refuri="http://www.boost.org/doc/libs/1_45_0/libs/serialization/doc/index.html">Serialization</reference> library offers facilities for saving and
restoring C++ data structures to/from sequential representations
(e.g., for saving and loading to files). It is generally easy to use
and handles most structures correctly, including pointers, circular
lists, etc.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-04-05T11:13:09Zhttp://www.bnikolic.co.uk/blog/cpp-swig-insert-directive.htmlSWIG %insert directive<paragraph>It is often convenient to insert some verbatim code into SWIG
generated wrappers to go along with all of the automatically generated
code. For this purpose SWIG has the <literal>%insert</literal> directive, which takes
a parameter which is the section to insert the code into, e.g.:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-11-16T07:47:28Zhttp://www.bnikolic.co.uk/blog/cpp-constructor-template.htmlTemplate constructor in a non-template class<paragraph>Sometimes it is required to derive a new class from a base class with
constructors that can take many types and perform internal
conversion. An easy way to avoid errors due to by-hand writing
forwarding constructors for each of the types is to use a constructor
in the derived class with a template parameter. This works fine even
in a non-template class, i.e., non of the <emphasis>data members</emphasis> of the class
are dependent on template parameters. This is an example:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-20T17:44:19Zhttp://www.bnikolic.co.uk/blog/cpp-swig-java-raii.htmlSWIG wrappers in Java and the C++ RAII pattern<paragraph>There was recently some discussion on the QuantLib mailing list about
problems arising in SWIG-generated Java wrappers for C++ classes
(<reference name="thread" refuri="http://permalink.gmane.org/gmane.comp.finance.quantlib.devel/4529">thread</reference>
on the mailing list, <reference name="blog post" refuri="http://hpcquantlib.wordpress.com/2012/02/27/quantlib-swig-and-a-thread-safe-observer-pattern-in-c/">blog post</reference>). The
immediate problem in these discussions was that the Java garbage
collector runs in a thread which is separate to the main thread of
execution of the native C++ code. Therefore, the C++ destructors are
called at non-deterministic intervals and if they are not completely
thread-safe the program will eventually fail.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-04-23T09:28:37Zhttp://www.bnikolic.co.uk/blog/indexplain.htmlComputing Blog -- Complete Index and permanent links<paragraph>This blog is linked on <reference name="technorati" refuri="http://technorati.com/blogs/www.bnikolic.co.uk/blog">technorati</reference>.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-15T15:28:12Zhttp://www.bnikolic.co.uk/blog/python-numba-note.htmlNumba<paragraph>I came across the <reference name="Numba" refuri="https://github.com/ContinuumIO/numba">Numba</reference>
project recently (H/T <reference name="@mza" refuri="https://twitter.com/#!/mza">@mza</reference>), which
looks interesting indeed. From the front page:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/ql-equity-option-ex.htmlA minor rework of the Equity Option example in QuantLib<paragraph>To enable some experiments with QuantLib I've reorganised the
EquityOption example so that each of the pricing methods sits in a
separate function. It is a pretty trivial change but I think it makes
the example a bit more readable. Feel free to use in accordance with
the QuantLib licence.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-checked-delete.htmlPrivate implementation using smart pointers and deletion trouble<paragraph>It is often desirable to hide excess implementation detail from users
of libraries by using forward declarations and private pointers. There
is a lot written on the Internet on this idiom. If you are using it
you may very well want to use the <literal>boost::scoped_ptr<></literal> smart
pointer. There is however one simple trap you can fall into doing this
and then you may get error messages related to incomplete type such as
this:</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-15T15:17:26Zhttp://www.bnikolic.co.uk/blog/python-cxfreeze-using.htmlPython cx_Freeze package<paragraph>I've recently started using the <reference name="cx_Freeze" refuri="http://cx-freeze.sourceforge.net/">cx_Freeze</reference> Python package. This package
makes it possible to more easily distribute Python-based programs by
packaging together all of the libraries, python modules and supporting
files that are needed to run the program in a single, <emphasis>stand-alone</emphasis>,
directory. The Python script itself is turned into an executable which
can be run directly from the command line. And, unlike some
alternative, this package works on Linux!</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/python-running.htmlRunning Python Programs<paragraph>Answering the question "How do I run Python programs?" is the obvious
first step in learning how to use and program python, but often people
do not spend enough time thinking about this.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/emacs-environment-vars.htmlSetting environment variables from within Emacs<paragraph>If you have a long-running <literal>emacs</literal> session it is sometimes
convenient to change or set the values of the UNIX "environment"
variables of the <literal>emacs</literal> process. This is easy to do using the
"setenv" function.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2012-03-19T11:59:34Zhttp://www.bnikolic.co.uk/blog/emacs-byte-order-marks.htmlByte Order Marks and Emacs<paragraph>Some programs write <reference name="byte order marks" refuri="http://en.wikipedia.org/wiki/Byte_order_mark">byte order marks</reference> into their output
files, even when they are encoded in UTF-8. When opening such file in
Emacs in the ordinary way these byte order marks are correctly
interpreted and removed from the contents that are displayed to the
user.</paragraph>Bojan Nikolicbojan@bnikolic.co.uk2009-09-23T09:44:55Zhttp://www.bnikolic.co.uk/blog/cpp-rr-class-hirearchy.htmlRR: Avoiding Artificial Class Hierarchies<paragraph>Polymorphism is a cornerstone of object oriented programing. It allows
run-time resolution of the class function (method) to be called,
depending on concrete type of the object. This is of course extremely
useful, but requirement for run-time resolution of function called
should <strong>not</strong> be by itself the reason for deciding on a deep and
complex class hierarchy. If run-time resolution is all that is
required, then much simpler solutions based on function pointers, or
<literal>boost::function</literal> object are much better suited.</paragraph>