Friday, April 04, 2014

Quantlib and Python - Getting Started

[See part 1 of this series here]

When it comes to open source software Linux is the only way to go.

Why would you use anything other than Photoshop on a Mac or a cutting edge game on Windows? - using Linux is just easier for Python development and all the quant lib packages come ready made for your machine (no messy compiling required!).

In order to install Quantlib for Python on Debian (sure to work on Ubuntu and Mint also) Linux system run:

apt-get install quantlib-python quantlib-swig

which will install everything you need.

Now give your setup a quick test:

cd /usr/share/doc/quantlib-python/examples/
python bonds.py

With any luck you will see a bunch of analytical results in your console.

This collection of examples are one of two resources I have found about using Python for Quantlib, which hopefully I can add to a little with these blog posts.

The other reference which you can use are the test units also included in the same folder.

ls /usr/share/doc/quantlib-python/examples/test/

These tests are used as a check by the library developers to ensure everything is good to go and no bugs have been introduced.  With such meagre references the tests are valuable reference for code written in Python.

One of the other places to go to with is the Quantlib C++ library reference itself.  As I said before, C++ is not my forte and in this day and age more of an academic pursuit in finance than anything else.  Nevertheless, example Python code is in short supply - and the python code that you do write is pretty close to what you see written in C++.

The upshot is on the one hand your Python code doesn't feel super Pythonic because you are tied so close to the C++ libraries.  On the other hand the C++ idioms start making more and more sense after days and weeks of banging your head of the wall! (no pain no gain?)

The places to ask questions are Wilmott, Quant Stack Exchange and the mailing list.  None are high traffic when it comes to Quantlib (scared off yet?) so your mileage may vary.

[Continued here]


Quantlib and Python - An Introduction

I am learning how to write Quantlib code with Python in order to create a project of mine called Vol Kills.  What better way to learn than writing down what I have figured out?  And perhaps I can help others out along the way.

First question, why Quantlib? why Python?

Firstly Python is easier to learn than C++ (I admit I never tried, always sounded too daunting).  You can code quick with no need to worry about the cruft that comes with Java and C.

Secondly, we're really just using Python to send messages to Quantlib which is written in C++ compiled down to super fast 1s and 0s.

Best of both worlds!

Third Python does a lot.  You get the stats libraries; web frameworks; heavy lifting"extract transform load" libraries and more right there in the one place (their motto is "batteries included" after all).  No need to mess around with multiple languages and run times.

A quick word about QuantLib.  It's a collection of code which helps people like me model financial investments; understand how investor's portfolios tick and perhaps point out some opportunities and pitfalls ahead.

Quantlib has been developed for over a decade.  It is widely used and battle hardened.  Best of all it is free and open source, which means you can use it without worrying about licensing fees and nasty bugs (the more eyeballs on the code the less chance of errors).

[Continued here]

Saturday, March 01, 2014

Quantlib 1.3 Debian Packages for Debian Stable

Debian is the old reliable Linux distribution.

It comes in several flavours.  "Unstable" which is really just the latest and greatest open source apps all collected together.

On the other end of the scale the "stable" release includes battle hardened software that has been tested for years.

Unstable is used on desktops stable is all about servers.

I ran into a problem last week however, as I needed some features from Quantlib 1.3 which weren't available in 1.2 (bundled with Stable).

Last time I did any serious compilation work was college.  Turned out not to be too tricky.

As of this weekend Quantlib 1.3 itself is out of date but I'll make do without 1.4 for the time being.

Without further ado download the deb packages here (including Ruby and Python bindings).

Sunday, March 25, 2012

"Monotony Collapses Time. Novelty Unfolds It"

Psychologists have done experiments which show that packing more events into your life stretches out your experience of time (see this podcast).

In one experiment a psychologist locked himself up for two months in complete isolation. When he was pulled out he had only one month of entries in his journal.

In effect he had lost a month. Time as he experienced it halved.

Collecting as many memories as possible is not too bad a goal. One day does not become indistinguishable from the next; years don't have rhetorical postscripts about where they went.

I wonder how much time is expanded by taking vacations; living in new places and doing new things? Is there a limit to expansion?

Learning how to retell memories well and remembering to jot them down may be good habits also. Then again I am not a fan of sentimentality. Maximising 'future memory' is the way to go.

Sunday, March 18, 2012

Suffragettes

While doing my best to fight Irish stereotypes - i.e. not drinking on St. Patrick's day - I listened to this incredible documentary (I still have the MP3 if anyone wants to listen) about the suffregette movement in the UK (and Ireland) one hundred years ago.

Women fighting for the vote and their civil rights; bombs planted in cabinet ministers houses; torture of suffragettes in prisons by the authorities - all relayed by nice old women on recordings made in the 70s.

I had no idea how gritty and tough the fight for women's suffrage was!

Interestingly, after the vote was won by women the point was made in the documentary that there was still a lot inequality left to tackle.

The same point was made at the end of Ken Burns' documentary on the civil war - changing the law is easier (a four year war which killed hundreds of thousands) than changing people's mindsets.

Thursday, February 23, 2012

Stomach Churning Poetry

People write songs and poems about feeling in love, it's the feeling that makes hearts tick and pencils scribble. Crazy things happen when someone falls for a boy or a girl - novels and movies are written about the ensuing twists and turns.

