mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +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,
|
||||
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 */,
|
||||
@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) {
|
||||
|
||||
when (arr) {
|
||||
is Zero -> print("zero")
|
||||
is Zero -> println("zero")
|
||||
is RollOut -> {
|
||||
println("rollOut(\"${arr.startDate}\".ld, \"${arr.endDate}\".ld, Frequency.${arr.frequency}) { ")
|
||||
indent {
|
||||
|
@ -1,125 +1,84 @@
|
||||
package net.corda.contracts.universal
|
||||
|
||||
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 {
|
||||
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 {
|
||||
(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 {
|
||||
"cancel" anytime {
|
||||
acmeCorp.owes(highStreetBank, 10.K, USD)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
"exercise" anytime {
|
||||
rollOut("2016-09-01".ld, "2018-09-01".ld, Frequency.Quarterly) {
|
||||
actions {
|
||||
(acmeCorp or highStreetBank) may {
|
||||
"proceed".givenThat(after(end)) {
|
||||
highStreetBank.owes(acmeCorp, payout, USD)
|
||||
next(vars.cap to vars.cap - payout)
|
||||
val floating = interest(notional, "act/365", fix("LIBOR", start, Tenor("3M")), start, end)
|
||||
val fixed = interest(notional, "act/365", 0.5.bd, start, end)
|
||||
|
||||
"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 {
|
||||
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
|
||||
val stateInitial = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), contractInitial)
|
||||
|
||||
actions {
|
||||
(acmeCorp or highStreetBank) may {
|
||||
"proceed".givenThat(after(end)) {
|
||||
highStreetBank.owes(acmeCorp, payout, currency)
|
||||
next(vars.uses to vars.uses - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(acmeCorp or highStreetBank) may {
|
||||
"proceedWithoutExercise".givenThat(after(end)) {
|
||||
next()
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun issue() {
|
||||
transaction {
|
||||
output { stateInitial }
|
||||
timestamp(TEST_TX_TIME_1)
|
||||
|
||||
this `fails with` "transaction has a single command"
|
||||
|
||||
tweak {
|
||||
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
|
||||
this `fails with` "the transaction is signed by all liable parties"
|
||||
}
|
||||
|
||||
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