Skip to content

Commit d053021

Browse files
committed
added Lexifi contracts (incomplete)
This commit adds the contracts used by the Generic Pricing engine from Lexifi to the code (together with a description). Two of the three contracts have been implemented so far, and one of them requires division on the RealE type (not implemented yet).
1 parent a0247d9 commit d053021

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Haskell/Contract/Expr.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ instance MkExpr Int where
203203
instance MkExpr Double where
204204
constr = R
205205

206+
-- | Fractional instance for Expr Double, enables fractional literals
207+
-- (and division, not used yet)
208+
instance (MkExpr a, Fractional a) => Fractional (Expr a) where
209+
(/) = undefined -- arith Div, when we have a division operator
210+
-- recip x = 1 / x -- default
211+
fromRational x = constr (fromRational x)
212+
206213
-- the smart constructors of the interface
207214

208215
i = I -- :: Int -> IntE

Haskell/LexifiContracts.hs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
-- contracts from Lexifi, used with the generic pricing engine
3+
4+
module LexifiContracts
5+
where
6+
7+
-- MEMO: clean up imports and exports of umbrella file "Contract.hs"
8+
import Contract
9+
import Contract.Type
10+
import Contract.Date
11+
import Contract.Expr
12+
13+
-- European option on DJ_Eurostoxx_50, starting
14+
european :: MContract
15+
european = (start, -- 2011-12-09
16+
transl duration -- on 2012-11-30
17+
(scale (maxx 0 (obs (idx,0) - strike))
18+
(transfOne EUR "them" "us")))
19+
where start = at "2011-12-09" :: Date
20+
duration = dateDiff start (at "2012-11-30")
21+
-- MEMO this fct. should be called "daysBetween"
22+
idx = "DJ_Eurostoxx_50"
23+
strike = 4000
24+
25+
-- worst-off contract on five fixed dates (chain of iff)
26+
worstOff :: MContract
27+
worstOff = (start, foldr mkDateCheck endCase (zip dDiffs premiums))
28+
where start = at "2012-01-27"
29+
dates = map (\s -> at (show s ++ "-01-27")) [2013..2017]
30+
dDiffs = zipWith dateDiff (start:dates) dates
31+
premiums = [1150.0, 1300.0, 1450.0, 1600.0, 1750]
32+
-- on the five dates (offset): one below initial spot => pay premium
33+
mkDateCheck (offset, premium) cont
34+
= transl offset $ iff barrier (collectEUR premium) cont
35+
barrier = nott (foldl1 minn (zipWith mkDiff idxs spots) !<! 0)
36+
-- MEMO we should have <= , > and >= as smart constructors
37+
mkDiff idx spot = obs (idx, 0) - spot
38+
-- MEMO we should have RealE division.
39+
idxs = [ "DJ_Eurostoxx_50", "Nikkei_225", "SP_500" ]
40+
spots = [ 3758.05, 11840, 1200 ]
41+
-- if end (date 5) reached: pay 1000 if all above 0.75,
42+
-- otherwise pay the fraction of the worst (HOW? no division)
43+
endCase = iff (allAbove 0.75) (collectEUR 1000)
44+
(collectEUR (1000 * minRatio))
45+
minRatio = error "cannot define minimum ratio without division"
46+
allAbove d = nott (foldl1 (!|!)
47+
(zipWith (fractionSmaller d) idxs spots))
48+
{- 0.75 < minimum [ obs(id,0) / sp | (id, sp) <- zip idxs spots ]
49+
<==>
50+
and [ 0.75 * sp !<! obs (id, 0) | (id, sp) <- zip idxs spots ]
51+
<==>
52+
not (or [obs(id, 0) !<! 0.75 * sp | (id, sp) <- zip idxs spots]) -}
53+
fractionSmaller d idx spot = obs(idx, 0) !<! d * spot
54+
collectEUR amount = scale amount (transfOne EUR "them" "us")
55+
56+
--

lexifi-contracts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ previously fixed amount, depending on which date it was (premiums),
5858
and end the contract. Otherwise continue with the next date.
5959

6060
If test on all five dates failed (at least one was below start on each
61-
date), test if all indexes were at least 75% of the start value. In
61+
date), test on last date if all indexes are at least 75% of start. In
6262
this case, pay 1000 (end of discounted_payoffs). Otherwise, pay
6363
(1000*worst percentage).
6464

0 commit comments

Comments
 (0)