Note that there are some explanatory texts on larger screens.

plurals
  1. POIdiomatic option pricing and risk using Repa parallel arrays
    primarykey
    data
    text
    <p>Suppose I want to price a call option using a finite difference method and repa then the following does the job:</p> <pre><code>import Data.Array.Repa as Repa r, sigma, k, t, xMax, deltaX, deltaT :: Double m, n, p :: Int r = 0.05 sigma = 0.2 k = 50.0 t = 3.0 m = 3 p = 1 xMax = 150 deltaX = xMax / (fromIntegral m) n = 800 deltaT = t / (fromIntegral n) singleUpdater a = traverse a id f where Z :. m = extent a f _get (Z :. ix) | ix == 0 = 0.0 f _get (Z :. ix) | ix == m-1 = xMax - k f get (Z :. ix) = a * get (Z :. ix-1) + b * get (Z :. ix) + c * get (Z :. ix+1) where a = deltaT * (sigma^2 * (fromIntegral ix)^2 - r * (fromIntegral ix)) / 2 b = 1 - deltaT * (r + sigma^2 * (fromIntegral ix)^2) c = deltaT * (sigma^2 * (fromIntegral ix)^2 + r * (fromIntegral ix)) / 2 priceAtT :: Array U DIM1 Double priceAtT = fromListUnboxed (Z :. m+1) [max 0 (deltaX * (fromIntegral j) - k) | j &lt;- [0..m]] testSingle :: IO (Array U DIM1 Double) testSingle = computeP $ singleUpdater priceAtT </code></pre> <p>But now suppose I want to price options in parallel (say to do a spot ladder) then I can do this:</p> <pre><code>multiUpdater a = fromFunction (extent a) f where f :: DIM2 -&gt; Double f (Z :. ix :. jx) = (singleUpdater x)!(Z :. ix) where x :: Array D DIM1 Double x = slice a (Any :. jx) priceAtTMulti :: Array U DIM2 Double priceAtTMulti = fromListUnboxed (Z :. m+1 :. p+1) [max 0 (deltaX * (fromIntegral j) - k) | j &lt;- [0..m], _l &lt;- [0..p]] testMulti :: IO (Array U DIM2 Double) testMulti = computeP $ multiUpdater priceAtTMulti </code></pre> <p>Questions:</p> <ol> <li>Is there a more idiomatic way of doing this in repa?</li> <li>Will the above method actually price in parallel?</li> <li>How can I determine whether my code really is generating something that will be executed in parallel?</li> </ol> <p>I tried this for 3 but sadly encountered a bug in ghc:</p> <pre><code>bash-3.2$ ghc -fext-core --make Test.hs [1 of 1] Compiling Main ( Test.hs, Test.o ) ghc: panic! (the 'impossible' happened) (GHC version 7.4.1 for x86_64-apple-darwin): MkExternalCore died: make_lit </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload