Stephan Lavavej’s make_unique proposal

Stephan Lavavej has submitted a proposal to the C++ Standards committee for make_unique (the std::unique_ptr equivalent to std::make_shared for std::shared_ptr).

make_unique’s presence in the Standard Library will have several wonderful consequences. It will be possible to teach users “never say new/delete /new[]/delete[]” without disclaimers. Additionally, make_unique shares two advantages with make_shared (excluding the third advantage, increased efficiency). First, unique_ptr<LongTypeName> up(new LongTypeName(args)) must mention LongTypeName twice, while auto up = make_unique<LongTypeName>(args) mentions it once. Second, make_unique prevents the unspecified-evaluation-order leak triggered by expressions like foo(unique_ptr<X>(new X), unique_ptr<Y>(new Y)). (Following the advice “never say new” is simpler than “never say new, unless you immediately give it to a named unique_ptr”.)

It’s a really useful utility as demonstrated in this video.

Leave a comment

Filed under C++

Primer on Credit Default Swaps

This is an excellent introduction to CDS’s, aimed at developers.

Now consider the case where we buy a General Motors bond. We then enter into a credit default swap to the maturity of the bond as well. This acts as insurance against General Motors defaulting on the bond. We receive interest from the General Motors bond, but pay some of it away in insurance on the credit default swap. Suppose the interest rate on a US Government bond is 5% and the interest rate on a General Motors bond of the same maturity is 8%. We’d expect the premium on a credit default swap on General Motors for the same period to be about 3%. Note that the 3% premium is also called the ‘spread’ on a credit default swap, since it is the spread between the government bond and the corporate bond interest rates.

In summary, a credit default swap is a contract where one party to the contract pays a small periodic premium to the other, in return for protection against a credit event (financial difficulty) of a known reference entity (company).

I wish there were more articles on financial products like this, written in plain English for non-Quants.

Leave a comment

Filed under Finance

Equality and Comparisons in F#

This blog post from Don Syme is really useful when considering options for customising equality and comparisons in F#. Having said that, with F# 2.0, it looks like you don’t need to put attributes on your type, it’s enough to follow Don’s overrides of GetHashCode, Equals and CompareTo.

Leave a comment

Filed under Programming

C++11 noexcept

Someone on ISOCpp re-awakened an old question on StackOverflow about noexcept, dynamic v static checking and differences between noexcept and the (now deprecated) throw specifiers.

Throw specifiers were the subject of Item 14 – Use Exception Specifications Judiciously in Scott Meyers’ More Effective C++. The drawbacks he mentions are: the standard prohibits compilers from rejecting calls to functions that might violate the exception specification (including if there is no specifier on the called function – this to allow integration with legacy code libraries that lack such specifications); you cannot know anything about the exceptions thrown by a template’s type parameters – so templates and exception specifications don’t mix; they’re easy to violate inadvertently (e.g. via callback functions); they lead to abrupt program termination when violated.

Stroustrup wrote this about noexcept in his C++11 FAQ:

If a function declared noexcept throws (so that the exception tries to escape the noexcept function) the program is terminated (by a call to terminate()). The call of terminate() cannot rely on objects being in well-defined states (i.e. there is no guarantees that destructors have been invoked, no guaranteed stack unwinding, and no possibility for resuming the program as if no problem had been encountered). This is deliberate and makes noexcept a simple, crude, and very efficient mechanism

This post gives a history of noexcept,

If the noexcept feature appears to you incomplete, prepared in a rush, or in need of improvement, note that all C++ Committee members agree with you. The situation they faced was that a safety problem with throwing move operations was discovered in the last minute and it required a fast solution

There are however important differences [between noexcept and throw()]. In case the no-throw guarantee is violated, noexcept will work faster: it does not need to unwind the stack, and it can stop the unwinding at any moment (e.g., when reaching a catch-all-and-rethrow handler). It will not call std::unexpected. Next, noexcept can be used to express conditional no-throw, like this: noexcept(some-condition)), which is very useful in templates, or to express a may-throw: noexcept(false).

