mirror of
https://github.com/corda/corda.git
synced 2025-02-21 17:56:54 +00:00
universal: swaption
This commit is contained in:
parent
bfd7aa4fc2
commit
336ce362e8
@ -151,9 +151,6 @@ class DummyPerceivable<T> : Perceivable<T>
|
|||||||
data class Interest(val amount: Perceivable<BigDecimal>, val dayCountConvention: String,
|
data class Interest(val amount: Perceivable<BigDecimal>, val dayCountConvention: String,
|
||||||
val interest: Perceivable<BigDecimal>, val start: Perceivable<Instant>, val end: Perceivable<Instant>) : Perceivable<BigDecimal>
|
val interest: Perceivable<BigDecimal>, val start: Perceivable<Instant>, val end: Perceivable<Instant>) : Perceivable<BigDecimal>
|
||||||
|
|
||||||
fun libor(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") start: String, @Suppress("UNUSED_PARAMETER") end: String): Perceivable<BigDecimal> = DummyPerceivable()
|
|
||||||
fun libor(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") start: Perceivable<Instant>, @Suppress("UNUSED_PARAMETER") end: Perceivable<Instant>): Perceivable<BigDecimal> = DummyPerceivable()
|
|
||||||
|
|
||||||
fun interest(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") dayCountConvention: String, @Suppress("UNUSED_PARAMETER") interest: BigDecimal /* todo - appropriate type */,
|
fun interest(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") dayCountConvention: String, @Suppress("UNUSED_PARAMETER") interest: BigDecimal /* todo - appropriate type */,
|
||||||
@Suppress("UNUSED_PARAMETER") start: String, @Suppress("UNUSED_PARAMETER") end: String): Perceivable<BigDecimal> = Interest(Const(amount), dayCountConvention, Const(interest), const(parseDate(start).toInstant()), const(parseDate(end).toInstant()))
|
@Suppress("UNUSED_PARAMETER") start: String, @Suppress("UNUSED_PARAMETER") end: String): Perceivable<BigDecimal> = Interest(Const(amount), dayCountConvention, Const(interest), const(parseDate(start).toInstant()), const(parseDate(end).toInstant()))
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ private class PrettyPrint(arr : Arrangement) {
|
|||||||
fun prettyPrint(arr: Arrangement) {
|
fun prettyPrint(arr: Arrangement) {
|
||||||
|
|
||||||
when (arr) {
|
when (arr) {
|
||||||
is Zero -> print("zero")
|
is Zero -> println("zero")
|
||||||
is RollOut -> {
|
is RollOut -> {
|
||||||
println("rollOut(\"${arr.startDate}\".ld, \"${arr.endDate}\".ld, Frequency.${arr.frequency}) { ")
|
println("rollOut(\"${arr.startDate}\".ld, \"${arr.endDate}\".ld, Frequency.${arr.frequency}) { ")
|
||||||
indent {
|
indent {
|
||||||
|
@ -1,125 +1,84 @@
|
|||||||
package net.corda.contracts.universal
|
package net.corda.contracts.universal
|
||||||
|
|
||||||
import net.corda.core.contracts.Frequency
|
import net.corda.core.contracts.Frequency
|
||||||
|
import net.corda.core.contracts.Tenor
|
||||||
|
import net.corda.core.utilities.DUMMY_NOTARY
|
||||||
|
import net.corda.testing.transaction
|
||||||
|
import org.junit.Ignore
|
||||||
|
import org.junit.Test
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
class Swaption {
|
class Swaption {
|
||||||
val notional = 10.M
|
|
||||||
val currency = USD
|
|
||||||
val coupon = 1.5.bd
|
|
||||||
|
|
||||||
val dreary_contract = arrange {
|
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
|
||||||
|
|
||||||
|
val notional = 50.M
|
||||||
|
val currency = EUR
|
||||||
|
|
||||||
|
val tradeDate: LocalDate = LocalDate.of(2016, 9, 1)
|
||||||
|
|
||||||
|
val contractInitial = arrange {
|
||||||
|
|
||||||
actions {
|
actions {
|
||||||
(highStreetBank or acmeCorp) may {
|
|
||||||
"proceed".givenThat(after("01/07/2015")) {
|
|
||||||
highStreetBank.owes(acmeCorp, libor(notional, "01/04/2015", "01/07/2015"), currency)
|
|
||||||
acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, "01/04/2015", "01/07/2015"), currency)
|
|
||||||
actions {
|
|
||||||
(highStreetBank or acmeCorp) may {
|
|
||||||
"proceed".givenThat(after("01/10/2015")) {
|
|
||||||
highStreetBank.owes(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency)
|
|
||||||
acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency)
|
|
||||||
|
|
||||||
actions {
|
|
||||||
(highStreetBank or acmeCorp) may {
|
|
||||||
"dummy" anytime { zero }
|
|
||||||
// etc ...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actions {
|
|
||||||
acmeCorp may {
|
|
||||||
"cancel" anytime {
|
|
||||||
acmeCorp.owes(highStreetBank, 10.K, USD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
acmeCorp may {
|
acmeCorp may {
|
||||||
"cancel" anytime {
|
"exercise" anytime {
|
||||||
acmeCorp.owes(highStreetBank, 10.K, USD)
|
rollOut("2016-09-01".ld, "2018-09-01".ld, Frequency.Quarterly) {
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val elegant_contract = arrange {
|
|
||||||
rollOut("01/04/2015".ld, "01/04/2025".ld, Frequency.Quarterly) {
|
|
||||||
actions {
|
|
||||||
(highStreetBank or acmeCorp) may {
|
|
||||||
"proceed".givenThat(after(start)) {
|
|
||||||
highStreetBank.owes(acmeCorp, libor(notional, start, end), currency)
|
|
||||||
acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, start, end), currency)
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
acmeCorp may {
|
|
||||||
"cancel" anytime {
|
|
||||||
acmeCorp.owes(highStreetBank, 10.K, currency)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val strike = 1.2
|
|
||||||
|
|
||||||
val tarf = arrange {
|
|
||||||
rollOut("01/04/2015".ld, "01/04/2016".ld, Frequency.Quarterly, object {
|
|
||||||
val cap = variable(150.K)
|
|
||||||
}) {
|
|
||||||
actions {
|
|
||||||
acmeCorp may {
|
|
||||||
"exercise".givenThat(before(end)) {
|
|
||||||
val payout = (EUR / USD - strike).plus() * notional
|
|
||||||
|
|
||||||
actions {
|
actions {
|
||||||
(acmeCorp or highStreetBank) may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"proceed".givenThat(after(end)) {
|
val floating = interest(notional, "act/365", fix("LIBOR", start, Tenor("3M")), start, end)
|
||||||
highStreetBank.owes(acmeCorp, payout, USD)
|
val fixed = interest(notional, "act/365", 0.5.bd, start, end)
|
||||||
next(vars.cap to vars.cap - payout)
|
|
||||||
|
"pay floating" anytime {
|
||||||
|
highStreetBank.owes(acmeCorp, floating - fixed, currency)
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
"pay fixed" anytime {
|
||||||
|
highStreetBank.owes(acmeCorp, fixed - floating, currency)
|
||||||
|
next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(acmeCorp or highStreetBank) may {
|
}
|
||||||
"proceedWithoutExercise".givenThat(after(end)) {
|
|
||||||
next()
|
highStreetBank may {
|
||||||
}
|
"expire".givenThat(after("2016-09-01"))
|
||||||
|
{
|
||||||
|
zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val tarf2 = arrange {
|
val stateInitial = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), contractInitial)
|
||||||
rollOut("01/04/2015".ld, "01/04/2016".ld, Frequency.Quarterly, object {
|
|
||||||
val uses = variable(4)
|
|
||||||
}) {
|
|
||||||
actions {
|
|
||||||
acmeCorp may {
|
|
||||||
"exercise".givenThat(before(end)) {
|
|
||||||
val payout = (EUR / USD - strike).plus() * notional
|
|
||||||
|
|
||||||
actions {
|
@Test
|
||||||
(acmeCorp or highStreetBank) may {
|
fun issue() {
|
||||||
"proceed".givenThat(after(end)) {
|
transaction {
|
||||||
highStreetBank.owes(acmeCorp, payout, currency)
|
output { stateInitial }
|
||||||
next(vars.uses to vars.uses - 1)
|
timestamp(TEST_TX_TIME_1)
|
||||||
}
|
|
||||||
}
|
this `fails with` "transaction has a single command"
|
||||||
}
|
|
||||||
}
|
tweak {
|
||||||
}
|
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
|
||||||
(acmeCorp or highStreetBank) may {
|
this `fails with` "the transaction is signed by all liable parties"
|
||||||
"proceedWithoutExercise".givenThat(after(end)) {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
|
||||||
|
|
||||||
|
this.verifies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test @Ignore
|
||||||
|
fun `pretty print`() {
|
||||||
|
println ( prettyPrint(contractInitial) )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user