This is the third in a series of posts looking at our current ArrayFire <a href="http://www.accelereyes.com/arrayfire/c/examples.htm" target="_blank">examples</a>. The code can be compiled and run from <code>arrayfire/examples/</code> when you <a href="http://www.accelereyes.com/download_arrayfire">download</a> and install the ArrayFire library. Today we will discuss the examples found in the <code>financial/</code> directory.

In these examples, my machine has the following configuration:
<pre class="lang:default highlight:0 decode:true">ArrayFire v1.9 (build XXXXXXX) by AccelerEyes (64-bit Linux)
License: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CUDA toolkit 5.0, driver 304.54
GPU0 Quadro 6000, 6144 MB, Compute 2.0 (single,double)
Display Device: GPU0 Quadro 6000
Memory Usage: 5549 MB free (6144 MB total)...</pre>
<strong><a href="http://www.accelereyes.com/arrayfire/c/examples_2financial_2blackscholes_8cpp-example.htm">Black-Scholes</a></strong>

There are a number of applications of ArrayFire and GPU programming in the world of finance and markets. Here we have an example of <a href="http://en.wikipedia.org/wiki/Black%E2%80%93Scholes">Black-Scholes</a>, which is a model for computing options prices in the stock market. Understanding how this model works isn't necessary to understand this example. In fact, ArrayFire improves the relationship between the scientist/mathematician/analyst who needs to use a particular model, and the programmer who has to write it. Rather than having a whole bunch of nasty GPU code getting in the way and obscuring the algorithm, ArrayFire allows the algorithm to take precedence in your code, and express itself naturally. Take a look at the following snippet of algorithm code:
<pre class="lang:default decode:true">    // S = Underlying stock price
    // X = Strike Price
    // R = Risk free rate of interest
    // V = Volatility
    // T = Time to maturity

    array d1 = log(S / X);
    d1 = d1 + (R + (V*V)*0.5) * T;
    d1 = d1 / (V*sqrt(T));

    array d2 = d1 - (V*sqrt(T));
    C = S * cnd(d1) - (X * exp((-R)*T) * cnd(d2));
    P = X * exp((-R)*T) * cnd(-d2) - (S * cnd(-d1));</pre>
In this snippet, it is really easy to see what the mathematics are doing. We don't even have to deal with for-loops because of the way ArrayFire naturally works with the array data type.

Using ArrayFire can simplify many mathematical algorithms and bring the speed of the GPU to the analyst without forcing him or her to waste valuable time with the details of GPU kernel coding.  So go ahead, see which algorithms <em>you</em> can run on the GPU by <a href="http://www.accelereyes.com/download_arrayfire">downloading</a> the ArrayFire library today!

---

<strong>Posts in this series:</strong>
<ol>
	<li><a href="http://blog.accelereyes.com/blog/2013/03/04/arrayfire-examples-part-1-of-8-getting-started/">ArrayFire Examples (Part 1 of 8) – Getting Started</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/03/06/arrayfire-examples-part-2-of-8-benchmarks/">ArrayFire Examples (Part 2 of 8) – Benchmarks</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/03/25/arrayfire-examples-part-3-of-8-financial/">ArrayFire Examples (Part 3 of 8) – Financial</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/04/16/arrayfire-examples-part-4-of-8-image-processing">ArrayFire Examples (Part 4 of 8) - Image Processing</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/06/05/arrayfire-examples-part-5-of-8-machine-learning/">ArrayFire Examples (Part 5 of 8) - Machine Learning</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/06/12/arrayfire-examples-part-6-of-8-multiple-gpus/">ArrayFire Examples (Part 6 of 8) - Multiple GPU</a></li>
	<li><a href="http://blog.accelereyes.com/blog/2013/07/03/arrayfire-examples-part-7-of-8-pde/">ArrayFire Examples (Part 7 of 8) - PDE</a></li>
</ol>
<strong> </strong>