Showing posts with label High Frequency Trading. Show all posts
Showing posts with label High Frequency Trading. Show all posts

Thursday, August 16, 2012

Calculate the sum of all the primes below two million


The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Question is from Project Euler Q10 , which is a very interesting website.

My Solution is as below, which has performance:
time a.out
sum of Prime = 142913828922
0.090u 0.005s 0:00.09 100.0%    0+0k 0+0io 0pf+0w 
        int l_iCount = 2;
        const int l_iMax = 2000000;
        const int IS_PRIME = 0;
        const int NOT_PRIME = 1;
        int l_arIntegers[l_iMax];
        //initialize and assume all to be prime
        memset(l_arIntegers, 0, sizeof(l_arIntegers));
        l_arIntegers[0] = NOT_PRIME;    //for 1
        l_arIntegers[1] = IS_PRIME;     //for 2
        long long l_iSumOfPrimes = 0;
        while(l_iCount < l_iMax)
        {
                if(l_arIntegers[l_iCount - 1] == IS_PRIME)
                {
                        for(int i = 2 * l_iCount; i < l_iMax; )
                        {
                                if(l_arIntegers[i - 1] != NOT_PRIME)
                                        l_arIntegers[i - 1] = NOT_PRIME;
                                i += l_iCount;
                        }
                        //it is a prime
                        l_iSumOfPrimes += l_iCount;
                        std::cout << "found a Prime = " << l_iCount << std::endl;
                }
                l_iCount++;
        }
        std::cout << "sum of Prime = " << l_iSumOfPrimes << std::endl;
When I started to code the solution, I tried the normal check for a prime number, it was too slow to be acceptable. then I thought maybe it is faster to create an array of all integers to be checked as above, just having simple comparison and assignment to 1, without tons of mod (%) operations. And the execution result proved to be working.
 
I have checked the recommended solutions from Project Euler after solving it, my solution is very close to the optimal answer.
 
Here is my Project Euler Label:
 

Thursday, November 3, 2011

What is really needed by a high frequency trader

High-Frequency Trading

What Does High-Frequency Trading - HFT Mean?
A program trading platform that uses powerful computers to transact a large number of orders at very fast speeds. High-frequency trading uses complex algorithms to analyze multiple markets and execute orders based on market conditions. Typically, the traders with the fastest execution speeds will be more profitable than traders with slower execution speeds. As of 2009, it is estimated more than 50% of exchange volume comes from high-frequency trading orders.

Please note the bold highlighted sentence, for high frequency trader, they normally do not care about your system's real latency figure. they just want to ensure that your system is faster than their competitors.
that is also to mean that your system takes less time from market tick received to order leaves for exchange. Remember the key is not how fast your system can be, the key is that your system should be faster than others.
High-Frequency Trading

for a similar strategy which takes arbitrage opportunities, the institute which has faster system will grab all market opportunities and leave nothing for competitors. It is not a game that all market participants can share the opportunities. Based on a statistics report, India's high frequency trading firms reduced from 300+ to about 30 in just one year. It is a matter of survival or not based on the speed of the system they used.
High-Frequency Trading

the latency war once starts then it will end at the situation that all systems survived in the market will become almost the same speed restricted by current technologies provided. And for high frequency trading, exchange's support is equally important. some exchanges, like that of China, actually limit the possibilities of high frequency trading strategies by putting restrictions in their gateway libraries.