|« Pretty Basic Validation||The "Who Knows?" Code »|
Brad’s phone rang with the telltale tone of an inner-office call. “Yeah,” he briskly blurted out as he picked up the phone, “what’cha ya need?” That was actually his nice way of answering the phone. As the senior trader at Æxecor, one of the world’s largest energy trading companies, Brad didn’t need to impress anyone and, in his mind, displaying anything less than vicious hubris would be a sign of weakness.
“Err,” the receptionist nervously answered, “there’s a… err, delivery for you, sir. They—”
“Hmphf,” Brad’s scoff cut her off. “So just sign for it, then! Is that really that hard to do? You can do that, can’t you?”
“Well sir,” the receptionist winced, “they’re asking for mooring instructions? And we need to pay wharfage charges? They said you’d know. I’m at a loss.”
“Fine,” Brad scowled, “I guess I have to do everything around here!” He slammed down the phone and marched out of his corner office. Despite Æxecor’s location – the “old docks” district – their office was one of the most posh in the city. On one end of the expansive, former warehouse sat the executive suites, which had a tremendous view of the city skyline. The other end – where Brad was headed towards – was the reception which overlooked its own, private bay on the river.
“Okay, I’m here!” he angrily announced once he stepped foot in the lobby. “So let’s do this! What do I need to—”
Brad stopped mid-sentence. His eyes were immediately drawn through the floor-to-ceiling windows and onto the river bay that Æxecor’s building overlooked. There was an absolutely gigantic barge – nay, an armada of tightly-connected barges – overfilled with enormous piles of coal that was attempting to dock in front of the building. “What… the… fuuu—”
“You mus’ be Brad,” a cheerful voice jumped in. Brad’s eye’s shifted towards the scruffy fellow wearing some sort of workman’s uniform who was sitting in one of the reception chairs. “Now first and foremost, how in the Sam Hill are we ‘sposed to moor this boat? I count two cleats, but we sure as heck can’t hitch these. And, shoot, do you even have a bulk berth?”
For once, Brad was speechless. He had absolutely no idea who that man was and he could hardly understand a word he said. Plus, there was that gargantuan vessel that was slowly moving towards the building. “Uhh,” he stuttered, “wait. Are you delivering… coal? To… uhh, us?”
“Well, yeah! Twenty-eight thousand tons of the good ol’ black gold!” The workman sarcastically furrowed his brow adding, “I mean, we did get the right address, har har. This is Æxecor? And this is Pier 53? And you are Brad, the fella who ordered it, right?”
It was that moment that Brad’s palm almost immediately made contact with his forehead. He realized that something must have really gone awry: instead of virtually trading 28,000 tons of coal, Brad had somehow ended up with 28,000 tons of real coal.
If you’ve ever watched Trading Places, the 1983 classic starring Eddie Murphy and Dan Aykroyd, then you’re probably at least familiar with commodities markets. At a basic level, commodities such as gold, wool, and soy beans are sold by producers and, eventually, delivered to buyers. But Billy Ray Valentine didn’t strike it rich and bankrupt the Duke Brothers by hauling around Frozen Concentrated Orange Juice (FCOJ); instead, they worked the commodities market by buying and selling FCOJ futures contracts. Actually, that’s really the only way to trade in commodities.
A futures contract is pretty straight forward: you agree to buy X units of commodity Y at $N per unit at some fixed future date. While it might seem a bit strange for an individual to agree to buy twenty tons of pork bellies in April for $34,420 (even if he really loves bacon), the idea is to sell the to-be-delivered pork bellies long before April, and to sell them for more than $34,420. Just about every conceivable commodity is bought and sold in this manner long before the commodity is even produced. The whole point of all this trading is to shift the risk (and rewards) of fluctuating commodity prices from the producers (farmers, miners, etc) to the traders.
Of course, because commodity traders don’t actually want to be stuck with tons and tons of pork bellies, a whole series of middlemen — from the brokers to the exchanges to the clearing houses — work hard to ensure that, when you say "I’ll buy 300 tons of pork bellies for $518,000 in May," you don’t actually buy 300 tons of pork bellies for $518,000 in May.
Brokers, for example, will set up round-turn trades so that, for each futures contract purchased, an offsetting contract can be sold to whoever actually wants to buy the goods. The exchange’s automated trading systems have all sorts of rules-engines to make sure that obvious errors (like delivering truckloads of commodities to a commercial office park) don’t slip through. And finally, processors at the clearing house will double-check transactions to make sure they weren’t sent over in error.
All that said, it’s almost impossible for traders to actually buy the commodities they are buying. Well, almost impossible.
Æxecor traded coal on only one exchange (the WTFSE), and they didn’t trade coal very often. As such, when WTFSE upgraded its public-facing, WebService-based API, Æxecor’s internal trading system could no longer communicate with it. With a couple pending coal trades, this presented a bit of a problem.
Fortunately, Æxecor had a staff of crack programmers, and they were able to hack together a solution that worked with the WTFSE’s new API. Essentially, the coder added a bit of XML to their trading requests, including this following snippet.
<AdditionalProperties> <PhysicallyDeliver> <value>False</value> </PhysicallyDeliver> </AdditionalProperties>
Notice anything off about that XML? If you said, “value should be 0 instead of False”, then give yourself a pat on the back. As it turned out, WTFSE only recognized 1’s and 0’s to represent True and False and, if the value was nether 1 nor 0, it simply defaulted to 1. Whoops!
Now, this normally wouldn’t have been that big of a deal; to ensure accurate transactions, the WTFSE (and just about all other exchanges) sends back a trade confirmation with all of the original information encoded in their XML. That way, both parties have to understand each other’s data. On Æxecor's end, everything looked hunky dory, especially as a result of the following line of code.
bool physicallyDeliver = (getNodeVal("PhysicallyDeliver").toLower() == "true");
Kudos to the developer for verifying the correct case... but, a string can be infinitely more things than simply "true" or "false". Such as "1" or "0". Whoops.
Even a mistakenly confirmed incorrect trade shouldn’t have been that big of a deal, since the clearing house would notice some pretty big problems with the trade. You can’t just call up FedEx and request delivery of thousands upon thousands of tons of raw material to some office complex downtown. Commodities can only be delivered to a fixed number of delivery points, such as warehouses adjacent to train yards or ports. Of course, since Æxecor’s offices were in located on Pier 53, a recently redeveloped warehouse district off the river, it would have seemed like the logical place to accept delivery of a whole bunch of coal, especially to a rules engine. Whoops.
Fortunately, the commodity futures trading market doesn’t rely entirely on software. There are back-office personnel on both sides of the transaction (and several places in the middle) to make sure that a trader doesn’t do something silly like accidently click the “physically deliver” checkbox, enter into round-turn trades that creates an instant net loss, and so on.
So with everyone looking over transactions, you’d think that someone along the way would have noticed that trading giant Æxecor asked for physical delivery of a million-and-a-half dollars worth of coal. Actually, someone probably did, but because the trade came from Brad, there was just no way it could be made in err.
As the senior trader at Æxecor, Brad made it very clear that no one — “not even His Holiness, the Pope” — shall question his trades. After all, Brad makes complex trading decisions that no one else could possibly comprehend. Sometimes he buys high and sells low. Sometimes he holds in a decline. Sometimes he refuses to sell at any price. Brad works in mysterious ways, and if he said “do it”, then it better get done.
“Now don’t go telling me that this coal ain’t yours,” the workman said defensively, sensing something was awry. “I mean, if you don’t want it, that’s your business. But this here is your coal, mister Brad.”
As much as Brad wanted to deny it, he knew it was his. And not only that, but he had haughtily confirmed, re-confirmed, and re-re-confirmed with Æxecor’s own back-office processing team. He had just assumed, like he always did, that the mouth-breathing paper-pushers couldn’t read English. As he played back the last thing he told one of the processors about the coal order – “what part of ‘execute my f*ing trade’ don’t you understand!?” – he wondered what he could possibly do with 56,000,000 pounds of real coal.
Try to imagine for a moment how you would unload a mountain of coal worth million-and-a-half dollars. Craigslist does have its limits, after all.
As it turned out, it was more difficult than Brad could have ever imagined to sell real coal. The commodities market really only deals in futures, and everyone who actually needs 28,000 tons of coal has bought it long in advance. And besides, who wants to buy coal from some guy named Brad? Eventually, after paying exorbitant wharfing, shipping, environmental, docking, unloading, loading, and multiple-fee fees, Brad was finally able to unload it for twenty cents on the dollar.
Ever since “The Big Purchase”, Brad has never been able to live down his mountain of coal. Every time he passed others in the hallway, he knew that they knew about the coal, and they knew that he knew that they knew. No one really poked fun or laughed at him, but it didn’t matter. Brad was no longer thought of the senior trader at Æxecor; instead, he was the guy who accidently bought all that coal.
|« Pretty Basic Validation||The "Who Knows?" Code »|