The standard no-arbitrage price
and the price time
{-# LANGUAGE GADTs #-} | |
module Spreadsheet where | |
import Control.Applicative | |
import Control.Monad (forM_) | |
import Data.IORef | |
import Data.List (union) | |
import Data.Unique |
select [] = [] | |
select (x:xs) = (x,xs) : select xs | |
pairs nums = [(a, b) | (a, bs) <- select nums, b <- bs] | |
triples nums = [(a,b,c) | (a,bs) <- select nums, (b,cs) <- select bs, c <- cs] | |
overlap (a,b,c) (d,e,f) = | |
case compare a d of |
import Data.Map (Map, (!), insert, empty) | |
import Control.Monad.State (StateT, put, get, liftIO, evalStateT) | |
type Val = Int | |
type Var = String | |
data Instruction = | |
Set Val Var | |
| Print Var | |
| Add Var Var Var |
<h1 id="fx-forwards">FX Forwards</h1> | |
<p>The standard no-arbitrage price <span class="MathJax_Preview"></span><span class="MathJax" id="MathJax-Element-1-Frame" role="textbox" aria-readonly="true"><nobr><span class="math" id="MathJax-Span-1" style="width: 2.069em; display: inline-block;"><span style="display: inline-block; position: relative; width: 1.715em; height: 0px; font-size: 121%;"><span style="position: absolute; clip: rect(1.243em 1000.003em 2.6em -0.469em); top: -2.122em; left: 0.003em;"><span class="mrow" id="MathJax-Span-2"><span class="msubsup" id="MathJax-Span-3"><span style="display: inline-block; position: relative; width: 1.656em; height: 0px;"><span style="position: absolute; clip: rect(1.243em 1000.003em 2.305em -0.469em); top: -2.122em; left: 0.003em;"><span class="mi" id="MathJax-Span-4" style="font-family: MathJax_Math; font-style: italic;">F<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.121em;"></span></span><span style="display: inline-block; width: 0px; h |
(* Define monadic operations for a list *) | |
let return x = [x] | |
let (>>=) lst f = List.concat (List.map f lst) | |
(* Generate the combinations of k distinct objects from a list *) | |
(* Simple version |
sortBy c=m.map(:[]) -- O(n log n) | |
where m[]=[];m[x]=x;m x=m(n x);n[]=[];n[x]=[x];n(x:y:z)=p x y:n z | |
p[]y=y;p x[]=x;p (w:x)(y:z)=case c w y of GT->y:p(w:x)z;_->w:p x(y:z) | |
sort x=m(map(:[])x) | |
where m[]=[];m[x]=x;m x=m(n x);n[]=[];n[x]=[x];n(x:y:z)=p x y:n z | |
p[]y=y;p x[]=x;p (w:x)(y:z)=if w>y then y:p(w:x)z else w:p x(y:z) |
import Control.Applicative | |
import qualified Data.Set as Set | |
import AI.Search.Uninformed | |
step :: Set.Set String -> String -> [] String | |
step wordlist xs = Set.toList . Set.fromList . filter f $ remove1 xs ++ swap1 xs ++ add1 xs | |
where | |
f w = Set.member w wordlist | |
len = length xs | |
letters = ['a'..'z'] |
import Control.Probability | |
expected p = expectation (runProb p) | |
die = uniform [1..6] :: Bayes Double Integer | |
game n | |
| n == 0 = die | |
| otherwise = do | |
x <- die |
module AI.Search.Examples.Graph where | |
import Control.Monad | |
import Control.Monad.ST | |
import Control.Applicative | |
import Data.STRef | |
import Data.Map (Map, (!)) | |
import qualified Data.Map as Map | |
import Data.List (nub) | |
import Data.Graph.Inductive (LNode, LEdge, Gr) |