SIMM valuation test now verifies the trade more robustly by checking trade ID.

This commit is contained in:
Clinton Alexander 2016-12-19 16:13:37 +00:00
parent 7d591e9cba
commit 00a44c5fbd
2 changed files with 21 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import net.corda.testing.http.HttpApi
import net.corda.vega.api.PortfolioApi
import net.corda.vega.api.PortfolioApiUtils
import net.corda.vega.api.SwapDataModel
import net.corda.vega.api.SwapDataView
import net.corda.vega.portfolio.Portfolio
import org.junit.Test
import java.math.BigDecimal
@ -25,6 +26,7 @@ class SimmValuationTest: IntegrationTestCategory {
val valuationDate = LocalDate.parse("2016-06-06")
val nodeALegalName = "Bank A"
val nodeBLegalName = "Bank B"
val testTradeId = "trade1"
}
@Test fun `runs SIMM valuation demo`() {
@ -35,8 +37,8 @@ class SimmValuationTest: IntegrationTestCategory {
val nodeBParty = getPartyWithName(nodeA, nodeBLegalName)
val nodeAParty = getPartyWithName(nodeB, nodeALegalName)
assert(createTradeBetween(nodeA, nodeBParty))
assert(tradeExists(nodeB, nodeAParty))
assert(createTradeBetween(nodeA, nodeBParty, testTradeId))
assert(tradeExists(nodeB, nodeAParty, testTradeId))
assert(runValuationsBetween(nodeA, nodeBParty))
assert(valuationExists(nodeB, nodeAParty))
}
@ -54,15 +56,15 @@ class SimmValuationTest: IntegrationTestCategory {
return api.getJson<PortfolioApi.AvailableParties>("whoami")
}
private fun createTradeBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean {
val trade = SwapDataModel("trade1", "desc", valuationDate, "EUR_FIXED_1Y_EURIBOR_3M",
private fun createTradeBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty, tradeId: String): Boolean {
val trade = SwapDataModel(tradeId, "desc", valuationDate, "EUR_FIXED_1Y_EURIBOR_3M",
valuationDate, LocalDate.parse("2020-01-02"), BuySell.BUY, BigDecimal.valueOf(1000), BigDecimal.valueOf(0.1))
return api.putJson("${counterparty.id}/trades", trade)
}
private fun tradeExists(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean {
val trades = api.getJson<List<Map<String, Any>>>("${counterparty.id}/trades")
return (!trades.isEmpty())
private fun tradeExists(api: HttpApi, counterparty: PortfolioApi.ApiParty, tradeId: String): Boolean {
val trades = api.getJson<Array<SwapDataView>>("${counterparty.id}/trades")
return (trades.find { it.id == tradeId } != null)
}
private fun runValuationsBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean {

View File

@ -115,15 +115,21 @@ class PortfolioApiUtils(private val ownParty: Party) {
)
}
fun createTradeView(state: IRSState): Any {
data class TradeView(
val fixedLeg: Map<String, Any>,
val floatingLeg: Map<String, Any>,
val common: Map<String, Any>,
val ref: String)
fun createTradeView(state: IRSState): TradeView {
val trade = if (state.buyer.name == ownParty.name) state.swap.toFloatingLeg() else state.swap.toFloatingLeg()
val fixedLeg = trade.product.legs.first { it.type == SwapLegType.FIXED } as RateCalculationSwapLeg
val floatingLeg = trade.product.legs.first { it.type != SwapLegType.FIXED } as RateCalculationSwapLeg
val fixedRate = fixedLeg.calculation as FixedRateCalculation
val floatingRate = floatingLeg.calculation as IborRateCalculation
return mapOf(
"fixedLeg" to mapOf(
return TradeView(
fixedLeg = mapOf(
"fixedRatePayer" to state.buyer.name,
"notional" to mapOf(
"token" to fixedLeg.currency.code,
@ -139,7 +145,7 @@ class PortfolioApiUtils(private val ownParty: Party) {
"calendar" to listOf("TODO"),
"paymentCalendar" to mapOf<String, Any>() // TODO
),
"floatingLeg" to mapOf(
floatingLeg = mapOf(
"floatingRatePayer" to state.seller.name,
"notional" to mapOf(
"token" to floatingLeg.currency.code,
@ -154,7 +160,7 @@ class PortfolioApiUtils(private val ownParty: Party) {
"paymentCalendar" to listOf("TODO"),
"fixingCalendar" to mapOf<String, Any>() // TODO
),
"common" to mapOf(
common = mapOf(
"valuationDate" to trade.product.startDate.unadjusted,
"hashLegalDocs" to state.contract.legalContractReference.toString(),
"interestRate" to mapOf(
@ -165,7 +171,7 @@ class PortfolioApiUtils(private val ownParty: Party) {
)
)
),
"ref" to trade.info.id.get().value
ref = trade.info.id.get().value
)
}
}