Skip to content

Commit

Permalink
Merge pull request #3895 from input-output-hk/scp-2708-actus-validate…
Browse files Browse the repository at this point in the history
…-ann

SCP 2708 - ACTUS ANN contracts
  • Loading branch information
yveshauser committed Sep 13, 2021
2 parents ca3d41f + f555d03 commit 652d927
Show file tree
Hide file tree
Showing 33 changed files with 1,851 additions and 1,552 deletions.
34 changes: 32 additions & 2 deletions marlowe-actus/README.md
@@ -1,5 +1,35 @@
# Marlowe ACTUS: standardised financial contracts on Cardano Computation Layer

Here we present a library to generate Marlowe contracts from ACTUS contract terms
_marlowe-actus_ is a library to generate Marlowe contracts from ACTUS contract terms

See: https://www.actusfrf.org/
## ACTUS (algorithmic contract types unified standards)

ACTUS is a foundation that defines the ACTUS taxonomy of financial contracts, see https://www.actusfrf.org/

### Contract types

The following contract types are implemented in Haskell and Marlowe.

#### Amortizing loans

An amortizing loan is a loan that requires periodic payments where a payment consists of the interest payment and the principal.

##### Principal at maturity (PAM)

Principal at maturity only defines periodic interest payments, the full principal is due at maturity.

##### Linear Amortizer (LAM)

Regular principal repayments over time, the interest payments decrease linearly.

##### Negative Amortizer (NAM)

Negative amortization means that the payments per period are smaller than the interest, i.e. the balance of the loan increases over time.

##### Annuity (ANN)

The annuity amortization consists of regular payments of equal amounts over the lifetime of the loan.

## Test cases

For the contract types mentioned above the implementation is tested with the test cases provided by ACTUS: https://github.com/actusfrf/actus-tests
39 changes: 24 additions & 15 deletions marlowe-actus/app/Main.hs
Expand Up @@ -4,30 +4,39 @@

module Main where

import Data.Aeson (decode)
import Data.Int (Int32)
import Data.Map as M (empty)
import Data.String (IsString (fromString))
import Data.Time.Calendar (showGregorian)
import Language.Marlowe.ACTUS.Analysis (sampleCashflows)
import Language.Marlowe.ACTUS.Definitions.Schedule (CashFlow (..))
import Language.R (R)
import qualified Language.R as R
import Data.Aeson (decode)
import Data.Int (Int32)
import Data.String (IsString (fromString))
import Data.Time (Day)
import Data.Time.Calendar (showGregorian)
import Language.Marlowe.ACTUS.Analysis (genProjectedCashflows)
import Language.Marlowe.ACTUS.Definitions.BusinessEvents
import Language.Marlowe.ACTUS.Definitions.Schedule (CashFlow (..))
import Language.R (R)
import qualified Language.R as R
import Language.R.QQ

riskFactors :: EventType -> Day -> RiskFactors
riskFactors _ _ =
RiskFactorsPoly
{ o_rf_CURS = 1.0,
o_rf_RRMO = 1.0,
o_rf_SCMO = 1.0,
pp_payoff = 0.0
}

get_dates :: String -> R s [String]
get_dates terms = return $ case (decode $ fromString terms) of
Just terms' ->
let
cfs = sampleCashflows M.empty terms'
date = showGregorian <$> cashCalculationDay <$> cfs
event = show <$> cashEvent <$> cfs
Just terms' -> let
cfs = genProjectedCashflows riskFactors terms'
date = showGregorian <$> cashCalculationDay <$> cfs
event = show <$> cashEvent <$> cfs
in (\(d, e) -> d ++ " " ++ e) <$> (zip date event)
Nothing -> []

get_cfs :: String -> R s [Double]
get_cfs terms = return $ case (decode $ fromString terms) of
Just terms' -> amount <$> sampleCashflows M.empty terms'
Just terms' -> amount <$> genProjectedCashflows riskFactors terms'
Nothing -> []

r_shiny :: R s Int32
Expand Down
14 changes: 4 additions & 10 deletions marlowe-actus/marlowe-actus.cabal
Expand Up @@ -33,7 +33,6 @@ library
base -any,
bytestring,
containers -any,
mtl,
newtype-generics,
template-haskell -any,
plutus-tx -any,
Expand All @@ -44,8 +43,7 @@ library
marlowe -any,
time -any,
sort -any,
validation -any,
QuickCheck
validation -any
default-language: Haskell2010
default-extensions: ExplicitForAll ScopedTypeVariables
DeriveGeneric StandaloneDeriving DeriveLift
Expand All @@ -54,7 +52,6 @@ library
exposed-modules:
Language.Marlowe.ACTUS.MarloweCompat
Language.Marlowe.ACTUS.Generator
Language.Marlowe.ACTUS.QCGenerator
Language.Marlowe.ACTUS.Analysis
Language.Marlowe.ACTUS.Definitions.BusinessEvents
Language.Marlowe.ACTUS.Definitions.ContractTerms
Expand All @@ -69,10 +66,9 @@ library
Language.Marlowe.ACTUS.Model.SCHED.ContractScheduleModel
Language.Marlowe.ACTUS.Model.SCHED.ContractSchedule
Language.Marlowe.ACTUS.Model.INIT.StateInitializationModel
Language.Marlowe.ACTUS.Model.INIT.StateInitialization
Language.Marlowe.ACTUS.Model.INIT.StateInitializationFs
Language.Marlowe.ACTUS.Model.APPLICABILITY.Applicability
Language.Marlowe.ACTUS.Model.APPLICABILITY.ApplicabilityModel
Language.Marlowe.ACTUS.Model.Utility.ANN.Annuity
Language.Marlowe.ACTUS.Model.Utility.DateShift
Language.Marlowe.ACTUS.Model.Utility.ScheduleGenerator
Language.Marlowe.ACTUS.Model.Utility.YearFraction
Expand Down Expand Up @@ -105,8 +101,7 @@ executable marlowe-shiny
Language.Marlowe.ACTUS.Model.SCHED.ContractScheduleModel
Language.Marlowe.ACTUS.Model.SCHED.ContractSchedule
Language.Marlowe.ACTUS.Model.INIT.StateInitializationModel
Language.Marlowe.ACTUS.Model.INIT.StateInitialization
Language.Marlowe.ACTUS.Model.INIT.StateInitializationFs
Language.Marlowe.ACTUS.Model.Utility.ANN.Annuity
Language.Marlowe.ACTUS.Model.Utility.DateShift
Language.Marlowe.ACTUS.Model.Utility.ScheduleGenerator
Language.Marlowe.ACTUS.Model.Utility.YearFraction
Expand Down Expand Up @@ -162,8 +157,7 @@ executable marlowe-actus-test-kit
Language.Marlowe.ACTUS.Model.SCHED.ContractScheduleModel
Language.Marlowe.ACTUS.Model.SCHED.ContractSchedule
Language.Marlowe.ACTUS.Model.INIT.StateInitializationModel
Language.Marlowe.ACTUS.Model.INIT.StateInitialization
Language.Marlowe.ACTUS.Model.INIT.StateInitializationFs
Language.Marlowe.ACTUS.Model.Utility.ANN.Annuity
Language.Marlowe.ACTUS.Model.Utility.DateShift
Language.Marlowe.ACTUS.Model.Utility.ScheduleGenerator
Language.Marlowe.ACTUS.Model.Utility.YearFraction
Expand Down

0 comments on commit 652d927

Please sign in to comment.