Safe Haskell | None |
---|---|
Language | Haskell98 |
Netrium is Copyright Anthony Waite, Dave Hetwett, Shaun Laurens 2009-2015, and files herein are licensed |under the MIT license, the text of which can be found in license.txt
The definition of the basic contract language
- data Contract
- = Zero
- | One Tradeable
- | Give Contract
- | Party PartyName Contract
- | And Contract Contract
- | Or ChoiceId Contract Contract
- | Cond (Obs Bool) Contract Contract
- | Scale (Obs Double) Contract
- | Read Var (Obs Double) Contract
- | When (Obs Bool) Contract
- | Anytime ChoiceId (Obs Bool) Contract
- | Until (Obs Bool) Contract
- zero :: Contract
- one :: Tradeable -> Contract
- and :: Contract -> Contract -> Contract
- give :: Contract -> Contract
- party :: PartyName -> Contract -> Contract
- or :: ChoiceId -> Contract -> Contract -> Contract
- cond :: Obs Bool -> Contract -> Contract -> Contract
- scale :: Obs ScaleFactor -> Contract -> Contract
- type ScaleFactor = Double
- when :: Obs Bool -> Contract -> Contract
- anytime :: ChoiceId -> Obs Bool -> Contract -> Contract
- until :: Obs Bool -> Contract -> Contract
- read :: Var -> Obs Double -> Contract -> Contract
- letin :: String -> Obs Double -> (Obs Double -> Contract) -> Contract
- data Tradeable
- newtype Commodity = Commodity String
- newtype Unit = Unit String
- newtype Location = Location String
- newtype Duration = Duration Int
- newtype Currency = Currency String
- newtype CashFlowType = CashFlowType String
- newtype Portfolio = Portfolio String
- type ChoiceId = String
- type PartyName = String
- data Obs a
- konst :: (Show a, Eq a) => a -> Obs a
- var :: VarName -> Obs Double
- primVar :: VarName -> Obs Double
- primCond :: VarName -> Obs Bool
- type Time = UTCTime
- at :: Time -> Obs Bool
- before :: Time -> Obs Bool
- after :: Time -> Obs Bool
- between :: Time -> Time -> Obs Bool
- ifthen :: Obs Bool -> Obs a -> Obs a -> Obs a
- negate :: Num a => a -> a
- max :: Obs Double -> Obs Double -> Obs Double
- min :: Obs Double -> Obs Double -> Obs Double
- abs :: Num a => a -> a
- (%==) :: Obs Double -> Obs Double -> Obs Bool
- (%>) :: Obs Double -> Obs Double -> Obs Bool
- (%>=) :: Obs Double -> Obs Double -> Obs Bool
- (%<) :: Obs Double -> Obs Double -> Obs Bool
- (%<=) :: Obs Double -> Obs Double -> Obs Bool
- (%&&) :: Obs Bool -> Obs Bool -> Obs Bool
- (%||) :: Obs Bool -> Obs Bool -> Obs Bool
- (%+) :: Obs Double -> Obs Double -> Obs Double
- (%-) :: Obs Double -> Obs Double -> Obs Double
- (%*) :: Obs Double -> Obs Double -> Obs Double
- (%/) :: Obs Double -> Obs Double -> Obs Double
Contracts
The contract type and primitives
The main contract data type
one :: Tradeable -> Contract Source #
If you acquire one t
you immediately recieve one unit of the
Tradeable
t
.
and :: Contract -> Contract -> Contract Source #
If you acquire c1
you immediately acquire both and
c2c1
and c2
.
party :: PartyName -> Contract -> Contract Source #
Make a contract with a named 3rd party as the counterparty.
or :: ChoiceId -> Contract -> Contract -> Contract Source #
If you acquire c1
you immediately acquire your choice of
either or
c2c1
or c2
.
cond :: Obs Bool -> Contract -> Contract -> Contract Source #
If you acquire cond obs c1 c2
then you acquire c1
if the observable
obs
is true at the moment of acquistion, and c2
otherwise.
scale :: Obs ScaleFactor -> Contract -> Contract Source #
If you acquire scale obs c
, then you acquire c
at the same moment
except that all the subsequent trades of c
are multiplied by the value
of the observable obs
at the moment of acquistion.
type ScaleFactor = Double Source #
Scaling factor (used to scale the One
contract)
when :: Obs Bool -> Contract -> Contract Source #
If you acquire when obs c
, you must acquire c
as soon as observable
obs
subsequently becomes true.
anytime :: ChoiceId -> Obs Bool -> Contract -> Contract Source #
Once you acquire anytime obs c
, you may acquire c
at any time the
observable obs
is true.
until :: Obs Bool -> Contract -> Contract Source #
Once acquired, until obs c
is exactly like c
except that it /must be
abandoned/ when observable obs
becomes true.
:: String | A unique variable name |
-> Obs Double | The observable to observe now |
-> (Obs Double -> Contract) | The contract using the observed value |
-> Contract |
Observe the value of an observable now and save its value to use later.
Currently this requires a unique variable name.
Example:
letin "count" (count-1) $ \count' -> ...
Tradable items
A canonical tradeable element, physical or financial
Commodity, e.g. Gas, Electricity
Unit, e.g. tonnes, MWh
Location, e.g. UK, EU
A duration is a span of time, measured in seconds.
Currency, e.g. EUR, USD, GBP
newtype CashFlowType Source #
Cashflow type, e.g. cash, premium
Eq CashFlowType Source # | |
Show CashFlowType Source # | |
XmlContent CashFlowType Source # | |
HTypeable CashFlowType Source # | |
Portfolio name
Choice identifiers
Observables
A simple expression language of "observable values".
An observable represents is a time-varying value (a function from
Time
to a value).
Currently there are two types of observables:
- condition observables, type
Obs Bool
- real-valued observables, type
Obs Double
var :: VarName -> Obs Double Source #
A named interal contract program variable.
Usually you should use letin
rather than this directly.
primVar :: VarName -> Obs Double Source #
A named external real-valued observable
Example:
primVar "gas-price"
at :: Time -> Obs Bool Source #
An observable that becomes true at a single given point in time and is false at all other times.
before :: Time -> Obs Bool Source #
An observable that is true up to a given point in time and is false thereafter.
after :: Time -> Obs Bool Source #
An observable that becomes true after a given point in time and is false prior to that time.
between :: Time -> Time -> Obs Bool Source #
An observable that is true between two given points in time and is false at all other times.
between t1 t2 = time >= t1 && time < t2