-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExamples.hs
84 lines (58 loc) · 2.18 KB
/
Examples.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env runhaskell
{-# LANGUAGE FlexibleInstances #-}
import Control.Monad.Reader hiding (when)
import Data.Decimal
import qualified Data.List as L hiding (and)
import DSL
import FinancialArithmetic
import Models
import Graphics.EasyPlot
------------------------------------------------------------------------------
main = do
let payments1 = []
let u1 = Contract "1" $ when (at $ 3 Months) (Give $ One $ 100 USD)
let u2 = Contract "2" $ american (1 Month, 3 Months) (One $ 10 NZD)
print $ u1 .+ u2
-- let timeline = map Model [0..11]
-- print $
{- EXAMPLE 1: ------------------------------------------------------------
Over the timeframe of 12 months, get and compare performance figures
for two contracts.
First contract:
Pay 100 NZD at the beginning of the third month,
get 105 NZD at the end of the 10th month.
Second contract:
Pay 100 USD at the beginning of the third month,
get 103 USD at the end of the 10th month.
-}
let c1 = Contract "C1" $
(when (at $ 2 Months) (Give $ One $ 100 NZD))
`And`
(when (at $ 10 Months) (One $ 105 NZD))
let c2 = Contract "C2" $ And
(when (at $ 2 Months) (Give $ One $ 100 USD))
(when (at $ 10 Months) (One $ 103 USD))
{-
Information provided:
Main currency
Highest deposit rates for each month
Lowest loan rates for each month
Defined in Models.hs
-}
let m = m_nzakl_2015_baseline
-- Schedule of payments
let s1 = contractToSchedule m c1
let s2 = contractToSchedule m c2
-- Print actions for each period of the whole term
print $ name c1 ++ ": " ++ (show s1)
print $ name c2 ++ ": " ++ (show s2)
{-
Questions asked:
* Calculate NPV, NFV for each contract
* Calculate equivalent deposit rate for each contract
-}
let npv :: Contract -> Reader (Model, Time) Contract
npv c = do
(m, t) <- ask
return $ npv' m t c
print $ runReader (npv c1) (m, 1 Month)