What I do every day is about a feeling, unfortunately not love, it's the feeling you get when you are about to make a big decision, that feeling in your stomach when you can't really think straight you just feel a little off colour (or maybe extremely ill if it's a humungous decision).

The bigger the decision the bigger the stakes the more stomach churning the quandry.

Here's an example of a not so risky proposition and something rather more risky (albeit slightly artificial).

Heads I give you a Snickers bar, tails I give you nothing (and you give me nothing either). Good deal eh? (if you are allergic to nuts you can eat around them!) Half the time you will end up with a nice Snickers, half the time nothing happens.

That's a no brainer, not stomach churning at all.

Well what about this for size? Heads I give you a Snickers plus ten thousand bucks; tails you give me ten thousand bucks!

The stakes are waaaaay higher now and if you happened to agree to partake in the game, your palms will probably feel a little sweaty, heart pumping.

Chances are you wouldn't take part in the game, even though it's slightly biased in your favour. In fact it's biased exactly the same way as the first game - that delicious snickers bar - however a chance of losing the 10,000 bucks wouldn't make you sleep well at night.

And that feeling my pals is the nervousness, stomach churningness that is risk. That's what I think about most days and that's what I help describe for hedge funds, pension funds and their investors.

If only I was paid to write poetry and sing songs about risk to said investors instead of spreadsheets and reports.

Thursday, February 09, 2012

Finite Games

At the end of the Super Bowl last weekend there was an odd moment a minute from time.

A New York Giants player found himself rushing towards the goal line and couldn't stop himself from scoring a touchdown. You may think that would be the dream of every American - to score a touchdown and help win the biggest prize in American sport.

The problem was by scoring the New England Patriots then had a slim chance of scoring down the other end in the remaining time. The correct strategy was to not score but keep the ball and wait until the last moment to score a field goal.

The problem of not wanting to score (at least for a period) is a quirk that happens toward the end of games. The same happens in soccer now and again - a team will rather keep the ball than score.

It happens elsewhere also, every relationship or 'game' we have is finite, there's always an end game and it's always plays out differently to what's gone one before.

Friday, December 23, 2011

Pop Up Restaurants

A restaurant goes out of business and the landlord is finding it difficult to lease the space - so they rent out to people on a short term basis at lower than normal rents.

Hey presto, you have a pop up restaurant!

Monday, December 19, 2011

Facebook

I am back on FB.

A couple of reasons:

1) I want to keep in contact with people better, especially those in Indonesia

2) /All/ the free internet PCs in Changi airport had people logging into Facebook. Just goes to show you...

Private Equity

I leave a vibrant Jakarta for a miserable Dublin.

This morning a retired doctor is telling me how screwed Ireland is over a coffee in Dublin. He tells me how the English are doing their level best to bring the Euro down, intimating the the prime minister is in cahoots with big financial interests in London.

He looks for some confirmation from me, I only mutter indecisively.

Conspiracy theories are something I used to hear in Jakarta, now I am listening to them in Dublin. I suppose there's less time for a good yarn when everyone is making good money.

Friday, November 25, 2011

Saturday, November 05, 2011

Harry Potter

I am reading it on my way to and from work and sometimes even at home - I am terrible about reading-off-net so to speak which is a shame.

I feel reading-on-net is throwaway for the most part, it's nice in that you read a little about a lot quickly - but good books are like long term relationships, much more meaningful.

Even newspapers are marginally better, I suppose it's easier to read longer articles on paper.

Tuesday, October 18, 2011

Wednesday, October 12, 2011

Americana

BBC 's Americana - consigned to history. I've lived here for about 3 years and, it struck just the right tone. Pity.

Sunday, September 04, 2011

Insecurity

Piers Morgan had Mark Sanford on his show last night.

Sanford was squirmish - as anyone would do having to talk about his private life on TV.

In any case, he said one line in particular that I remember. While quoting the bible, he said that the only thing women need is a feeling of security in a relationship.

Inferring that the defining characteristic of women is that they are insecure.

What an idiot.

Saturday, August 13, 2011

Net Positive Karma

It blows my mind how the people I have met through being a blogger and have only really known over the 'net are willing to be so generous to me.

I asked this Brandon over at the Java Jive to write give a little advice for my sis about teaching in Indonesia, and he took the time to a really nice reply.

This has happened to me over and over again. Pity I am not the blogger I once was, it's such an incredible medium.

Saturday, July 02, 2011

Love Hate

I just read about how a Saudi diplomat enslaved an Indonesian maid in Berlin.

A German human rights organisation made a good point - human rights should trump diplomatic rights every time.

I started reading the comments next to the article. The commentators are rightfully outraged.

This story comes on the back of several brutal cases concerning Indonesian maids in Saudi Arabia. Torture (girl's faces being destroyed beyond recognition), slavery, rape, death sentences (the accusation was black magic, after a family's son left home).

The place sounds like a hell hole.

Many issues arise which have been written about elsewhere.

One is pertinent to me however, after reading the comments. Many in the west believe Islam is a monolithic religion, which is of course a gross over simplification. For example, Indonesia's Muslims have a love hate relationship with the Middle East. On the one hand, it is the ancient source of Islam on the other it can be the modern day heart of evil, which devours so many young innocent Indonesians.