Pages

Wednesday, January 20, 2010

UNIX for Quants

here i will discuss some basic command that are usually a quant need.

  • pwd -> to know in which directory person is working.
  • cd -> to change directory
  • df -> to check disk space
  • finger -> to see who is on the system
  • ls -> to check files in the current directory
  • passwd-> to change the password
  • logout -> to logout from the system.
  • rm -> to delete files
  • man -> to find help on commands
Running a C++ code in UNIX.

  • vi code.cpp (a text editor will open where you can type the code)
  • :wq (to save the changes and quit)
  • :q (to quit)
  • g++ code.cpp (to compile the code)
  • ./a.out (to run the code)

Making make files

Make files are used in project which have dependencies in number of files. By running make you can implement all the changes at one go.Following is the MakeFile example.

all: code

code: code1.o code2.o (to link both object files)
g++ code1.o code2.o -o code

code1: code.cpp (to make code1 object file)
g++ -c code1.cpp
code2: code.cpp (to make code2 object file)
g++ -c code2.cpp
clean: (to clean all created files)
rm -rf *o code


to find details any of the above command type man command which will take you to help file.

Sunday, January 17, 2010

TWAP Algorithm

Time Weighteed Average Pricing: TWAP is (time weighted average price) the average price of contracts or shares over a specified time. Which makes buy price to be fair price instead of executign order at time of day when price is high.

When it is used? It is used at point of tiime when investor want to distribute its order through out the day.

Comapison with VWAP: In VWAP order is distributed according to volume traded in exchange while in this case time is the main factor. For example in VWAP 45% of the order takes place in first half of the day while rest of the order takes place in the second half of the day.To execute the order evceenly through out the day this algorithm is used.

Algo:
1) Get the order and decide upon the time execution.
2) Submit the order and include delay() function to delay certain order using for loops.

Why C++ ?

Algorithmic trading whenever we talk about is implemented in c++ irrespective of the fact system or strategy.

One of the reason for c++ being used is low latency. Latency is the delay in the order submitted and order executed .In algrtihmic trading latecny is importnt because as soon as target price arrive, order has to be executed otherwise there is no advantage of setting up these systems.

C++ is code is low level code (very near to hardware) due to which its execution takes place at higher speeed as compare to higher languages code like Java etc which needs time for both compile time and run time.

One question that can come to a programmer mind is why not C ? No doubt C is better in terms of speed but C++ being object oriented emerges out as a best candidate for AT.

Note: Latency is affected by other factors as well like broadband speed,distance to server,Execution speed etc. Execution can be reason HPC (High Performance Computing) role in trading is increasing day by day.

VWAP Algorithm

Value Weighted Average Price: in this algo trader first estimate the volume of the trade that takes place in the market on a particular day. Then depending upon the volume traded in day he/she divides the number of the stocks to be bought depending upon the volume in the market so that effective price should be weighted average price.I will try to write algo for this:
  1. Find Daily Volume in a stock, Say it came out to be X.
  2. Number of shares to be bought in day , Say 100.
  3. At particular time if total volume traded on stock is 10% of X then buy 10% of stock, means buy 10 shares.
Note: Percentage can be reduced to 1% or whatever value you want.

This algorithm instead of used for day can be used for long or short duration. VWAP is typically used by HNIs who do not want to sway the market with their orders and do not want to let sniffer know their presence in the market.

Thanks
Sidharth

Algorithmic Trading

Algorithmic Trading in India is not very popular, has just started sprouting. Goldman Sachs, Credit suisse all with their global efficient electronic platform about to wooing Indian HNIs.Till now it is available to captive trading benches of brokers and investment bankers where algorithms are used to trade.

First of all answering some basic questions:

what is algorithmic trading (AT) ?
it is nothing but trading with the help of computer algorithms to make best use of the opportunity available in the market, which is present for such a short time, that is very difficult to track with human eye. while on the other hands computer can sit waiting for the whole day for such a event.
e.g. say jan future trading at significant discount then depending upon the algo opportunity can be exploited using F&O or Cash market.

Usage ?
According to one report in US AT makes 30% of the whole trade happens at the exchange.

Quant?
It is the name given to person who design and code algos to find arbitrage opportunities in the market.

In the following posts, i will try to share various algos used in the process and will try to incorporate if i am able to do it .