mirror of
https://github.com/corda/corda.git
synced 2024-12-20 13:33:12 +00:00
Minor tweaks to the experimental universal contract DSL
This commit is contained in:
parent
79ecd03413
commit
d7defd3157
@ -16,15 +16,16 @@ fun swap(partyA: Party, amountA: BigDecimal, currencyA: Currency, partyB: Party,
|
|||||||
|
|
||||||
fun fx_swap(expiry: String, notional: BigDecimal, strike: BigDecimal,
|
fun fx_swap(expiry: String, notional: BigDecimal, strike: BigDecimal,
|
||||||
foreignCurrency: Currency, domesticCurrency: Currency,
|
foreignCurrency: Currency, domesticCurrency: Currency,
|
||||||
partyA: Party, partyB: Party) = arrange {
|
partyA: Party, partyB: Party) =
|
||||||
actions {
|
arrange {
|
||||||
(partyA or partyB).may {
|
actions {
|
||||||
"execute".givenThat(after(expiry)) {
|
(partyA or partyB).may {
|
||||||
swap(partyA, notional * strike, domesticCurrency, partyB, notional, foreignCurrency)
|
"execute".givenThat(after(expiry)) {
|
||||||
|
swap(partyA, notional * strike, domesticCurrency, partyB, notional, foreignCurrency)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// building an fx swap using abstract swap
|
// building an fx swap using abstract swap
|
||||||
fun fx_swap2(expiry: String, notional: Long, strike: Double,
|
fun fx_swap2(expiry: String, notional: Long, strike: Double,
|
||||||
|
@ -31,14 +31,14 @@ class ActionsBuilder {
|
|||||||
else
|
else
|
||||||
Actions(actions.toSet())
|
Actions(actions.toSet())
|
||||||
|
|
||||||
fun Party.may(init: ActionBuilder.() -> Action): Action {
|
infix fun Party.may(init: ActionBuilder.() -> Action): Action {
|
||||||
val builder = ActionBuilder(setOf(this))
|
val builder = ActionBuilder(setOf(this))
|
||||||
builder.init()
|
builder.init()
|
||||||
actions.addAll( builder.actions )
|
actions.addAll( builder.actions )
|
||||||
return builder.actions.first()
|
return builder.actions.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Set<Party>.may(init: ActionBuilder.() -> Action): Action {
|
infix fun Set<Party>.may(init: ActionBuilder.() -> Action): Action {
|
||||||
val builder = ActionBuilder(this)
|
val builder = ActionBuilder(this)
|
||||||
builder.init()
|
builder.init()
|
||||||
actions.addAll( builder.actions )
|
actions.addAll( builder.actions )
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package net.corda.contracts.universal
|
package net.corda.contracts.universal
|
||||||
|
|
||||||
import net.corda.core.contracts.Amount
|
|
||||||
import net.corda.core.contracts.USD
|
import net.corda.core.contracts.USD
|
||||||
import net.corda.core.crypto.Party
|
|
||||||
import net.corda.core.crypto.generateKeyPair
|
|
||||||
import java.math.BigDecimal
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sofusmortensen on 23/05/16.
|
* Created by sofusmortensen on 23/05/16.
|
||||||
@ -15,7 +10,7 @@ import java.util.*
|
|||||||
|
|
||||||
val cds_contract = arrange {
|
val cds_contract = arrange {
|
||||||
actions {
|
actions {
|
||||||
acmeCorp.may {
|
acmeCorp may {
|
||||||
"claim".givenThat(acmeCorporationHasDefaulted and before("2017-09-01")) {
|
"claim".givenThat(acmeCorporationHasDefaulted and before("2017-09-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1.M, USD)
|
highStreetBank.gives(acmeCorp, 1.M, USD)
|
||||||
}
|
}
|
||||||
@ -27,7 +22,7 @@ val cds_contract = arrange {
|
|||||||
// both parties have the right to trigger the exchange of cash flows
|
// both parties have the right to trigger the exchange of cash flows
|
||||||
val an_fx_swap = arrange {
|
val an_fx_swap = arrange {
|
||||||
actions {
|
actions {
|
||||||
(acmeCorp or highStreetBank).may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"execute".givenThat(after("2017-09-01")) {
|
"execute".givenThat(after("2017-09-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1200.K, USD)
|
highStreetBank.gives(acmeCorp, 1200.K, USD)
|
||||||
acmeCorp.gives(highStreetBank, 1.M, EUR)
|
acmeCorp.gives(highStreetBank, 1.M, EUR)
|
||||||
@ -38,7 +33,7 @@ val an_fx_swap = arrange {
|
|||||||
|
|
||||||
val american_fx_option = arrange {
|
val american_fx_option = arrange {
|
||||||
actions {
|
actions {
|
||||||
acmeCorp.may {
|
acmeCorp may {
|
||||||
"exercise".givenThat(before("2017-09-01")) {
|
"exercise".givenThat(before("2017-09-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1200.K, USD)
|
highStreetBank.gives(acmeCorp, 1200.K, USD)
|
||||||
acmeCorp.gives(highStreetBank, 1.M, EUR)
|
acmeCorp.gives(highStreetBank, 1.M, EUR)
|
||||||
@ -49,12 +44,12 @@ val american_fx_option = arrange {
|
|||||||
|
|
||||||
val european_fx_option = arrange {
|
val european_fx_option = arrange {
|
||||||
actions {
|
actions {
|
||||||
acmeCorp.may {
|
acmeCorp may {
|
||||||
"exercise".givenThat(before("2017-09-01")) {
|
"exercise".givenThat(before("2017-09-01")) {
|
||||||
fx_swap("2017-09-01", 1.M, 1.2.bd, EUR, USD, acmeCorp, highStreetBank)
|
fx_swap("2017-09-01", 1.M, 1.2.bd, EUR, USD, acmeCorp, highStreetBank)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(acmeCorp or highStreetBank).may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"expire".anytime {
|
"expire".anytime {
|
||||||
zero
|
zero
|
||||||
}
|
}
|
||||||
@ -64,7 +59,7 @@ val european_fx_option = arrange {
|
|||||||
|
|
||||||
val contractZeroCouponBond = arrange {
|
val contractZeroCouponBond = arrange {
|
||||||
actions {
|
actions {
|
||||||
acmeCorp.may {
|
acmeCorp may {
|
||||||
"execute".givenThat(after("2017-11-01")) {
|
"execute".givenThat(after("2017-11-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1.M, USD)
|
highStreetBank.gives(acmeCorp, 1.M, USD)
|
||||||
}
|
}
|
||||||
@ -75,7 +70,7 @@ val contractZeroCouponBond = arrange {
|
|||||||
// maybe in the presence of negative interest rates you would want other side of contract to be able to take initiative as well
|
// maybe in the presence of negative interest rates you would want other side of contract to be able to take initiative as well
|
||||||
val zero_coupon_bond_2 = arrange {
|
val zero_coupon_bond_2 = arrange {
|
||||||
actions {
|
actions {
|
||||||
(acmeCorp or highStreetBank).may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"execute".givenThat(after("2017-09-01")) {
|
"execute".givenThat(after("2017-09-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1.M, USD)
|
highStreetBank.gives(acmeCorp, 1.M, USD)
|
||||||
}
|
}
|
||||||
@ -94,12 +89,12 @@ val zero_coupon_bond_2 = arrange {
|
|||||||
//
|
//
|
||||||
val no_touch = arrange {
|
val no_touch = arrange {
|
||||||
actions {
|
actions {
|
||||||
(acmeCorp or highStreetBank).may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"execute".givenThat(after("2017-09-01")) {
|
"execute".givenThat(after("2017-09-01")) {
|
||||||
highStreetBank.gives(acmeCorp, 1.M, USD)
|
highStreetBank.gives(acmeCorp, 1.M, USD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highStreetBank.may {
|
highStreetBank may {
|
||||||
"knock out".givenThat(EUR / USD gt 1.3) {
|
"knock out".givenThat(EUR / USD gt 1.3) {
|
||||||
zero
|
zero
|
||||||
}
|
}
|
||||||
@ -109,12 +104,12 @@ val no_touch = arrange {
|
|||||||
|
|
||||||
val one_touch = arrange {
|
val one_touch = arrange {
|
||||||
actions {
|
actions {
|
||||||
highStreetBank.may {
|
highStreetBank may {
|
||||||
"expire".givenThat(after("2017-09-01")) {
|
"expire".givenThat(after("2017-09-01")) {
|
||||||
zero
|
zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
acmeCorp.may {
|
acmeCorp may {
|
||||||
"knock in".givenThat(EUR / USD gt 1.3) {
|
"knock in".givenThat(EUR / USD gt 1.3) {
|
||||||
highStreetBank.gives(acmeCorp, 1.M, USD)
|
highStreetBank.gives(acmeCorp, 1.M, USD)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user