One other non-negligible difference is that noexcept has the potential to become statically checked in the future revisions of C++ standard, whereas throw() is deprecated and may vanish in the future.

and this comment on SO from Jonathan Wakely also makes sense:

template code such as containers can behave differntly based on the presence or absence of noexcept (and equivalently throw()) so it’s not just about compiler optimizations, but also impacts library design and choice of algorithm. The key to doing that is the noexcept operator that allows code to query how throwy an expression is, that’s the new thing, and all that cares about is a yes/no answer, it doesn’t care what type of exception might be thrown, only whether one might be thrown or not

Leave a comment

Filed under C++

How to monitor, inspect and break on COM calls

A colleague recommended API Monitor from rohitab.com for monitoring COM calls between components. I’ve installed it and have to agree that it looks really promising:
APIMonitor
For the tool to be useful, you have to tell it about your custom COM interfaces by generating an XML file in a similar format to IDL – obviously room for improvement there by the authors (I wonder why they don’t read IDL files natively?). Having said that, once you have provided the interfaces, API Monitor will log all calls via those interfaces on any components that you specify. Better still, you can inspect the values in each call and even set breakpoints that will take you into the debugger of your choice (e.g. Visual Studio).

Leave a comment

Filed under Programming

NFC key to the future

Clever new uses for NFC-enabled phones.

Leave a comment

Filed under Technology

How to pull water out of thin air

Amazing article on an engineering project

20130305-190014.jpg

with real social benefits.

Leave a comment

Filed under Technology

Latest “Fat Finger” trade

TheTradeNews.com reports that a trade input error caused an inflated sell order to be posted on Nasdaq OMX Stockholm, leading to ABN AMRO being fined this week.

The sponsored access client put in a negative value of -5,000 shares in the volume field for a sell order, which its own trading system erroneously converted to more than 294 million shares. This order, for shares in Swedish manufacturer SKF, was sent to the market despite constituting around 70% of outstanding SKF shares and resulted in the execution of 800,000 shares.

It’s amazing that this was a manually entered trade, yet didn’t have sufficient data validation, let alone pre-trade controls.

Leave a comment

Filed under Finance

How to recover accidentally deleted files

I was over-zealous when clearing space on my hard disk and accidentally deleted a project that wasn’t completely under source control. Fortunately, WinUndelete came to the rescue. It finds files that weren’t even in the recycle bin and allows you to restrict the search to only the file extensions you need (making it much faster than some competitor products). The restore worked perfectly – although the display of the found files wasn’t that pretty, it did the job. My only gripe was the cost – $49.95 seems pretty high when I only needed two files. Still, it was worth it to avoid repeating half a day of development.

Leave a comment

Filed under Technology

Alleged insider trading in Heinz options

CNBC reports on an alleged case of insider trading:

The SEC says a trader purchased 2,500 out-of-the-money call options on shares of Heinz for $95,000 on Feb. 13. The options give the purchasers the right to acquire 250,000 shares at $65 each until June. The stock was trading at just over $60 a share at the time. The out-of-the-money call options weren’t very popular. On Feb. 12, only 14 $65 June call options were traded. On the day before, none at all.

When Berkshire Hathaway and 3G Capital Management announced a buyout, the stock rose to about $72. The price of the June 65 call options, now very much in the money, surged 1,700 percent. The $90,000 investment had been turned into $1.8 million.

The article points out that the SEC has frozen the Zurich-based trading account, leaving the beneficiary a dilemma – though their identity is confidential under Swiss-banking rules, they would have to go to court in the US to unfreeze the assets:

At that point, the SEC will likely publicly brand this person a securities fraud. If the trader doesn’t come forward by June, his investment goes to zero.

Leave a comment

Filed under Finance