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

Module for valuation semantics

- newtype PR a = PR {}
- type RV a = [a]
- takePr :: Int -> PR a -> PR a
- horizonPr :: PR a -> Int
- andPr :: PR Bool -> Bool
- liftPr :: (a -> b) -> PR a -> PR b
- lift2Pr :: (a -> b -> c) -> PR a -> PR b -> PR c
- lift2PrAll :: (a -> a -> a) -> PR a -> PR a -> PR a
- lift3Pr :: (a -> b -> c -> d) -> PR a -> PR b -> PR c -> PR d
- zipWithAll :: (a -> a -> a) -> [a] -> [a] -> [a]
- data Model = Model {}
- simpleModel :: Time -> Model
- rateModels :: [(Currency, PR Double)]
- rateModel :: Currency -> PR Double
- bigK :: a -> PR a
- konstSlices :: t -> [[t]]
- condPr :: PR Bool -> PR a -> PR a -> PR a
- disc :: Currency -> (PR Bool, PR Double) -> PR Double
- absorb :: Currency -> (PR Bool, PR Double) -> PR Double
- snell :: Currency -> (PR Bool, PR Double) -> PR Double
- prevSlice :: RV Double -> RV Double
- rates :: Double -> Double -> PR Double
- probabilityLattice :: [RV Double]
- expectedValue :: RV Double -> RV Double -> Double
- expectedValuePr :: PR Double -> [Double]
- evalC :: Model -> Currency -> Contract -> PR Double
- evalO :: Obs a -> PR a
- latticeImage :: PR Double -> String -> String -> IO ExitCode
- printTree :: PR Double -> IO ()
- writeTreeAsDot :: String -> PR Double -> IO ()
- runDot :: String -> String -> IO ExitCode
- prToDot :: PR Double -> [String]
- rvsToDot :: [RV Double] -> [String]
- dotExt :: [Char]
- assignIds :: [RV a] -> Int -> [RV (Int, a)]
- numberList :: [a] -> Int -> [(Int, a)]
- showNodes :: [RV (Int, Double)] -> [String]
- nodeLabel :: Double -> String
- treeToDot :: [RV (Int, a)] -> [String]
- dotJoin :: RV (Int, a) -> RV (Int, a) -> [String]
- dotGraph :: [String] -> [String]
- dotGraphHdr :: [String]
- formatDotStmt :: String -> String

# Value Processes

## The basics

Type for value processes

## Value process helpers

horizonPr :: PR a -> Int Source #

Determines the number of time steps in a value process. Only terminates for finite value processes

andPr :: PR Bool -> Bool Source #

Returns True if every value in a value process is true, false otherwise. Only terminates for finite value processes.

## Value process lifting

lift3Pr :: (a -> b -> c -> d) -> PR a -> PR b -> PR c -> PR d Source #

Lift functions with 3 arguments

zipWithAll :: (a -> a -> a) -> [a] -> [a] -> [a] Source #

A version of zipWith that handles input lists of different lengths

This is used to support lifted binary operations such as (+)

# Models

A model has a start date/time and an exchange rate model

simpleModel :: Time -> Model Source #

A simple model with a constant exchange rate model

rateModels :: [(Currency, PR Double)] Source #

Each currency has different parameters for the interest rate model. Since the model is not realistic, these parameters are currently entirely arbitrary.

rateModel :: Currency -> PR Double Source #

Function to pick an exchange rate model from the above list

# Process primitives

konstSlices :: t -> [[t]] Source #

Generate an infinite list

disc :: Currency -> (PR Bool, PR Double) -> PR Double Source #

The primitive (disc t k) maps a real-valued random variable at date T, expressed in currency k, to its "fair" equivalent stochastic value process in the same currency k.

A simplifying assumption is that at some point, the boolean-valued process becomes True for an entire RV. This provides a simple termination condition for the discounting process.

absorb :: Currency -> (PR Bool, PR Double) -> PR Double Source #

Given a boolean-valued process o, the primitive absorbk(o,p) transforms the real-valued process p, expressed in currency k, into another real-valued process. For any state, the result is the expected value of receiving p's value if the region o will never be True, and receiving zero in the contrary. In states where o is True, the result is therefore zero

snell :: Currency -> (PR Bool, PR Double) -> PR Double Source #

Not currently implemented. The paper describes the following as a possible algorithm:

- take the final column of the tree (horizon),
- discount it back one time step,
- take the maximum of that column with the corresponding column of the original tree,
- then repeat that process all the way back to the root.

snellk(o,p) is the smallest process q (under an ordering relation mention briefly at the end of B:4.6) such that:

forall o' . (o => o') => q >= snellk(o',q)

# Lattices

## Simple calculation

prevSlice :: RV Double -> RV Double Source #

Calculates a previous slice in a lattice by averaging each adjacent pair of values in the specified slice

rates :: Double -> Double -> PR Double Source #

Constructs a lattice containing possible interest rates given a starting rate and an increment per time step. This "unrealistically regular" model matches that shown in B:Fig.8. However, it is so simple that some interest rates go negative after a small number of time steps. A better model is needed for real applications. Don't use this to model your retirement fund!

## Probability calculation

probabilityLattice :: [RV Double] Source #

Each node in a value process lattice is associated with a probability.

"...in our very simple setting the number of paths from the root to the node is proportional to the probability that the variable will take that value."

## Expected value

expectedValue :: RV Double -> RV Double -> Double Source #

The code for absorb above does not obviously deal with the expected value mentioned in the spec. This is because the expected value of each random variable is implicit in the value process lattice representation: each node in the lattice is associated with a probability, and the expected value at a particular date is simply the sum of the product of the value at each node and its associated probability. The following functions implement this calculation.

# Valuation semantics

## Valuation semantics for contracts

## Valuation semantics for observables

# Functions for Graphviz output

latticeImage :: PR Double -> String -> String -> IO ExitCode Source #

This code generates graphs which represent a value process lattice. Currently assumes Double values, constrained by showNode's formatting of the value.

Write out tree as Dot file and run Dot to generate image:

runDot :: String -> String -> IO ExitCode Source #

Run Dot on a file with the specified base name, and generate a graphic file with the specified type.

numberList :: [a] -> Int -> [(Int, a)] Source #

showNodes :: [RV (Int, Double)] -> [String] Source #

showNodes returns a list of "primary" Dot representations of numbered `RV`

nodes, with each node's value specified as the node's label. These nodes can then be referenced repeatedly in the generated Dot code without specifying a label.

treeToDot :: [RV (Int, a)] -> [String] Source #

Generate Dot code for relationships between numbered `RV`

nodes.

dotGraphHdr :: [String] Source #

formatDotStmt :: String -> String Source #