Time to apply the brakes to high-speed trading?

UltraHighFrequencyTrading.com posted a good article on the history behind high frequency trading and the potential consequences of some proposed changes to trading rules:

High-frequency trading might appear to pose threats on the horizon, notes Tabb, but hasty regulation is all but certain to trigger unintended consequences. “It could totally destroy the market,” he says. If rules lock a high-frequency investor into a bid of $102 for even half a second when the market value is $101, other investors could swoop in at $101 and make a dollar a share on the incorrect price. This will create incentives not to quote or provide liquidity, making it harder and much more expensive to invest.

Now the debate is getting political:

While the debate simmers, high-frequency traders are enlisting influential allies in Washington. Republican members of Congress Jeb Hensarling of Texas and Spencer Bachus of Alabama are advocating a slow approach to any regulatory initiatives. In letters to the SEC and the House Financial Services Committee, both congressmen warned not to “shoot the computers first and ask questions later.”

Leave a comment

Filed under Finance, Technology

Herb Sutter Video – C++ Concurrency

Another excellent video from Herb Sutter, this time on C++ Concurrency. The Monitor class is based on his Wrapper pattern
20130118-133301.jpg
and allows the caller to group related calls into a transaction, with synchronisation supplied via a mutex.
20130118-133722.jpg
The Concurrent class replaces the mutex with a concurrent_queue to avoid the caller blocking whilst the tasks complete.
20130118-133609.jpg
What’s especially elegant is ~Concurrent which pushes a done function onto message queue in order to signal not to wait for any more tasks (the concurrent_queue.pop() is assumed to wait until the next task is pushed). The done data member is not required to be atomic because it is only mutated on the worker thread, never on the calling thread.

1 Comment

Filed under C++, Video

Star programmer outsourced his own job!

TheRegister reports that an audit discovered a firm’s star programmer was outsourcing his own work to China!

A security audit of a US critical infrastructure company last year revealed that its star developer had outsourced his own job to a Chinese subcontractor and was spending all his work time playing around on the internet.

The ruse was obviously paying off for him handsomely:

Further investigation found that the enterprising Bob had actually taken jobs with other firms and had outsourced that work too, netting him hundreds of thousands of dollars in profit as well as lots of time to hang around on internet messaging boards.

Leave a comment

Filed under Programming

Personal Projects

Thought-provoking essay on the hidden value of personal projects:

All of these properties of personal projects suggest they’re a really good predictor of talent that is worth hiring. Though this approach may suffer from the occasional false negative (even the greats now and again bang out quick-and-dirty personal projects don’t necessarily impress), a false positive probably never does: you’ll probably never find someone with a great personal project who also turns out to be rubbish.

Leave a comment

Filed under Programming

Memory corruption due to C++ code incompatible with C++11 standard

I’m a big fan of C++11 and the new features that have become available, including move semantics.  However, our team found today that a code optimization which worked under VS 2005 was causing memory corruption under VS 2010.

The story goes back to a string holder class a bit like this (if you think BSTRs you’ll be on the right lines, but taking COM out of the picture makes the example clearer):

class CDeepCopy
{
protected:
  char* m_pStr;
  size_t m_length;

  void clone( size_t length, const char* pStr )
  {
    m_length = length;
    m_pStr = new char [m_length+1];
    for ( size_t i = 0; i < length; ++i )
    {
      m_pStr[i] = pStr[i];
    }
    m_pStr[length] = '';
  }

public:
  CDeepCopy() : m_pStr( nullptr ), m_length( 0 )
  {
  }

  CDeepCopy( const std::string& str )
  {
    clone( str.length(), str.c_str() );
  }

  CDeepCopy( const CDeepCopy& rhs )
  {
    clone( rhs.m_length, rhs.m_pStr );
  }

  CDeepCopy& operator=( const CDeepCopy& rhs )
  {
    if (this == &rhs)
      return *this;

    clone( rhs.m_length, rhs.m_pStr );
    return *this;
  }

  bool operator<( const CDeepCopy& rhs ) const
  {
    if (m_length < rhs.m_length)
      return true;
    else if (rhs.m_length < m_length)
      return false;

    return strcmp( m_pStr, rhs.m_pStr ) < 0;
  }

  virtual ~CDeepCopy()
  {
    delete [] m_pStr;
  }
};

