<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>voyce &#187; Finance</title>
	<atom:link href="http://www.voyce.com/index.php/category/finance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Sun, 15 Jan 2012 13:10:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tax Avoidance 2.0</title>
		<link>http://www.voyce.com/index.php/2012/01/06/tax-avoidance-2-0/</link>
		<comments>http://www.voyce.com/index.php/2012/01/06/tax-avoidance-2-0/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 00:05:21 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1430</guid>
		<description><![CDATA[Tax avoidance is rife in the new (and existing) generation of tech companies.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2012/01/dislike.png"><img src="http://www.voyce.com/wp-content/uploads/2012/01/dislike.png" alt="dislike" title="dislike" width="210" height="95" class="alignleft size-full wp-image-1443" /></a>Warning: This is a bit off-topic for my blog, but I had to write it and get it off my chest. </p>
<p>In these times of financial woe, people love to complain about all the big, nasty, faceless companies avoiding paying tax. They inevitably moan about it on Facebook, Google and Twitter (and sometimes even do something about it in the real, physical, world). But what about those companies themselves? The Web 2.0 behemoths are now some of the largest companies in the world, and they&#8217;ve decided &#8211; just like the evil old companies &#8211; that they don&#8217;t like paying all that tax. Don&#8217;t be evil&#8230; and don&#8217;t pay any tax if you can help it. But how do they do it?<br />
<span id="more-1430"></span></p>
<h2>The Numbers</h2>
<p>An Irish Times <a href="http://www.irishtimes.com/newspaper/finance/2011/1223/1224309416349.html">newspaper article</a> caught my eye the other day. It discusses the rapid growth of Facebook&#8217;s Dublin operation in 2010, whose accounts have just been published (as they must be by law, despite FB&#8217;s apparent reluctance). The headline figure is that:</p>
<blockquote><p>
[Revenue] is up from €15.2 million to <b>€229.1 million</b>
</p></blockquote>
<p>That&#8217;s a pretty significant increase! But that&#8217;s only revenue, how much of it was left over as profit?</p>
<blockquote><p>
Facebook Ireland generated a pretax profit of <b>€1.9 million</b>
</p></blockquote>
<p>What?! Where did the other €227 million go? </p>
<p>According to the article it mostly disappeared into a mysterious black hole known as &#8220;administrative expenses&#8221;:</p>
<blockquote><p>
Administrative expenses increased &#8230; to €221.6 million as a result of &#8230; royalties paid to other Facebook entities for services provided during the year.
</p></blockquote>
<h2>How do they do that?</h2>
<p>Is it me or does that sound suspicious? Well, it should do, because it is. </p>
<p>It turns out that Ireland&#8217;s significantly lower rate of corporation tax (12% vs 26% in the UK, and one of the lowest in the world) isn&#8217;t the only reason why companies like Facebook, <a href="http://www.guardian.co.uk/business/ireland-business-blog-with-lisa-ocarroll/2011/mar/24/google-ireland-tax-reasons-bermuda">Google et al move there</a>. There&#8217;s also the very useful fact that, unlike most developed economies, Ireland chose not to introduce any legislation to prevent companies siphoning off their revenue to low-or-no-tax regimes like the Cayman islands or Bermuda.</p>
<p>So that&#8217;s where the &#8220;missing&#8221; €221 million has ended up: it&#8217;s been paid from the Irish part of the business to the tax-haven subsidiary, leaving only a small amount subject to corporation tax in Ireland. This practise is known in tax circles as the &#8220;double Irish&#8221;, and it (along with its Dutch equivalent) seems to be fairly widely used and well understood, even having its own <a href="http://en.wikipedia.org/wiki/Double_Irish_arrangement">wikipedia entry</a>. Of course Facebook now funnels as much as possible of the revenue from the UK (its second biggest market) through the Ireland operation to get the most out of this arrangement. That explains the large increase in the numbers since last year. </p>
<p>There are many high-profile tech companies that have Dublin operations and may be avoiding tax in this way, including:</p>
<ul>
<li>Facebook</li>
<li>Twitter</li>
<li>LinkedIn</li>
<li>Google</li>
<li>Microsoft</li>
<li>Oracle</li>
</ul>
<p>That&#8217;s quite a roll call.</p>
<h2>The Result</h2>
<p>The result of all these shenanigans for Facebook? It pays a ridiculously small effective tax rate of less than 1%, even better than <a href="http://www.businessweek.com/technology/google-tax-cut/google-terminal.html">Google&#8217;s 2.4% rate</a>.  And given Ireland&#8217;s <a href="http://news.businessweek.com/article.asp?documentKey=1376-LXBO661A1I4H01-4A40DCQ22ID111VEL291CSBQT6">current economic state</a> I can&#8217;t imagine their government will be introducing more restrictive tax legislation any time soon in an attempt to crack down on it. They can&#8217;t risk these big companies abandoning their new homes in Dublin&#8217;s <a href="http://www.irishtimes.com/newspaper/finance/2011/0930/1224305000761.html">Silicon Dock</a>.</p>
<p>Of course, you should feel free to &#8216;like&#8217; this blog post on Facebook, after all, what will it cost you?</p>
<p>(* Disclaimer: These are solely my opinions, not those of my employer or anyone else).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2012/01/06/tax-avoidance-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginning F#: Positive Discrimination</title>
		<link>http://www.voyce.com/index.php/2010/11/29/fsharp-positive-discrimination/</link>
		<comments>http://www.voyce.com/index.php/2010/11/29/fsharp-positive-discrimination/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 23:24:46 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1068</guid>
		<description><![CDATA[Discriminated unions for the rest of us.]]></description>
			<content:encoded><![CDATA[<p>(or &#8220;Discriminated unions for dummies like me&#8221;, or &#8220;Tagged unions for the rest of us&#8221;)</p>
<p>Discriminated unions are one of those things in the lexicon of functional programming that can often sound baffling to &#8220;outsiders&#8221;; it&#8217;s almost up there with monads and currying. But in practice they&#8217;re simple and incredibly useful. I thought I&#8217;d try and show a concrete example of where they can be used in a way which is more powerful and robust than the equivalent OO approach.<br />
<span id="more-1068"></span></p>
<h3>The usual suspects</h3>
<p>When people first start looking at functional programming, they often come across examples that implement a compiler, and this is their first exposure to discriminated unions. Unfortunately these examples tend to use complex recursive discriminated unions to represent the language syntax tree, which can be a bit of turn-off for anyone who&#8217;s not a language geek.</p>
<h3>A problem</h3>
<p>The way I like to think of DUs is a means of easily and precisely specifying a set of types that we&#8217;re expecting to work with. </p>
<p>What do I mean by this? Well, imagine you&#8217;re writing some code that can work on various different types, and you need to identify some common aspect to identify them. For example, you&#8217;re valuing different financial product types: swaps, swaptions, caps and floors. Although each of these trade types would be represented differently, you may want to perform the same operation across all of them.</p>
<h3>The OO approach</h3>
<p>The normal OO approach would be to use an interface; implemented by all of the types and consumed by our method. For instance:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Swap <span style="color: #008000;">:</span> <span style="color: #0600FF;">public</span> IValuable <span style="color: #000000;">&#123;</span> ... <span style="color: #000000;">&#125;</span>
<span style="color: #FF0000;">class</span> Swaption <span style="color: #008000;">:</span> <span style="color: #0600FF;">public</span> IValuable <span style="color: #000000;">&#123;</span> ... <span style="color: #000000;">&#125;</span>
...
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">double</span> ValueTrades<span style="color: #000000;">&#40;</span>IValuable<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> trades<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> ... <span style="color: #000000;">&#125;</span></pre></div></div>

<p>But this isn&#8217;t particularly elegant or easy. For a start it requires that the type implement the interface &#8211; what if you&#8217;re working with externally provided types that can&#8217;t be changed? The other thing is that interfaces tend to give you a false sense of security about type safety. Given that we know there&#8217;s an object implementing the interface, I&#8217;ve all too often seen OO code taking an interface parameter then immediately type-casting it to another interface that the underlying object is expected to support. Run-time typing failures FTL.     </p>
<h3>The union</h3>
<p>So how could we implement this using discriminated unions instead?</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">type</span> Trade <span style="color: #000080;">=</span> 
    <span style="color: #000080;">|</span> SwapTrade <span style="color: #06c; font-weight: bold;">of</span> Swap
    <span style="color: #000080;">|</span> SwaptionTrade <span style="color: #06c; font-weight: bold;">of</span> Swaption</pre></div></div>

<p>What we&#8217;ve done is create a new type that consists of exactly one of its possible cases. We identify each case with a tag (in fact, these types are often called tagged unions) called SwapTrade and SwaptionTrade and separate them with the bar &#8216;|&#8217;. </p>
<p>Easy, isn&#8217;t it? But, err, how do we get to the actual thing we want? Well that&#8217;s where another functional programming staple steps in: pattern matching. We can add some code that will match against the possible union cases and allow us to get at the type itself:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> valueTrades <span style="color: #000080;">&#40;</span>trades <span style="color: #000080;">:</span> Trade list<span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #000080;">...</span>
    <span style="color: #505090;">trades</span> <span style="color: #000080;">|&gt;</span> List<span style="color: #000080;">.</span><span style="color: #505090;">iter</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> t <span style="color: #000080;">-&gt;</span>
        <span style="color: #06c; font-weight: bold;">match</span> t <span style="color: #06c; font-weight: bold;">with</span> 
        <span style="color: #000080;">|</span> SwapTrade s <span style="color: #000080;">-&gt;</span> <span style="color: #060; font-style: italic;">(* do something with s *)</span> <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> 
        <span style="color: #000080;">|</span> SwaptionTrade st <span style="color: #000080;">-&gt;</span> <span style="color: #060; font-style: italic;">(* do something with st, which is of type Swaption *)</span> <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
        <span style="color: #000080;">&#41;</span></pre></div></div>

<p><div id="attachment_1082" class="wp-caption alignright" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/10/pattern_warning.png"><img src="http://www.voyce.com/wp-content/uploads/2010/10/pattern_warning-300x71.png" alt="Pattern matching warning" title="pattern_warning" width="300" height="71" class="size-medium wp-image-1082" /></a><p class="wp-caption-text">Pattern matching warning</p></div>And one of the big advantages here is that we get compile time checking; the compiler will warn us if we fail to deal with any of the union cases. In other words, if we add a new case to the <code>Trade</code> union, we&#8217;ll get a warning if we fail to deal with it wherever we&#8217;ve pattern-matched against it. In fact, that&#8217;s the fundamental difference between this and the interface approach; in theory the interface approach means we can chuck anything we like at it; as long as it supports the interface it will work. In the discriminated union version we&#8217;re being explicit about exactly what types we can handle.</p>
<p>Hope you found this useful. As a long-term OO developer moving to functional programming it certainly helps me to see how aspects of FP can be applied to common OO problems. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/11/29/fsharp-positive-discrimination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating and plotting random numbers</title>
		<link>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/</link>
		<comments>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 23:44:55 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=562</guid>
		<description><![CDATA[An example of generating random numbers in F# and visualising their distribution using the WPF charting control.]]></description>
			<content:encoded><![CDATA[<p>For a while now I&#8217;ve been planning to write a blog post about pricing financial instruments using Monte Carlo techniques in F#. As part of this I needed to generate normally distributed random numbers, and while putting together the code to do it I realised it was interesting enough to warrant its own post.</p>
<p>I&#8217;m making use of a few F#/.NET idioms to make the process easier. For instance, sequences (.NET&#8217;s <code>IEnumerable</code>) are used as the source of uniformly distributed random numbers. Also, to verify that the resulting numbers are actually normally distributed, we can easily use existing WPF/silverlight controls to visualise the values direct from within Visual Studio, in a manner similar to <a href="http://www.voyce.com/index.php/2009/06/26/black-scholes-option-pricing-using-fsharp-and-wpf/">this previous post</a> &#8211; but without having to write the plotting code ourselves.<br />
<span id="more-562"></span></p>
<h3>Implementation</h3>
<p>So firstly, we create the random number stream:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> rr <span style="color: #000080;">=</span> System<span style="color: #000080;">.</span><span style="color: #505090;">Random</span><span style="color: #000080;">&#40;</span>System<span style="color: #000080;">.</span><span style="color: #505090;">DateTime</span><span style="color: #000080;">.</span><span style="color: #505090;">Now</span><span style="color: #000080;">.</span><span style="color: #505090;">Minute</span><span style="color: #000080;">&#41;</span>
<span style="color: #06c; font-weight: bold;">let</span> rands <span style="color: #000080;">=</span> seq <span style="color: #000080;">&#123;</span> <span style="color: #06c; font-weight: bold;">while</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: #06c; font-weight: bold;">yield</span> rr<span style="color: #000080;">.</span><span style="color: #505090;">NextDouble</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">&#125;</span></pre></div></div>

<p>As you can see <code>rands</code> is an infinite sequence. As such, you should be wary of the &#8220;eager&#8221; functions from the Seq module that attempt to consume the entire sequence at once, they&#8217;ll obviously cause a problem here. Also notice that I&#8217;ve picked a somewhat dubious seed for the random number generator, as this is only for demonstration purposes.</p>
<p>In order to obtain normally distributed random numbers I&#8217;m using the <a href="http://en.wikipedia.org/wiki/Box–Muller_transform">Box-Muller</a> transform. I started off with an implementation transcribed from VBA (from <a href="http://www.amazon.com/gp/product/0470319585?ie=UTF8&#038;tag=wwwvoycecom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0470319585">Wilmott</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwvoycecom-20&#038;l=as2&#038;o=1&#038;a=0470319585" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> et al) &#8211; yes, yes, I know &#8211; but of course this used mutable references. Not nice. So I reworked it a little to use <code>Seq.pick</code>, which takes items from the sequence while a predicate returns <code>None</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> boxMuller <span style="color: #06c; font-weight: bold;">_</span> <span style="color: #000080;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #000080;">&#40;</span>x,dist<span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span> 
        rands
        <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">pick</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> x <span style="color: #000080;">-&gt;</span>
            <span style="color: #06c; font-weight: bold;">let</span> x <span style="color: #000080;">=</span> <span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> x <span style="color: #000080;">-</span> <span style="color: #c6c;">1.0</span>
            <span style="color: #06c; font-weight: bold;">let</span> y <span style="color: #000080;">=</span> <span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#40;</span>Seq<span style="color: #000080;">.</span><span style="color: #505090;">take</span> <span style="color: #c6c;">1</span> rands<span style="color: #000080;">&#41;</span> <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">hd</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">-</span> <span style="color: #c6c;">1.0</span>
            <span style="color: #06c; font-weight: bold;">match</span> <span style="color: #000080;">&#40;</span>x <span style="color: #000080;">*</span> x <span style="color: #000080;">+</span> y <span style="color: #000080;">*</span> y<span style="color: #000080;">&#41;</span> <span style="color: #06c; font-weight: bold;">with</span>
                <span style="color: #000080;">|</span> dist <span style="color: #06c; font-weight: bold;">when</span> dist <span style="color: #000080;">&lt;</span> <span style="color: #c6c;">1.0</span> <span style="color: #000080;">-&gt;</span> Some <span style="color: #000080;">&#40;</span>x,dist<span style="color: #000080;">&#41;</span>
                <span style="color: #000080;">|</span> dist <span style="color: #000080;">-&gt;</span> None
            <span style="color: #000080;">&#41;</span> 
    x <span style="color: #000080;">*</span> Math<span style="color: #000080;">.</span><span style="color: #505090;">Sqrt</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">-</span><span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> Math<span style="color: #000080;">.</span><span style="color: #505090;">Log</span><span style="color: #000080;">&#40;</span>dist<span style="color: #000080;">&#41;</span> <span style="color: #000080;">/</span> dist<span style="color: #000080;">&#41;</span></pre></div></div>

<p>It&#8217;s not particularly efficient as we&#8217;re consuming two uniform numbers to generate one normal one &#8211; hence the additional Seq.take within the pick. Of course we could change the function to return the 2 generated numbers as an extra element in the tuple.</p>
<p>Next, let&#8217;s generate some numbers, and get them in a suitable form to display:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> makeData <span style="color: #06c; font-weight: bold;">_</span> <span style="color: #000080;">=</span>
    Seq<span style="color: #000080;">.</span><span style="color: #505090;">init</span> <span style="color: #c6c;">100000</span> boxMuller
    <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">countBy</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> d <span style="color: #000080;">-&gt;</span> 
        <span style="color: #06c; font-weight: bold;">let</span> d <span style="color: #000080;">=</span> decimal d
        Math<span style="color: #000080;">.</span><span style="color: #505090;">Round</span><span style="color: #000080;">&#40;</span>d, <span style="color: #c6c;">1</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">sortBy</span> fst</pre></div></div>

<p>We initialise a sequence with an arbitrary amount of numbers (100000, enough to get a good distribution, hopefully), then use <code>Seq.countBy</code> to do a naive grouping that allows us to see how the numbers are distributed, i.e. counting how many numbers fit in each 0.10 bucket. We then sort the output by bucket. </p>
<h3>Visualisation</h3>
<p>Now we can display what we&#8217;ve got. We can create a simple WPF object-model using imperative code, including the very useful chart control from the WpfToolkit. The chart control enables us to add a series and set our <code>seq&lt;decimal * float&gt;</code> directly as the series ItemsSource, which is the standard way to specify the items for a collection control. If you specify the tuple <code>Item1</code> and <code>Item2</code> properties for the bindings, WPF will be able to access the data from each element, and that&#8217;s all you need.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;">    <span style="color: #06c; font-weight: bold;">let</span> series <span style="color: #000080;">=</span> 
        ColumnSeries<span style="color: #000080;">&#40;</span>
            IndependentValueBinding <span style="color: #000080;">=</span> Data<span style="color: #000080;">.</span><span style="color: #505090;">Binding</span><span style="color: #000080;">&#40;</span><span style="color: #008080;">&quot;Item1&quot;</span><span style="color: #000080;">&#41;</span>,
            DependentValueBinding <span style="color: #000080;">=</span> Data<span style="color: #000080;">.</span><span style="color: #505090;">Binding</span><span style="color: #000080;">&#40;</span><span style="color: #008080;">&quot;Item2&quot;</span><span style="color: #000080;">&#41;</span>,
            ItemsSource <span style="color: #000080;">=</span> makeData <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> chart <span style="color: #000080;">=</span> Chart<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    chart<span style="color: #000080;">.</span><span style="color: #505090;">Series</span><span style="color: #000080;">.</span><span style="color: #505090;">Add</span> series
    Window<span style="color: #000080;">&#40;</span>
        Name<span style="color: #000080;">=</span><span style="color: #008080;">&quot;Plot&quot;</span>,
        Title<span style="color: #000080;">=</span><span style="color: #008080;">&quot;Normally distributed random numbers&quot;</span>,
        Width<span style="color: #000080;">=</span><span style="color: #c6c;">900.0</span>,
        Height<span style="color: #000080;">=</span><span style="color: #c6c;">700.0</span>,
        Content<span style="color: #000080;">=</span>chart,
        Visibility<span style="color: #000080;">=</span>Visibility<span style="color: #000080;">.</span><span style="color: #505090;">Visible</span><span style="color: #000080;">&#41;</span></pre></div></div>

<p>Here&#8217;s the resulting output:<br />
<img src="http://www.voyce.com/wp-content/uploads/2009/11/dist-300x233.png" alt="dist" title="dist" width="300" height="233" class="alignleft size-medium wp-image-576" />As I&#8217;ve mentioned before, this is a fantastically immediate way of doing numerical development in Visual Studio. You can enter all of this code directly into F# interactive within VS, iterate, and quickly see the effect that your changes have. It&#8217;s just as interactive as using the graph features in Excel, and the resulting code is much more easily reusable.</p>
<p><span style="visibility:hidden"> XD5RRV3XDNHN </span><br />
<script type="text/javascript" src="http://www.assoc-amazon.com/s/link-enhancer?tag=wwwvoycecom-20&#038;o=1">
</script><br />
<noscript><br />
    <img src="http://www.assoc-amazon.com/s/noscript?tag=wwwvoycecom-20" alt="" /><br />
</noscript></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ending the love affair with Excel</title>
		<link>http://www.voyce.com/index.php/2009/07/08/ending-the-love-affair-with-excel/</link>
		<comments>http://www.voyce.com/index.php/2009/07/08/ending-the-love-affair-with-excel/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 22:30:17 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=171</guid>
		<description><![CDATA[It's a well known fact that the financial services industry (where I mean banks, hedge funds, pension providers, fund managers etc) is deeply in love with Excel. But what is it about the Excel ecosystem that makes it so appealing, and how can we move seamlessly to a more robust, maintainable platform?]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_214" class="wp-caption alignleft" style="width: 160px"><a href="http://72.47.193.211/wp-content/uploads/2009/07/spreadsheets_mug.png"><img src="http://www.voyce.com/wp-content/uploads/2009/07/spreadsheets_mug-150x150.png" alt="I heart spreadsheets" title="I heart spreadsheets" width="150" height="150" class="size-thumbnail wp-image-214" /></a><p class="wp-caption-text">I heart spreadsheets</p></div>It&#8217;s a well known fact that the financial services industry (where I mean banks, hedge funds, pension providers, fund managers etc) is deeply in love with Excel. But what is it about the Excel ecosystem that makes it so appealing?</p>
<p>Unfortunately, given the ever-increasing focus on accountability and scalability in these domains, Excel is also an increasingly inappropriate platform for delivery of this sort of functionality. How can organisations ease the transition away from this environment to something more easily manageable, while retaining it&#8217;s positive benefits?</p>
<p><span id="more-171"></span></p>
<blockquote><p>Disclaimer: These are my own views and not those of my employer. The scenarios I describe are fictitious and not based on actual practices at my place of employment. Any similarity to actual events and behaviours is coincidental.
</p></blockquote>
<p>I see two main aspects of Excel&#8217;s operation that prove valuable in general, and in finance in particular: visibility and immediacy.</p>
<h3>Visibility</h3>
<p>From an end user&#8217;s point of view, one of the most positive aspects of Excel is it&#8217;s transparency. Even in an environment where complex processing goes on inside a plugin &#8211; say, an Excel user defined function (UDF) packaged as an XLL &#8211; it&#8217;s still only in the scope of a single function call in a single cell. You continue to get good visibility of the inputs and outputs from the function.</p>
<p>You can also get a good higher-level view of how the different parts of the calculation fit together. Either by inspection, editing the formula to quickly see which cells it references, or by using the formula auditing toolbar to get an overlay of dependent and precedent functions, you can see roughly how various parts of the calculation fit together.</p>
<p>This, combined with the logical separation of functionality into separate worksheets, gives you the impression of understandability.</p>
<p>The problem is that it&#8217;s just that &#8211; an impression &#8211; there is no structure enforced by the worksheet separation, you&#8217;re free to link between them as you see fit, and this can result in an extremely complex and virtually indecipherable &#8220;flow&#8221; of calculation within a workbook.</p>
<h3>Immediacy</h3>
<p>Luckily, to offset the complexity we have another important aspect of Excel&#8217;s usability: it&#8217;s immediacy.</p>
<p>Trading users can very quickly modify calculation trees to perform ad-hoc additional calculations such as applying spreads, and to gauge the effect of market moves on their portfolio, i.e. &#8220;what-if&#8221; scenarios.</p>
<p>Structuring users can fairly easily &#8211; given an existing set of functional pieces &#8211; assemble a model to price a complex new trade type. Although this is a much less common use case now that the demand for getting new structured products to market quickly has essentially vanished.</p>
<p>As well as this type of gross modification, it&#8217;s also possible to just repeatedly re-evaluate some small part of the calculation to quickly determine how it is affected by other changes.</p>
<p>The immediacy of the Excel environment, combined with the use of the Visual Basic for Applications (VBA) scripting language, enables both business and IT users to rapidly build out new sheets to perform ad-hoc tasks. Rapid application development, or RAD as it&#8217;s known, is all well and good for performing some transient, ad-hoc calculation for limited use, but unfortunately these tools have the habit of becoming indispensable parts of an organisation&#8217;s workflow. That&#8217;s when you start to see serious problems with scalability and maintainability.</p>
<h3>The problem?</h3>
<p>So the fundamental tension here is that exactly the same features which make Excel useful to traders, structurers, etc., also make it highly unsuitable for use in these environments. You really don&#8217;t want traders to be able to subtley alter the flow of the calculation, as much as they might like to. Excel should really be a read-only view on some underlying trade data source and calculation engine, but this isn&#8217;t always how it&#8217;s implemented.</p>
<p>You also want to provide some flexibility &#8211; the ability to experiment, explore and examine &#8211; but within certain constraints and without compromising future requirements. Being able to price a trade is a good start, but you will subsequently need to book it easily, re-value it reliably and potentially risk manage a large portfolio of them.</p>
<h3>Moving away from Excel</h3>
<p>Many houses provide underlying quant analytics implemented in C++, with a native C++ interface and a variety of other (sometimes auto-generated) wrappers that make it accessible in other environments. Ideally, the amount of actual functionality in these wrapper layers should be kept to an absolute minimum. It should be commodity code that can be regenerated as and when required.</p>
<p>However, even if this is the case, unless you have the ability in the underlying code to fan-out the processing you will still be constrained by the operating system process limits, e.g. 4gb address space.</p>
<p>The common alternative to hosting pricing and risk management within Excel is to write new dedicated applications to perform the calculations and (hopefully) provide a means to inspect and troubleshoot it.</p>
<p>Unfortunately these systems are built by teams who aren&#8217;t particularly familiar with the way the front office uses Excel. It&#8217;s often the case that spreadsheet development teams and systems development teams don&#8217;t interact; the former tend to be based on the trading desk while the latter are in another part of the building.</p>
<p>So the end result can end up being systems that work in a way developers feel comfortable with, rather than the way business users would like them to work. This can make the system seem like a black box to it&#8217;s users. And to make it worse these are the users who are accustomed to Excel&#8217;s high levels of transparency.</p>
<p>Although the system may be enforcing the fact that trade value is strictly a function of the trade, market and static data, having some transparency can still be valuable in giving skilled users confidence in the underlying calculation. They can apply their not-inconsiderable intuitive abilities to quickly gauge the correctness or otherwise of the valuation. It can help the quants move away from their native Excel/Matlab-style iterative development environment. And when groups need to work together to reconcile differences, everyone can benefit.</p>
<p>The problem? This amount of transparency has to be built into the system or the quant library pretty much from the ground up.</p>
<h3>Solutions</h3>
<p>One possible approach is to make your system a general purpose calculation engine. This has some appeal, but you have to be careful about sacrificing performance for generality. You might be tempted to try exactly matching the semantics of Excel&#8217;s calculation and type system. This can be a nightmare, with all sorts of limitations and nasty edge cases. For example, the fact that errors are a simple numeric value with no facility to carry extra information is crippling, and also the lack of support for objects as first class values in the type system.</p>
<p>However you choose to implement your calculation engine, ensure that it&#8217;s loosely coupled enough to be run out-of-process or across machine boundaries without code changes.</p>
<p>Here are some bullet-point takeaways for easing the transition:</p>
<ol>
<li><strong>Provide a means for users to examine intermediate calculations, and surface it in the UI.</strong><br />
This will give your intermediate and end users confidence in the calculations
</li>
<li><strong>Provide a means to capture and re-play valuations, including all their inputs and outputs.</strong><br />
	This will assist in reconciling valuations, and in passing snapshots around between groups.
</li>
<li><strong>Provide the ability to drive the system programatically.</strong><br />
	Along with persistent valuations, this will help in regression testing
</li>
</ol>
<p>I hope this post has served to give you some insights into the potential challenges of moving users away from Excel into more robust systems, why some of those users may be reluctant to move, and how you can help to ease the transition. And of course, let me know via the comments if you&#8217;ve got any observations on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/07/08/ending-the-love-affair-with-excel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

