Featured Post

Customer focus is a data imperative

Age of information is really the age of confirmation and it is upon us. Gone are the days of naive customer focus termed as providing the b...

Thursday, November 18, 2010

Human life, a Wiener Process?

This is a blog by a dot whose favorite read is Candide. If any of topics have been taken out of context or dealt lighter than their exalted position in shaping the future of human race or "markets" it is being done purely subliminally but intentionally. Now is the time to notice that the author puts his disclaimer right on the top of his ideas, to spare his limited readership the extra stress on their eyes and a nuisance on their minds of a footprint, because they are allowed to form opinions, disregard, discard, take out of context to north, south, east, west or simply read on because sometime spending a precious commodity such as time frivolously feels powerful, may the empowerment be yours. For more seriously inclined I have a blog "Also sprach Ashar", or the pathetic "Leiden des alter Ashar".

As the topic suggests we want to ponder on predictability of another stochastic variable in the illusory realm of universal time be it discrete or continuous; umm! a human. Considering the human has a normal disposition, I mean normal distribution which in our case is one and the same. Unfortunately for a human to be a "Wiener" he/she/it will have no dependence on the historical path, which we all know is only true in case of lottery winners(well even lottery winners have to buy a *#$!@#) or Markovians, the rest of us may depend on the Brownian motion for our existence but the outcome of our lives is pretty correlated to our historical paths, "outliers" or not. Let's for fun's sake assume that happenings in a long time interval can be divided into infinite small happenings which are independent of each other and are meaningless as in having a mean of zero and they deviate from each other by a fixed amount always. The drift rate i.e mean change per unit of time for a stochastic variable( not to be confused with a drunkard, even if he is following a Brownian path on a straight line) multiplied by the change in time will give us one part of his future while we can add an unpredictable string of events in terms of some multiple of deviation from expected outcomes. But since both the predictable and unpredictable parts of the generalized "Wiener" are multiples of constants (part average drift per unit of time and part a fixed variation from the mean), I declare that humans are not mere Wieners, they may be whiners or diners but they are not Wieners, in mathematical sense that is, because some us can be all of the above specially...okay never mind that thought process. Simply said a human cannot be modeled as a stock even if he/she/it follow a random walk.
Ahh! but Ito's process may give us a better approximation, not to mention a headache of calculus to go through as it makes the constant terms in a Wiener process a function of the variable and the time itself, which is more human, since the change in our future is neither free from where we are at present nor from the time it takes to make that change.

Beside the Hull is laying Saigyo so quoating one after the other is befitting,

"Shino tamete suzume umi haru o no warawa
hitai eboshi no hoshige naru kana",

Drawing his
sparrow hunting bow
of bent bamboo
the litle boy seems to be wishing
for a guardsman's black hat

Wednesday, November 17, 2010

Building and Including Boost libraries (VS 2010)

Before I venture into the pair trading further, I had to do a modification. Which is to read all the files in a directory and calculate stats on each pair one by one. I needed a directory iterator, which took me to boost filesystem, which happens to be one of the boost libs that need to be built in order to be used. Building and using boost with VS 2010 was easier than I thought. Here are the simple steps to build boost library and linking to it.
Assuming we have the boost downloaded for windows (boost_1_45_0_beta1.zip includes bjam, so no need for separate download)

1. start a command window.
2. change to directory Program Files (x86)\VS2010\VC\bin and run "vcvars32.bat". This will setup nmake and other environment variables for visual C++ to run from command line.
3. Change to directory where boost is installed. Run "bootstrap.bat". This will get the bjam specific setup done.
4. Run the command "bjam --build-type=complete". The only reason I will build the complete libraries is if, somehow you decided to static linking instead of dynamic linking you will need to rebuild those specific libraries. The default "bjam" command will only build dynamic linking libraries.
5. After a patience, patience and more patience messages the libs will be ready and at the end you can see the directories for include and link libraries.

If you do a simple program like directory iteration (just pluck a sample from the boost_1_45_0_beta1\libs\filesystem\v3\test\msvc10 directory).

Two more steps are needed to compile and link the program.
First in the C/C++ properties add the boost directory in the "Additional Include Directories" (For me it was D:\boost_1_45_0_beta1\)

Secondly in the Linker options add the library path (in my case it was D:\boost_1_45_0_beta1\stage\lib ).

The program should compile and link. I used static linking (in the C/C++ code generation-->Runtime library options, choose the options with(/MTd) or (/MT) depending upong debug or release build) to avoid the hassle of packing my libs along with my exe, so I needed the libboost_filesystem-vc100-mt-sgd-1_45.lib. One can choose which libs to build, but in the age of terabyte hard drives, building a Gig worth of libs in one shot was the option for me.

Wednesday, November 10, 2010

Pair trading application

When I downloaded the open source FIX engine I thought going through open source FIX ,Quantlib, and boost will get me up to speed on writing any numerical application. But compiling libraries and going through code was not really making me feel "accomplished". I wanted to brush up my C++ in a financial setting with my teeth clutched into the monster and its fangs ripping my sanity apart. I needed a project! So I posted a comment on GQR group in linked in and got response from a nice quant who wanted a pair trading algorithm developed. Well little I knew about the complexity of the project, till he sent me a 200 plus page book, a research paper and some instructions. I was excited to get a project. I was to make time series statistical calculations for statistical arbitrage. Although I believe that economic environment is/was? ripe for risk arbitrage as the chances of companies going bankrupt and emerging out of "crisis" as brand new organizations offer ample opportunities for remodeling capital structures.

I started with the book, the chapter one is .......by the end of 7 chapter, I was underwater.I started the project and I was hoping for a river of code to just flow through, but instead of monsoons and torrentials it was a trickle here and a drop there. Meanwhile I was also collecting all sort of available "free" C++ books, numerical methods in C++, design patterns, thinking in C++, Stroussup, Eckel, Scott Meyer, Erich Gamma to feel securely fastened as the programming part took off. I even downloaded the open source UML tool by Ameos to help design the class structure. The result of all this was a month and a half spent on reading material, writing snippets and "strategizing". I am not sure if any or all of that browsing, nibbling, sniffing, gnawing at pages helped but one night, I sat down and wrote the class structure and was on my way to at least getting the different time series calculations....
....The end result is a beta version completed few days ago... and from here on I will chronicle how the project will develop further....Next blog I will outline some of the C++ and the calculations for a stochastic time series parameters including C++ routines for covariance, variance, co-integration etc....and what a wonderful tool STL containers are...


The code is not commented, but it might be helpful for building something on top of it or taking snippets from it. If you can't down load, send an email to asharmairaj@yahoo.com. (I cannot post the PDF for Quantitative Methods and Analysis by GANAPATHY VIDYAMURTHY, but shoot me an email and I will send)

Example ticker files with trade data
============================
https://docs.google.com/leaf?id=0B_40SUf1ic7PNmRhZjhkNWQtMmZhZC00MDg4LThiOWEtMWEzNzYzMzUxMzgz&hl=en&authkey=CPPv7aoH
Executable
================
https://docs.google.com/leaf?id=0B_40SUf1ic7PNDQ3YmFiYjQtZjIzNy00NWM4LTlmYTUtZGE0N2MwYzJiODU0&hl=en&authkey=CJ-ktugB

Visual studio 2010 Project and files
==========================
https://docs.google.com/leaf?id=0B_40SUf1ic7PYzY3ZjQwMGItMDBmNi00Y2FhLThiNmItMDAwMWU0ZWE3MTMz&hl=en&authkey=CL_X_JwL