CDeepCopy was used as the key into a map. For large data sets with heavily overlapping key values, this was inefficient because each lookup would entail the cost of a copy constructor – this was particularly expensive due to the heap operations. As an optimization, the following technique was used to avoid the copy constructor call in the event of an update operation, yet worked correctly if the operator[]() call led to an insertion.

class CShallowCopy : public CDeepCopy
  {
  public:

  CShallowCopy( const std::string& str ) : CDeepCopy()
  {
    m_pStr = const_cast<char*>(str.c_str());
    m_length = str.length();
  }

  ~CShallowCopy()
  {
    m_pStr = nullptr;
  }
};

So you could do an efficient lookup like this that only caused a deep copy if an insertion into the map was required instead of an update:

int _tmain(int argc, _TCHAR* argv[])
{
  std::map<CDeepCopy, int> entries;
  std::string hello( "Hello" );

  CDeepCopy key( hello );
  entries[key] = 1;

  // Named variable
  CShallowCopy key2( hello );
  entries[key2] = 2;

  // Unnamed temporary variable
  entries[ CShallowCopy( hello ) ] = 3;

  return 0;
}

This code worked as intended in VS2005. However, compiled under VS2010 we were seeing memory corruption in the final case (the one with the unnamed temporary). After some debugging, we realised that under C++11, std::map has an operator[]( KeyT&& key ), that is the key is an rvalue reference – and this form is called for our unnamed temporary case. That avoids calling our CDeepCopy copy constructor, and so the key in the map can be left referencing deallocated memory.

A simple workaround prevents this happening again – declare CDeepCopy( CDeepCopy&& ) as private but omit the definition – this means that the unnamed temporary usage does not compile.

Leave a comment

Filed under C++ Code

Pop-up buttons for flat screen technology

TechCrunch broadcast an interview with Tactus, the company behind an innovation to bring transient pop-up buttons to flat screen devises.

Leave a comment

Filed under Technology, Video

BATS looks to compensate after long-term system error

BATS Global Markets has identified a software bug that has caused almost 450,000 trades to be executed at the wrong price over a period of 5 years, according to thetradenews.com:

The exchange group found that some short-sale orders were executed at a price that is equal to or less than the national best bid or offer, while non-displayed pegged orders may not have been executed at the most optimal price.

Under the SEC’s Reg NMS rules, trades must be routed to the market displaying the best price. As per short-selling rules, if a stock declines by 10% from the previous day’s close, traders can only sell short at a price one tick above the national best bid or offer until the end of the next trading day.

This sounds like an oversight in their understanding of the complex market rules rather than a bug – it wasn’t that the software was implemented correctly, this rule wasn’t implemented at all!

Leave a comment

Filed under Finance, Programming

Herb Sutter Video – You think you know Const and Mutable

Herb Sutter has published his C++ and Beyond talk on Const and Mutable in C++ 11.

20130110-130728.jpg

20130110-130826.jpg

20130110-130953.jpg

1 Comment

Filed under C++, Video

Treat market data with caution

Stale market data occurred yesterday on the Nasdaq, according to TheTradeNews.com:

As a result of the error, market data for many Nasdaq-listed stocks did not refresh for around 15 minutes, rendering some consolidated tape data unreliable. The issue was resolved at around 13.53 EST, according to a Nasdaq OMX statement.

Leave a comment

Filed under Finance

News on US Circuit Breakers

TheTradeNews.com reports that the rollout of new circuit breakers could be delayed to allow firms longer to implement them.

The new limit up-limit down (LULD) and market-wide circuit breakers are scheduled for introduction on 4 February but could be delayed until 6 April, pending approval by the Securities and Exchange Commission (SEC). Testing for the enhanced circuit breakers is expected to commence on 26 January.

Here’s how it’s supposed to work:

Under the current proposals, if the national best offer of a stock equals the lower price band, or if the national best bid of a stock equals the upper price band, trading in that stock will enter a ‘limit state’.

In a limit state, trades at the upper or lower limit must be adjusted or cancelled within 15 seconds to prevent a pause to trading of that stock. The length of a pause will depend on the liquidity characteristics of the stock in question, currently five minutes for S&P 500 and Russell 1000 constituents and at 10 minutes for most other securities.

Trades that are entered outside of the price band set for a stock will be rejected or adjusted to an appropriate price, at the discretion of the broker entering the trade.

Leave a comment

Filed under Finance