-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Contract normaliser and simulator -- -- Netrium enables financial engineers to precisely describe and execute -- both simple and exotic contracts with both financial and physical -- delivery. @package netrium @version 0.6.0 -- | 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 UnitsDB newtype UnitsDB UnitsDB :: [UnitDecl] -> UnitsDB [unUnitsDB] :: UnitsDB -> [UnitDecl] data UnitDecl CommodityDecl :: String -> UnitDecl UnitDecl :: String -> UnitDecl LocationDecl :: String -> UnitDecl CurrencyDecl :: String -> UnitDecl CashFlowTypeDecl :: String -> UnitDecl compileUnitsDB :: UnitsDB -> String instance GHC.Read.Read UnitsDB.UnitsDB instance GHC.Show.Show UnitsDB.UnitsDB instance GHC.Read.Read UnitsDB.UnitDecl instance GHC.Show.Show UnitsDB.UnitDecl instance Text.XML.HaXml.TypeMapping.HTypeable UnitsDB.UnitsDB instance Text.XML.HaXml.XmlContent.Parser.XmlContent UnitsDB.UnitsDB instance Text.XML.HaXml.TypeMapping.HTypeable UnitsDB.UnitDecl instance Text.XML.HaXml.XmlContent.Parser.XmlContent UnitsDB.UnitDecl -- | 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 ObservableDB newtype ObservableDB ObservableDB :: [ObservableDecl] -> ObservableDB [unObservableDB] :: ObservableDB -> [ObservableDecl] data ObservableDecl ObservableDecl :: String -> ObservableType -> ObservableDecl data ObservableType Double :: ObservableType Bool :: ObservableType compileObservableDB :: ObservableDB -> String instance GHC.Read.Read ObservableDB.ObservableDB instance GHC.Show.Show ObservableDB.ObservableDB instance GHC.Read.Read ObservableDB.ObservableDecl instance GHC.Show.Show ObservableDB.ObservableDecl instance GHC.Read.Read ObservableDB.ObservableType instance GHC.Show.Show ObservableDB.ObservableType instance Text.XML.HaXml.TypeMapping.HTypeable ObservableDB.ObservableDB instance Text.XML.HaXml.XmlContent.Parser.XmlContent ObservableDB.ObservableDB instance Text.XML.HaXml.TypeMapping.HTypeable ObservableDB.ObservableDecl instance Text.XML.HaXml.XmlContent.Parser.XmlContent ObservableDB.ObservableDecl instance Text.XML.HaXml.TypeMapping.HTypeable ObservableDB.ObservableType instance Text.XML.HaXml.XmlContent.Parser.XmlContent ObservableDB.ObservableType -- | 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 Observable -- | 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: -- --
-- primVar "gas-price" --primVar :: VarName -> Obs Double -- | A named external condition observable primCond :: VarName -> Obs Bool -- | A named interal contract program variable. -- -- Usually you should use letin rather than this directly. var :: VarName -> Obs Double -- | We use a continuous model of time. type Time = UTCTime -- | Convenience function to create a time from a date. mkdate :: Integer -> Int -> Int -> Time -- | An observable that becomes true at a single given point in time and is -- false at all other times. at :: Time -> Obs Bool -- | An observable that is true up to a given point in time and is false -- thereafter. before :: Time -> Obs Bool -- | An observable that becomes true after a given point in time and is -- false prior to that time. after :: Time -> Obs Bool -- | 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 --between :: Time -> Time -> Obs Bool (%==) :: Obs Double -> Obs Double -> Obs Bool infix 4 %== (%>) :: Obs Double -> Obs Double -> Obs Bool infix 4 %> (%>=) :: Obs Double -> Obs Double -> Obs Bool infix 4 %>= (%<) :: Obs Double -> Obs Double -> Obs Bool infix 4 %< (%<=) :: Obs Double -> Obs Double -> Obs Bool infix 4 %<= (%&&) :: Obs Bool -> Obs Bool -> Obs Bool infixr 3 %&& (%||) :: Obs Bool -> Obs Bool -> Obs Bool infixr 2 %|| (%+) :: Obs Double -> Obs Double -> Obs Double infixl 6 %+ (%-) :: Obs Double -> Obs Double -> Obs Double infixl 6 %- (%*) :: Obs Double -> Obs Double -> Obs Double infixl 7 %* (%/) :: Obs Double -> Obs Double -> Obs Double infixl 7 %/ -- | if..then..else for observables (returns an observable) ifthen :: Obs Bool -> Obs a -> Obs a -> Obs a -- | Unary negation. negate :: Num a => a -> a -- | Negate a boolean observable not :: Obs Bool -> Obs Bool max :: Obs Double -> Obs Double -> Obs Double min :: Obs Double -> Obs Double -> Obs Double -- | Absolute value. abs :: Num a => a -> a -- | XML parser for condition observables parseObsCond :: XMLParser (Obs Bool) -- | XML parser for real-valued observables parseObsReal :: XMLParser (Obs Double) -- | Create XML tags printObs :: Obs a -> Content () -- | Evaluate an observable at a given time eval :: Time -> Obs a -> Steps a data Steps a NeedNamedVal :: Time -> VarName -> (Double -> Steps a) -> Steps a NeedNamedCond :: Time -> VarName -> (Bool -> Steps a) -> Steps a Result :: a -> Steps a subst :: VarName -> Double -> Obs a -> Obs a -- | Check if an observable is known to be true at a given point in time, -- independent of knowledge of any external observables isTrue :: Time -> Obs Bool -> Bool -- | Check if an observable is known to be false at a given point in time, -- independent of knowledge of any external observables isFalse :: Time -> Obs Bool -> Bool -- | The next time that an observable is guaranteed to become true nextTrue :: Time -> Obs Bool -> Maybe Time -- | The next time that an observable is guaranteed to become false nextFalse :: Time -> Obs Bool -> Maybe Time evermoreTrue :: Time -> Obs Bool -> Bool evermoreFalse :: Time -> Obs Bool -> Bool -- | The time horizon of an condition observable is earliest time that it -- guaranteed to become true (or Nothing if there is no such -- time) timeHorizon :: Time -> Obs Bool -> Maybe Time -- | Return the earliest time horizon of a set of observables and the -- associate tag of the observable that has the earliest time horizon (or -- Nothing if none of the observables have a time horizon) earliestTimeHorizon :: Time -> [(Obs Bool, a)] -> Maybe (Time, a) simplifyWithinHorizon :: Time -> Time -> Obs Bool -> Obs Bool instance GHC.Show.Show a => GHC.Show.Show (Observable.Steps a) instance GHC.Classes.Eq (Observable.Obs a) instance GHC.Num.Num (Observable.Obs GHC.Types.Double) instance GHC.Real.Fractional (Observable.Obs GHC.Types.Double) instance GHC.Float.Floating (Observable.Obs GHC.Types.Double) instance Observable.DEq (Observable.Rep a1) (Observable.Rep a2) instance Observable.DEq (Observable.UnOp a1 b1) (Observable.UnOp a2 b2) instance Observable.DEq (Observable.BinOp a1 b1 c1) (Observable.BinOp a2 b2 c2) instance GHC.Show.Show (Observable.Obs a) instance GHC.Show.Show (Observable.UnOp a b) instance GHC.Show.Show (Observable.BinOp a b c) instance GHC.Show.Show a => Display.Display (Observable.Obs a) -- | 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 module Contract -- | The main contract data type data Contract Zero :: Contract One :: Tradeable -> Contract Give :: Contract -> Contract Party :: PartyName -> Contract -> Contract And :: Contract -> Contract -> Contract Or :: ChoiceId -> Contract -> Contract -> Contract Cond :: (Obs Bool) -> Contract -> Contract -> Contract Scale :: (Obs Double) -> Contract -> Contract Read :: Var -> (Obs Double) -> Contract -> Contract When :: (Obs Bool) -> Contract -> Contract Anytime :: ChoiceId -> (Obs Bool) -> Contract -> Contract Until :: (Obs Bool) -> Contract -> Contract -- | The zero contract has no rights and no obligations. zero :: Contract -- | If you acquire one t you immediately recieve one unit of the -- Tradeable t. one :: Tradeable -> Contract -- | If you acquire c1 and c2 you immediately acquire -- both c1 and c2. and :: Contract -> Contract -> Contract -- | Swap the rights and obligations of the party and counterparty. give :: Contract -> Contract -- | Make a contract with a named 3rd party as the counterparty. party :: PartyName -> Contract -> Contract -- | If you acquire c1 or c2 you immediately acquire your -- choice of either c1 or c2. or :: ChoiceId -> Contract -> Contract -> Contract -- | 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. cond :: Obs Bool -> Contract -> Contract -> Contract -- | 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. scale :: Obs ScaleFactor -> Contract -> Contract -- | Scaling factor (used to scale the One contract) type ScaleFactor = Double -- | If you acquire when obs c, you must acquire c as -- soon as observable obs subsequently becomes true. when :: Obs Bool -> Contract -> Contract -- | Once you acquire anytime obs c, you may acquire -- c at any time the observable obs is true. anytime :: ChoiceId -> Obs Bool -> Contract -> Contract -- | Once acquired, until obs c is exactly like c except -- that it /must be abandoned/ when observable obs becomes true. until :: Obs Bool -> Contract -> Contract -- | Deprecated: Use letin instead. read :: Var -> Obs Double -> Contract -> 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' -> -- ... --letin :: String -> Obs Double -> (Obs Double -> Contract) -> Contract -- | A canonical tradeable element, physical or financial data Tradeable Physical :: Commodity -> Unit -> Location -> (Maybe Duration) -> (Maybe Portfolio) -> Tradeable Financial :: Currency -> CashFlowType -> (Maybe Portfolio) -> Tradeable -- | Commodity, e.g. Gas, Electricity newtype Commodity Commodity :: String -> Commodity -- | Unit, e.g. tonnes, MWh newtype Unit Unit :: String -> Unit -- | Location, e.g. UK, EU newtype Location Location :: String -> Location -- | A duration is a span of time, measured in seconds. newtype Duration Duration :: Int -> Duration -- | Currency, e.g. EUR, USD, GBP newtype Currency Currency :: String -> Currency -- | Cashflow type, e.g. cash, premium newtype CashFlowType CashFlowType :: String -> CashFlowType -- | Portfolio name newtype Portfolio Portfolio :: String -> Portfolio -- | Choice label, used for options type ChoiceId = String -- | Name of a third party mentioned in a contract type PartyName = String -- | 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: -- --
-- primVar "gas-price" --primVar :: VarName -> Obs Double -- | A named external condition observable primCond :: VarName -> Obs Bool -- | We use a continuous model of time. type Time = UTCTime -- | An observable that becomes true at a single given point in time and is -- false at all other times. at :: Time -> Obs Bool -- | An observable that is true up to a given point in time and is false -- thereafter. before :: Time -> Obs Bool -- | An observable that becomes true after a given point in time and is -- false prior to that time. after :: Time -> Obs Bool -- | 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 --between :: Time -> Time -> Obs Bool -- | if..then..else for observables (returns an observable) ifthen :: Obs Bool -> Obs a -> Obs a -> Obs a -- | Unary negation. negate :: Num a => a -> a max :: Obs Double -> Obs Double -> Obs Double min :: Obs Double -> Obs Double -> Obs Double -- | Absolute value. abs :: Num a => a -> a (%==) :: Obs Double -> Obs Double -> Obs Bool infix 4 %== (%>) :: Obs Double -> Obs Double -> Obs Bool infix 4 %> (%>=) :: Obs Double -> Obs Double -> Obs Bool infix 4 %>= (%<) :: Obs Double -> Obs Double -> Obs Bool infix 4 %< (%<=) :: Obs Double -> Obs Double -> Obs Bool infix 4 %<= (%&&) :: Obs Bool -> Obs Bool -> Obs Bool infixr 3 %&& (%||) :: Obs Bool -> Obs Bool -> Obs Bool infixr 2 %|| (%+) :: Obs Double -> Obs Double -> Obs Double infixl 6 %+ (%-) :: Obs Double -> Obs Double -> Obs Double infixl 6 %- (%*) :: Obs Double -> Obs Double -> Obs Double infixl 7 %* (%/) :: Obs Double -> Obs Double -> Obs Double infixl 7 %/ instance GHC.Show.Show Contract.Contract instance GHC.Classes.Eq Contract.Contract instance GHC.Show.Show Contract.Tradeable instance GHC.Classes.Eq Contract.Tradeable instance GHC.Show.Show Contract.Portfolio instance GHC.Classes.Eq Contract.Portfolio instance GHC.Show.Show Contract.CashFlowType instance GHC.Classes.Eq Contract.CashFlowType instance GHC.Show.Show Contract.Currency instance GHC.Classes.Eq Contract.Currency instance GHC.Show.Show Contract.Location instance GHC.Classes.Eq Contract.Location instance GHC.Show.Show Contract.Unit instance GHC.Classes.Eq Contract.Unit instance GHC.Show.Show Contract.Commodity instance GHC.Classes.Eq Contract.Commodity instance GHC.Num.Num Contract.Duration instance GHC.Show.Show Contract.Duration instance GHC.Classes.Eq Contract.Duration instance Display.Display Contract.Contract instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Tradeable instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Tradeable instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Duration instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Duration instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Commodity instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Commodity instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Unit instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Unit instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Location instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Location instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Currency instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Currency instance Text.XML.HaXml.TypeMapping.HTypeable Contract.CashFlowType instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.CashFlowType instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Portfolio instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Portfolio instance Text.XML.HaXml.TypeMapping.HTypeable Contract.Contract instance Text.XML.HaXml.XmlContent.Parser.XmlContent Contract.Contract -- | 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 DecisionTree -- | A single step in a decision tree data DecisionStep x Done :: DecisionStep x Trade :: TradeDir -> Double -> Tradeable -> x -> DecisionStep x Choose :: Party -> ChoiceId -> x -> x -> DecisionStep x ObserveCond :: (Obs Bool) -> x -> x -> DecisionStep x ObserveValue :: (Obs Double) -> (Double -> x) -> DecisionStep x Wait :: [(Obs Bool, Time -> x)] -> [(ChoiceId, Time -> x)] -> DecisionStep x data Party FirstParty :: Party Counterparty :: Party ThirdParty :: PartyName -> Party -- | A full decision tree data DecisionTree DecisionTree :: Time -> (DecisionStep DecisionTree) -> DecisionTree unfoldDecisionTree :: (a -> (DecisionStep a, Time)) -> a -> DecisionTree decisionTree :: Time -> Contract -> DecisionTree -- | Current time, blocked, and runnable ThreadStates data ProcessState PSt :: Time -> [Blocked ThreadState] -> [ThreadState] -> ProcessState -- | Remaining contract, until conditions, inherited scaling, and -- direction of trade data ThreadState TSt :: Contract -> [Obs Bool] -> ScaleFactor -> TradeDir -> ThreadState data Blocked c -- | waiting for obs to become True BlockedOnWhen :: (Obs Bool) -> c -> Blocked c -- | waiting for obs to become value v BlockedOnAnytime :: Bool -> ChoiceId -> (Obs Bool) -> c -> Blocked c initialProcessState :: Time -> Contract -> ProcessState currentContract :: ProcessState -> Contract decisionStep :: ProcessState -> DecisionStep ProcessState subst :: String -> Double -> Contract -> Contract each :: [a] -> [(a, [a])] data TradeDir TradeDir2To1 :: TradeDir TradeDir1To2 :: TradeDir TradeDirPTo1 :: PartyName -> TradeDir TradeDirPTo2 :: PartyName -> TradeDir TradeDir1ToP :: PartyName -> TradeDir TradeDir2ToP :: PartyName -> TradeDir TradeDirPToQ :: PartyName -> PartyName -> TradeDir TradeDirQToP :: PartyName -> PartyName -> TradeDir -- | Give the interpretation of a TradeDir as a combination of party -- and give. evalTradeDir :: TradeDir -> (Contract -> Contract) -- | Precompose a TradeDir with party to get a new combined -- TradeDir. -- -- That is, it respects the law: -- --
-- evalTradeDir (setThirdParty p dir) = evalTradeDir dir . party p --setThirdParty :: PartyName -> TradeDir -> TradeDir -- | Precompose a TradeDir with give to get a new combined TradeDir. -- -- That is, it respects the law: -- --
-- evalTradeDir (flipTradeDir dir) = evalTradeDir dir . give --flipTradeDir :: TradeDir -> TradeDir -- | Return the two parties in a TradeDir in the order (recieving -- party, giving party). tradeDirParties :: TradeDir -> (Party, Party) newtype ObsCondition ObsCondition :: (Obs Bool) -> ObsCondition [unObsCondition] :: ObsCondition -> (Obs Bool) instance GHC.Base.Functor DecisionTree.DecisionStep instance GHC.Classes.Eq DecisionTree.ProcessState instance GHC.Show.Show DecisionTree.ProcessState instance GHC.Classes.Eq DecisionTree.ThreadState instance GHC.Show.Show DecisionTree.ThreadState instance GHC.Classes.Eq DecisionTree.TradeDir instance GHC.Show.Show DecisionTree.TradeDir instance GHC.Classes.Eq c => GHC.Classes.Eq (DecisionTree.Blocked c) instance GHC.Show.Show c => GHC.Show.Show (DecisionTree.Blocked c) instance GHC.Show.Show DecisionTree.Party instance GHC.Classes.Eq DecisionTree.Party instance GHC.Show.Show (DecisionTree.DecisionStep x) instance Display.Display DecisionTree.DecisionTree instance Text.XML.HaXml.TypeMapping.HTypeable DecisionTree.Party instance Text.XML.HaXml.XmlContent.Parser.XmlContent DecisionTree.Party instance Text.XML.HaXml.TypeMapping.HTypeable DecisionTree.TradeDir instance Text.XML.HaXml.XmlContent.Parser.XmlContent DecisionTree.TradeDir instance Text.XML.HaXml.TypeMapping.HTypeable (DecisionTree.Blocked c) instance Text.XML.HaXml.XmlContent.Parser.XmlContent c => Text.XML.HaXml.XmlContent.Parser.XmlContent (DecisionTree.Blocked c) instance Text.XML.HaXml.TypeMapping.HTypeable DecisionTree.ObsCondition instance Text.XML.HaXml.XmlContent.Parser.XmlContent DecisionTree.ObsCondition instance Text.XML.HaXml.TypeMapping.HTypeable DecisionTree.ThreadState instance Text.XML.HaXml.XmlContent.Parser.XmlContent DecisionTree.ThreadState instance Text.XML.HaXml.TypeMapping.HTypeable DecisionTree.ProcessState instance Text.XML.HaXml.XmlContent.Parser.XmlContent DecisionTree.ProcessState -- | 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 DecisionTreeSimplify decisionTreeSimple :: Time -> Contract -> DecisionTree decisionStepWithTime :: ProcessState -> (DecisionStep ProcessState, Time) simplifyWait :: Time -> [(Obs Bool, Time -> ProcessState)] -> Bool -> Either ProcessState [(Obs Bool, Time -> ProcessState)] -- | 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 Observations type Observations a = Map VarName (TimeSeries a) type Choices a = Map ChoiceId (TimedEvents a) data TimeSeries a SeriesEntry :: Time -> a -> (TimeSeries a) -> TimeSeries a SeriesEnds :: Time -> TimeSeries a SeriesUnbounded :: TimeSeries a lookupTimeSeries :: TimeSeries a -> Time -> Maybe a pruneTimeSeries :: Time -> TimeSeries a -> TimeSeries a lookupChoice :: Map ChoiceId (TimedEvents a) -> ChoiceId -> Time -> Maybe a timeSeriesEvents :: TimeSeries a -> TimedEvents (Maybe a) newtype TimedEvents a TEs :: [(Time, a)] -> TimedEvents a unTEs :: TimedEvents t -> [(Time, t)] mapAccumTS :: (acc -> x -> (acc, y)) -> acc -> TimedEvents x -> (acc, TimedEvents y) lookupTimedEvent :: TimedEvents a -> Time -> Maybe a -- | Insert an event into a TimedEvents series. -- -- This event is placed before the other simultaneous events in the -- sequence. insertEventBefore :: Time -> a -> TimedEvents a -> TimedEvents a -- | Insert an event into a TimedEvents series. -- -- This event is placed after the other simultaneous events in the -- sequence. insertEventAfter :: Time -> a -> TimedEvents a -> TimedEvents a pruneTimedEvents :: Time -> TimedEvents a -> TimedEvents a mergeEvents :: TimedEvents a -> TimedEvents b -> TimedEvents (MergeResult a b) mergeEventsBiased :: TimedEvents a -> TimedEvents a -> TimedEvents a -- | Generic merging utility. For sorted input lists this is a full outer -- join. mergeBy :: (a -> b -> Ordering) -> [a] -> [b] -> [MergeResult a b] data MergeResult a b OnlyInLeft :: a -> MergeResult a b InBoth :: a -> b -> MergeResult a b OnlyInRight :: b -> MergeResult a b data ObservationSeries ObservationsSeriesBool :: String -> (XMLTimeSeries Bool) -> ObservationSeries ObservationsSeriesDouble :: String -> (XMLTimeSeries Double) -> ObservationSeries data ChoiceSeries ChoiceSeries :: (XMLTimedEvents Choice) -> ChoiceSeries data Choice OrChoice :: ChoiceId -> Bool -> Choice AnytimeChoice :: ChoiceId -> Choice data Timed a Timed :: Time -> a -> Timed a data SeriesEnd Unbounded :: SeriesEnd Bounded :: Time -> SeriesEnd type XMLTimeSeries a = ([Timed a], SeriesEnd) type XMLTimedEvents a = [Timed a] toTimedEvents :: XMLTimedEvents a -> TimedEvents a fromTimedEvents :: TimedEvents a -> XMLTimedEvents a toTimeSeries :: XMLTimeSeries a -> TimeSeries a fromTimeSeries :: TimeSeries a -> XMLTimeSeries a instance GHC.Classes.Eq a => GHC.Classes.Eq (Observations.TimedEvents a) instance GHC.Read.Read a => GHC.Read.Read (Observations.TimedEvents a) instance GHC.Show.Show a => GHC.Show.Show (Observations.TimedEvents a) instance GHC.Read.Read a => GHC.Read.Read (Observations.TimeSeries a) instance GHC.Show.Show a => GHC.Show.Show (Observations.TimeSeries a) instance GHC.Base.Functor Observations.TimedEvents instance GHC.Base.Monoid a => GHC.Base.Monoid (Observations.TimedEvents a) instance Text.XML.HaXml.TypeMapping.HTypeable Observations.ObservationSeries instance Text.XML.HaXml.XmlContent.Parser.XmlContent Observations.ObservationSeries instance Text.XML.HaXml.TypeMapping.HTypeable Observations.ChoiceSeries instance Text.XML.HaXml.TypeMapping.HTypeable Observations.Choice instance Text.XML.HaXml.XmlContent.Parser.XmlContent Observations.ChoiceSeries instance Text.XML.HaXml.XmlContent.Parser.XmlContent Observations.Choice instance Text.XML.HaXml.TypeMapping.HTypeable Observations.SeriesEnd instance Text.XML.HaXml.XmlContent.Parser.XmlContent Observations.SeriesEnd instance Text.XML.HaXml.TypeMapping.HTypeable (Observations.Timed a) instance Text.XML.HaXml.XmlContent.Parser.XmlContent a => Text.XML.HaXml.XmlContent.Parser.XmlContent (Observations.Timed a) -- | 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 Interpreter data Output Trade :: Party -> Party -> Double -> Tradeable -> Output OptionUntil :: ChoiceId -> Time -> Output OptionForever :: ChoiceId -> Output data StopReason -- | contract reduced to zero Finished :: StopReason -- | stop time reached (in timeout mode) StoppedTime :: StopReason -- | stopped at first wait point (in wait mode) StoppedWait :: StopReason -- | a non-terminating wait WaitForever :: StopReason ChoiceRequired :: Party -> ChoiceId -> StopReason ObservationExhausted :: VarName -> StopReason -- | really an error ObservationMissing :: VarName -> StopReason data SimEnv SimEnv :: Observations Double -> Observations Bool -> Choices () -> Choices Bool -> SimEnv -- | primitive real-valued obs [valueObservations] :: SimEnv -> Observations Double -- | primitive bool-valued obs [condObservations] :: SimEnv -> Observations Bool -- | anytime options taken [optionsTaken] :: SimEnv -> Choices () -- | or choices made [choicesMade] :: SimEnv -> Choices Bool data SimOutputs SimOutputs :: TimedEvents String -> TimedEvents Output -> StopReason -> Time -> Contract -> ProcessState -> Maybe WaitInfo -> SimOutputs [simTrace] :: SimOutputs -> TimedEvents String [simOutputs] :: SimOutputs -> TimedEvents Output [simStopReason] :: SimOutputs -> StopReason [simStopTime] :: SimOutputs -> Time [simStopContract] :: SimOutputs -> Contract [simStopState] :: SimOutputs -> ProcessState [simStopWaitInfo] :: SimOutputs -> Maybe WaitInfo data StopWait NoStop :: StopWait StopFirstWait :: StopWait StopNextWait :: StopWait data WaitInfo WaitInfo :: [Obs Bool] -> Maybe Time -> [ChoiceId] -> WaitInfo [waitObs] :: WaitInfo -> [Obs Bool] [waitHorizon] :: WaitInfo -> Maybe Time [waitOptions] :: WaitInfo -> [ChoiceId] runContract :: SimEnv -> Time -> Maybe Time -> StopWait -> Either Contract ProcessState -> SimOutputs data WaitResult k WaitContinue :: k -> WaitResult k WaitStopped :: WaitResult k WaitFinished :: WaitResult k WaitNonTerm :: WaitResult k runWait :: SimEnv -> ObsEnv -> Maybe Time -> Time -> [(Obs Bool, k)] -> [(ChoiceId, k)] -> (Time, ObsResult (WaitResult k)) -- | When in a wait state there are three different things that can happen -- one of the observables can become true, we can choose to take an -- anytime option that is available to us. -- -- There are two ways an observable can become true, one is due to a -- change in a primitive/external ovservable, and the other is via the -- passage of time. -- -- Hence, overall, there are three events we are interested in while -- waiting. data WaitEvent k TakeOption :: ChoiceId -> WaitEvent k ObsChanged :: ObsEnv -> WaitEvent k Timeout :: k -> WaitEvent k -- | Take all three sources of events we are interested in and produce a -- unified event list mergeWaitEvents :: Observations Double -> Observations Bool -> Choices () -> [(Time, k)] -> Time -> ObsEnv -> TimedEvents (WaitEvent k) data ObsEnv ObsEnv :: (Map VarName (Maybe Double)) -> (Map VarName (Maybe Bool)) -> ObsEnv currentObsEnv :: Observations Double -> Observations Bool -> Time -> ObsEnv data ObsResult a ObsResult :: a -> ObsResult a ObsExhausted :: VarName -> ObsResult a ObsMissing :: VarName -> ObsResult a evalObs :: ObsEnv -> Time -> Obs a -> ObsResult a newtype WaitCondition WaitCondition :: (Obs Bool) -> WaitCondition newtype WaitOption WaitOption :: ChoiceId -> WaitOption instance GHC.Show.Show a => GHC.Show.Show (Interpreter.ObsResult a) instance GHC.Base.Functor Interpreter.ObsResult instance GHC.Show.Show k => GHC.Show.Show (Interpreter.WaitEvent k) instance GHC.Show.Show Interpreter.ObsEnv instance GHC.Classes.Eq Interpreter.SimOutputs instance GHC.Show.Show Interpreter.SimOutputs instance GHC.Classes.Eq Interpreter.WaitInfo instance GHC.Show.Show Interpreter.WaitInfo instance GHC.Classes.Eq Interpreter.StopWait instance GHC.Show.Show Interpreter.StopWait instance GHC.Show.Show Interpreter.StopReason instance GHC.Classes.Eq Interpreter.StopReason instance GHC.Show.Show Interpreter.Output instance GHC.Classes.Eq Interpreter.Output instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.Output instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.Output instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.StopReason instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.StopReason instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.StopWait instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.StopWait instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.WaitInfo instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.WaitInfo instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.WaitCondition instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.WaitCondition instance Text.XML.HaXml.TypeMapping.HTypeable Interpreter.WaitOption instance Text.XML.HaXml.XmlContent.Parser.XmlContent Interpreter.WaitOption -- | 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 module Valuation -- | Type for value processes newtype PR a PR :: [RV a] -> PR a [unPr] :: PR a -> [RV a] -- | Random variables type RV a = [a] -- | Truncates a (possibly infinite) value process takePr :: Int -> PR a -> PR a -- | Determines the number of time steps in a value process. Only -- terminates for finite value processes horizonPr :: PR a -> Int -- | Returns True if every value in a value process is true, false -- otherwise. Only terminates for finite value processes. andPr :: PR Bool -> Bool -- | Lift functions wih a single argument liftPr :: (a -> b) -> PR a -> PR b -- | Lift functions with 2 arguments lift2Pr :: (a -> b -> c) -> PR a -> PR b -> PR c -- | Lift functions for binary operations lift2PrAll :: (a -> a -> a) -> PR a -> PR a -> PR a -- | Lift functions with 3 arguments lift3Pr :: (a -> b -> c -> d) -> PR a -> PR b -> PR c -> PR d -- | A version of zipWith that handles input lists of different lengths -- -- This is used to support lifted binary operations such as (+) zipWithAll :: (a -> a -> a) -> [a] -> [a] -> [a] -- | To use Num operations on PR -- | To use Ord operations on PR -- | To use Equality operations on PR -- | A model has a start date/time and an exchange rate model data Model Model :: Time -> (Currency -> Currency -> PR Double) -> Model -- | Start date and time for the model [modelStart] :: Model -> Time -- | Exchange rate model [exch] :: Model -> Currency -> Currency -> PR Double -- | A simple model with a constant exchange rate model simpleModel :: Time -> Model -- | Each currency has different parameters for the interest rate model. -- Since the model is not realistic, these parameters are currently -- entirely arbitrary. rateModels :: [(Currency, PR Double)] -- | Function to pick an exchange rate model from the above list rateModel :: Currency -> PR Double -- | Constant process bigK :: a -> PR a -- | Generate an infinite list konstSlices :: t -> [[t]] -- | Evaluate a condition at date T condPr :: PR Bool -> PR a -> PR a -> PR a -- | 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. disc :: Currency -> (PR Bool, PR Double) -> PR Double -- | 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 absorb :: Currency -> (PR Bool, PR Double) -> PR Double -- | Not currently implemented. The paper describes the following as a -- possible algorithm: -- --
-- forall o' . (o => o') => q >= snellk(o',q) --snell :: Currency -> (PR Bool, PR Double) -> PR Double -- | Calculates a previous slice in a lattice by averaging each adjacent -- pair of values in the specified slice prevSlice :: RV Double -> RV Double -- | 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! rates :: Double -> Double -> PR Double -- | 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." probabilityLattice :: [RV Double] -- | 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. expectedValue :: RV Double -> RV Double -> Double expectedValuePr :: PR Double -> [Double] -- | Evaluate a contract at a given time evalC :: Model -> Currency -> Contract -> PR Double -- | Evaluate a constant observable evalO :: Obs a -> PR a -- | 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: latticeImage :: PR Double -> String -> String -> IO ExitCode -- | Supports interactive display of generated Dot code. printTree :: PR Double -> IO () -- | Write a value process out as a Dot file. writeTreeAsDot :: String -> PR Double -> IO () -- | Run Dot on a file with the specified base name, and generate a graphic -- file with the specified type. runDot :: String -> String -> IO ExitCode -- | Convert a PR Double to a list of dot node relationships. prToDot :: PR Double -> [String] -- | Convert lattice to list of dot node relationships. rvsToDot :: [RV Double] -> [String] dotExt :: [Char] -- | Number each of the nodes in a lattice. assignIds :: [RV a] -> Int -> [RV (Int, a)] numberList :: [a] -> Int -> [(Int, a)] -- | 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. showNodes :: [RV (Int, Double)] -> [String] nodeLabel :: Double -> String -- | Generate Dot code for relationships between numbered RV nodes. treeToDot :: [RV (Int, a)] -> [String] dotJoin :: RV (Int, a) -> RV (Int, a) -> [String] dotGraph :: [String] -> [String] dotGraphHdr :: [String] formatDotStmt :: String -> String instance GHC.Show.Show a => GHC.Show.Show (Valuation.PR a) instance GHC.Num.Num a => GHC.Num.Num (Valuation.PR a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Valuation.PR a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Valuation.PR a)