From 73a2215747be03dcbabfd0c3e8a61a74a2bba4a0 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Thu, 22 Sep 2016 15:22:19 +0100 Subject: [PATCH 1/6] Added core changes and docs required for simm valuation demo. --- .../kotlin/com/r3corda/core/math/Utils.kt | 7 +++ .../kotlin/com/r3corda/core/math/Utils.kt | 14 +++++ docs/source/initialmarginagreement.rst | 62 +++++++++++++++++++ docs/source/running-the-demos.rst | 43 +++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 core/src/main/kotlin/com/r3corda/core/math/Utils.kt create mode 100644 core/src/test/kotlin/com/r3corda/core/math/Utils.kt create mode 100644 docs/source/initialmarginagreement.rst diff --git a/core/src/main/kotlin/com/r3corda/core/math/Utils.kt b/core/src/main/kotlin/com/r3corda/core/math/Utils.kt new file mode 100644 index 0000000000..ec5c963f2b --- /dev/null +++ b/core/src/main/kotlin/com/r3corda/core/math/Utils.kt @@ -0,0 +1,7 @@ +package com.r3corda.core.math + +import java.math.BigDecimal + +fun Iterable.sum(): BigDecimal { + return this.fold(BigDecimal.valueOf(0)) { a: BigDecimal, b: BigDecimal -> a + b } +} \ No newline at end of file diff --git a/core/src/test/kotlin/com/r3corda/core/math/Utils.kt b/core/src/test/kotlin/com/r3corda/core/math/Utils.kt new file mode 100644 index 0000000000..635aeec797 --- /dev/null +++ b/core/src/test/kotlin/com/r3corda/core/math/Utils.kt @@ -0,0 +1,14 @@ +package com.r3corda.core.math + +import org.junit.Test + +import org.junit.Assert.* +import java.math.BigDecimal + +class Utils { + @Test + fun sum() { + val calculated = listOf(BigDecimal.valueOf(1.0), BigDecimal.valueOf(5.0)).sum() + assert(calculated == BigDecimal.valueOf(6.0)) + } +} \ No newline at end of file diff --git a/docs/source/initialmarginagreement.rst b/docs/source/initialmarginagreement.rst new file mode 100644 index 0000000000..5e52467e1d --- /dev/null +++ b/docs/source/initialmarginagreement.rst @@ -0,0 +1,62 @@ +Initial Margin Agreement Demo +============================= + +This CorDapp is a demonstration of how corda can be used for a very timely and real world requirement is in the process for initial margin agreement, featuring the integration of complex and industry proven third party libraries into corda nodes. + +SIMM Introduction +----------------- + +SIMM is an acronym for "Standard Initial Margin Model" + +Now this is a quite detailed and complicated subject, and I appeal to those of you who are know about this in depth to be somewhat patient as I attempt to reduce it to the principal parts suitable for the demonstration. It is effectively the calculation of what is known as a "margin" that is paid by one party to another when they agree a trade on certain types of transaction. This margin is paid such that, in the event of one of the counterparties suffering a credit event (a financial term and a polite way to say defaulting, not paying the debts that are due, or potentially even bankruptcy), then the party that is owed any sum already has some of the amount that it should have been paid. This payment to the receiving party is a preventative measure in order to reduce the risk of a potentially catastrophic default domino effect that caused the `Great Financial Crisis `_, as it means that they can be assured that if they need to pay another party, they will have a proportion of the funds that they have been relying on. + +To enact this, in September 2016, the ISDA committee - with full backing from various governing bodies - `issued a ruling on what is known as the ISDA SIMM ™ model `_, a way of fairly and consistently calculating this margin. Any parties wishing to trade a financial product that is covered under this ruling would, independently, use this model and calculate their margin payment requirement, agree it with their trading counterparty and then pay (or receive, depending on the results of this calculation) this amount. In the case of disagreement that is not resolved in a timely fashion, this payment would increase and so therefore it is in the parties interest to reach agreement in a short as time frame as possible. + +To be more accurate, the SIMM calculation is not performed on just one trade - it is calculated on an aggregate of intermediary values (which in this model are sensitivities to risk factors) from a portfolio of trades; therefore the input to a SIMM is actually this data, not the individual trades itself + +Also note that implementations of the SIMM are actually protected and subject to license restrictions by ISDA (this is due to the model itself being protected). We were fortunate enough to technically partner with `OpenGamma `_ who allowed us to demonstrate the SIMM process using their proprietary model. In the source code released, we have replaced their analytics engine with very simple stub functions that allow the process to run and can easily be swapped out in place for their real libraries. + +Process steps +------------- + +So hopefully we haven't lost anybody in the above paragraph but the outline of the process is as follows: + +Preliminaries + - Ensure that there are a number of live trades with another party financial products that are covered under the ISDA SIMM agreement (if none, then use the demo to enter some simple trades as described below). + +Initial Margin Agreement Process + - Agree that one will be performing the margining calculation against a portfolio of trades with another party, and agree the trades in that portfolio. In practice, one node will start the protocol but it does not matter which node does. + - Individually (at the node level), identify the data (static, reference etc) one will need in order to be able to calculate the metrics on those trades + - Confirm with the other counterparty the dataset from the above set + - Calculate any intermediary steps and values needed for the margin calculation (ie sensitivities to risk factors) + - Agree on the results of these steps + - Calculate the initial margin + - Agree on the calculation of the above with the other party + - In practise, pay (or receive) this margin (omitted for the sake of complexity for this example) + + +Corda Implementation +-------------------- + +R3 implemented a demonstration of the above for a project that we referred to as "Vega" (just in case references to the code or folder structures seem to refer to this). We presented this solution at our European Members Conference in September 2016. + +The demonstration can be run in two ways - via IntelliJ (which will allow you to add breakpoints, debug, etc), or via gradle and the command line. + + +Via IntelliJ + - locate ``Main.kt`` in TODO + - run TODO + - browse to TODO + +Via Command Line + - gradle TODO + - cd TODO + - java corda.jar TOOD + - (repeat for nodes x,y,z) TODO + + + + + + + diff --git a/docs/source/running-the-demos.rst b/docs/source/running-the-demos.rst index 3d87db6e32..af15f2ce20 100644 --- a/docs/source/running-the-demos.rst +++ b/docs/source/running-the-demos.rst @@ -174,3 +174,46 @@ In the second terminal, run: ./build/install/r3prototyping/bin/attachment-demo --role=SENDER You should see some log lines scroll past, and within a few seconds the message "File received - we're happy!" should be printed. + +Simm and Portfolio Demo +----------------------- + +To run the demo run: + +**Windows** + +Open a terminal window and navigate to the root directory of Corda and run: + +.. sourcecode:: shell + + gradlew apps:vega:installTemplateNodes + cd build\nodes\nameserver + java -jar corda.jar + +Now open another terminal in the root directory of Corda and run: + +.. sourcecode:: shell + + cd build\nodes\nodea + java -jar corda.jar + +Now open a third terminal in the root directory of Corda and run: + +.. sourcecode:: shell + + cd build\nodes\nodeb + java -jar corda.jar + +**Other** + +Open one terminal window and run the following commands from the root directory of Corda: + +.. sourcecode:: shell + + ./gradlew apps:vega:installTemplateNodes + cd build/nodes + ./runnodes + +Now open http://localhost:31339/web/vega and http://localhost:31340/web/vega to view the two nodes that this +will have started respectively. + From ca2a37915d91edf3611890a3439559ad37f217b1 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Wed, 2 Nov 2016 11:04:15 +0000 Subject: [PATCH 2/6] Review fixes for docs. --- docs/source/initialmarginagreement.rst | 52 ++++++++++++++++---------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/docs/source/initialmarginagreement.rst b/docs/source/initialmarginagreement.rst index 5e52467e1d..8c856295b8 100644 --- a/docs/source/initialmarginagreement.rst +++ b/docs/source/initialmarginagreement.rst @@ -1,28 +1,49 @@ Initial Margin Agreement Demo ============================= -This CorDapp is a demonstration of how corda can be used for a very timely and real world requirement is in the process for initial margin agreement, featuring the integration of complex and industry proven third party libraries into corda nodes. +This app is a demonstration of how Corda can be used for a very timely and real world requirement is in the process + for initial margin agreement, featuring the integration of complex and industry proven third party libraries into Corda nodes. SIMM Introduction ----------------- -SIMM is an acronym for "Standard Initial Margin Model" +SIMM is an acronym for "Standard Initial Margin Model". -Now this is a quite detailed and complicated subject, and I appeal to those of you who are know about this in depth to be somewhat patient as I attempt to reduce it to the principal parts suitable for the demonstration. It is effectively the calculation of what is known as a "margin" that is paid by one party to another when they agree a trade on certain types of transaction. This margin is paid such that, in the event of one of the counterparties suffering a credit event (a financial term and a polite way to say defaulting, not paying the debts that are due, or potentially even bankruptcy), then the party that is owed any sum already has some of the amount that it should have been paid. This payment to the receiving party is a preventative measure in order to reduce the risk of a potentially catastrophic default domino effect that caused the `Great Financial Crisis `_, as it means that they can be assured that if they need to pay another party, they will have a proportion of the funds that they have been relying on. +Now this is a quite detailed and complicated subject, and I appeal to those of you who are know about this in depth to +be somewhat patient as I attempt to reduce it to the principal parts suitable for the demonstration. It is effectively +the calculation of what is known as a "margin" that is paid by one party to another when they agree a trade on certain +types of transaction. This margin is paid such that, in the event of one of the counterparties suffering a credit event +(a financial term and a polite way to say defaulting, not paying the debts that are due, or potentially even bankruptcy), +then the party that is owed any sum already has some of the amount that it should have been paid. This payment to the +receiving party is a preventative measure in order to reduce the risk of a potentially catastrophic default domino +effect that caused the `Great Financial Crisis `_, +as it means that they can be assured that if they need to pay another party, they will have a proportion of the funds +that they have been relying on. -To enact this, in September 2016, the ISDA committee - with full backing from various governing bodies - `issued a ruling on what is known as the ISDA SIMM ™ model `_, a way of fairly and consistently calculating this margin. Any parties wishing to trade a financial product that is covered under this ruling would, independently, use this model and calculate their margin payment requirement, agree it with their trading counterparty and then pay (or receive, depending on the results of this calculation) this amount. In the case of disagreement that is not resolved in a timely fashion, this payment would increase and so therefore it is in the parties interest to reach agreement in a short as time frame as possible. +To enact this, in September 2016, the ISDA committee - with full backing from various governing bodies - +`issued a ruling on what is known as the ISDA SIMM ™ model `_, +a way of fairly and consistently calculating this margin. Any parties wishing to trade a financial product that is +covered under this ruling would, independently, use this model and calculate their margin payment requirement, +agree it with their trading counterparty and then pay (or receive, depending on the results of this calculation) +this amount. In the case of disagreement that is not resolved in a timely fashion, this payment would increase +and so therefore it is in the parties interest to reach agreement in a short as time frame as possible. -To be more accurate, the SIMM calculation is not performed on just one trade - it is calculated on an aggregate of intermediary values (which in this model are sensitivities to risk factors) from a portfolio of trades; therefore the input to a SIMM is actually this data, not the individual trades itself +To be more accurate, the SIMM calculation is not performed on just one trade - it is calculated on an aggregate of +intermediary values (which in this model are sensitivities to risk factors) from a portfolio of trades; therefore +the input to a SIMM is actually this data, not the individual trades itself. -Also note that implementations of the SIMM are actually protected and subject to license restrictions by ISDA (this is due to the model itself being protected). We were fortunate enough to technically partner with `OpenGamma `_ who allowed us to demonstrate the SIMM process using their proprietary model. In the source code released, we have replaced their analytics engine with very simple stub functions that allow the process to run and can easily be swapped out in place for their real libraries. +Also note that implementations of the SIMM are actually protected and subject to license restrictions by ISDA +(this is due to the model itself being protected). We were fortunate enough to technically partner with +`OpenGamma `_ who allowed us to demonstrate the SIMM process using their proprietary model. +In the source code released, we have replaced their analytics engine with very simple stub functions that allow +the process to run and can easily be swapped out in place for their real libraries. Process steps ------------- -So hopefully we haven't lost anybody in the above paragraph but the outline of the process is as follows: - Preliminaries - - Ensure that there are a number of live trades with another party financial products that are covered under the ISDA SIMM agreement (if none, then use the demo to enter some simple trades as described below). + - Ensure that there are a number of live trades with another party financial products that are covered under the + ISDA SIMM agreement (if none, then use the demo to enter some simple trades as described below). Initial Margin Agreement Process - Agree that one will be performing the margining calculation against a portfolio of trades with another party, and agree the trades in that portfolio. In practice, one node will start the protocol but it does not matter which node does. @@ -35,10 +56,8 @@ Initial Margin Agreement Process - In practise, pay (or receive) this margin (omitted for the sake of complexity for this example) -Corda Implementation --------------------- - -R3 implemented a demonstration of the above for a project that we referred to as "Vega" (just in case references to the code or folder structures seem to refer to this). We presented this solution at our European Members Conference in September 2016. +Running the app +--------------- The demonstration can be run in two ways - via IntelliJ (which will allow you to add breakpoints, debug, etc), or via gradle and the command line. @@ -53,10 +72,3 @@ Via Command Line - cd TODO - java corda.jar TOOD - (repeat for nodes x,y,z) TODO - - - - - - - From 26b3c0173d4b58d3567fc47f1a56d405e17e8f80 Mon Sep 17 00:00:00 2001 From: Richard Green Date: Wed, 2 Nov 2016 11:12:26 +0000 Subject: [PATCH 3/6] Fixing grammar --- docs/source/initialmarginagreement.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/initialmarginagreement.rst b/docs/source/initialmarginagreement.rst index 8c856295b8..1ee4b9330a 100644 --- a/docs/source/initialmarginagreement.rst +++ b/docs/source/initialmarginagreement.rst @@ -1,8 +1,8 @@ Initial Margin Agreement Demo ============================= -This app is a demonstration of how Corda can be used for a very timely and real world requirement is in the process - for initial margin agreement, featuring the integration of complex and industry proven third party libraries into Corda nodes. +This app is a demonstration of how Corda can be used for the real world requirement of initial margin calculation and +agreement; featuring the integration of complex and industry proven third party libraries into Corda nodes. SIMM Introduction ----------------- From 1a892886acead77ef3513f47d0f624d78641f28a Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Wed, 2 Nov 2016 11:36:12 +0000 Subject: [PATCH 4/6] Added instructions for running simm valuation demo. --- docs/source/initialmarginagreement.rst | 20 +++++++++++--------- docs/source/running-the-demos.rst | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/source/initialmarginagreement.rst b/docs/source/initialmarginagreement.rst index 1ee4b9330a..78a0fea976 100644 --- a/docs/source/initialmarginagreement.rst +++ b/docs/source/initialmarginagreement.rst @@ -61,14 +61,16 @@ Running the app The demonstration can be run in two ways - via IntelliJ (which will allow you to add breakpoints, debug, etc), or via gradle and the command line. +Run with IntelliJ:: -Via IntelliJ - - locate ``Main.kt`` in TODO - - run TODO - - browse to TODO + 1. Open the `cordapp-samples` project with IntelliJ + 2. Run the shared run configuration "SIMM Valuation Demo" + 3. Browse to http://localhost:10005/web/simmvaluationdemo -Via Command Line - - gradle TODO - - cd TODO - - java corda.jar TOOD - - (repeat for nodes x,y,z) TODO +Run via CLI:: + + 1. Navigate to the `cordapp-samples` directory in your shell + 2. Run the gradle target `deployNodes` (ie; ./gradlew deployNodes for Unix or gradlew.bat on Windows) + 1. Unix: `cd simm-valuation-demo/build/nodes && ./runnodes`. + 2. Windows: Open a command line window in each subdirectory of `simm-valuation-demo/build/nodes` and run `java -jar corda.jar` + 4. Browse to http://localhost:10005/web/simmvaluationdemo diff --git a/docs/source/running-the-demos.rst b/docs/source/running-the-demos.rst index af15f2ce20..4b47292968 100644 --- a/docs/source/running-the-demos.rst +++ b/docs/source/running-the-demos.rst @@ -175,7 +175,7 @@ In the second terminal, run: You should see some log lines scroll past, and within a few seconds the message "File received - we're happy!" should be printed. -Simm and Portfolio Demo +SIMM and Portfolio Demo ----------------------- To run the demo run: From acaa9f82a50885079d4805ccd843423d2f8d7199 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Thu, 3 Nov 2016 10:40:33 +0000 Subject: [PATCH 5/6] Rewrote some documentation about the simm demo. Moved a util function to the main utils file. --- core/src/main/kotlin/com/r3corda/core/Utils.kt | 7 ++++++- core/src/main/kotlin/com/r3corda/core/math/Utils.kt | 7 ------- docs/source/initialmarginagreement.rst | 11 ++++------- docs/source/running-the-demos.rst | 2 ++ 4 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 core/src/main/kotlin/com/r3corda/core/math/Utils.kt diff --git a/core/src/main/kotlin/com/r3corda/core/Utils.kt b/core/src/main/kotlin/com/r3corda/core/Utils.kt index cdd21bd822..86c4b29e51 100644 --- a/core/src/main/kotlin/com/r3corda/core/Utils.kt +++ b/core/src/main/kotlin/com/r3corda/core/Utils.kt @@ -288,4 +288,9 @@ fun Observable.bufferUntilSubscribed(): Observable { val subject = UnicastSubject.create() val subscription = subscribe(subject) return subject.doOnUnsubscribe { subscription.unsubscribe() } -} \ No newline at end of file +} + +/** Allows summing big decimals that are in iterable collections */ +fun Iterable.sum(): BigDecimal { + return this.fold(BigDecimal.valueOf(0)) { a: BigDecimal, b: BigDecimal -> a + b } +} diff --git a/core/src/main/kotlin/com/r3corda/core/math/Utils.kt b/core/src/main/kotlin/com/r3corda/core/math/Utils.kt deleted file mode 100644 index ec5c963f2b..0000000000 --- a/core/src/main/kotlin/com/r3corda/core/math/Utils.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.r3corda.core.math - -import java.math.BigDecimal - -fun Iterable.sum(): BigDecimal { - return this.fold(BigDecimal.valueOf(0)) { a: BigDecimal, b: BigDecimal -> a + b } -} \ No newline at end of file diff --git a/docs/source/initialmarginagreement.rst b/docs/source/initialmarginagreement.rst index 78a0fea976..becce56335 100644 --- a/docs/source/initialmarginagreement.rst +++ b/docs/source/initialmarginagreement.rst @@ -7,12 +7,9 @@ agreement; featuring the integration of complex and industry proven third party SIMM Introduction ----------------- -SIMM is an acronym for "Standard Initial Margin Model". - -Now this is a quite detailed and complicated subject, and I appeal to those of you who are know about this in depth to -be somewhat patient as I attempt to reduce it to the principal parts suitable for the demonstration. It is effectively -the calculation of what is known as a "margin" that is paid by one party to another when they agree a trade on certain -types of transaction. This margin is paid such that, in the event of one of the counterparties suffering a credit event +SIMM is an acronym for "Standard Initial Margin Model". It is effectively the calculation of a "margin" that is paid +by one party to another when they agree a trade on certain types of transaction. This margin is +paid such that, in the event of one of the counterparties suffering a credit event (a financial term and a polite way to say defaulting, not paying the debts that are due, or potentially even bankruptcy), then the party that is owed any sum already has some of the amount that it should have been paid. This payment to the receiving party is a preventative measure in order to reduce the risk of a potentially catastrophic default domino @@ -53,7 +50,7 @@ Initial Margin Agreement Process - Agree on the results of these steps - Calculate the initial margin - Agree on the calculation of the above with the other party - - In practise, pay (or receive) this margin (omitted for the sake of complexity for this example) + - In practice, pay (or receive) this margin (omitted for the sake of complexity for this example) Running the app diff --git a/docs/source/running-the-demos.rst b/docs/source/running-the-demos.rst index 4b47292968..2d3fc0e1b2 100644 --- a/docs/source/running-the-demos.rst +++ b/docs/source/running-the-demos.rst @@ -178,6 +178,8 @@ You should see some log lines scroll past, and within a few seconds the message SIMM and Portfolio Demo ----------------------- +.. note:: Read more about this demo at :doc:`initialmarginagreement`. + To run the demo run: **Windows** From cf4b91d7c7fc115d5026b411887cf5b7036f80d4 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Thu, 3 Nov 2016 10:47:34 +0000 Subject: [PATCH 6/6] Removed redundant file. --- .../src/test/kotlin/com/r3corda/core/math/Utils.kt | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 core/src/test/kotlin/com/r3corda/core/math/Utils.kt diff --git a/core/src/test/kotlin/com/r3corda/core/math/Utils.kt b/core/src/test/kotlin/com/r3corda/core/math/Utils.kt deleted file mode 100644 index 635aeec797..0000000000 --- a/core/src/test/kotlin/com/r3corda/core/math/Utils.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.r3corda.core.math - -import org.junit.Test - -import org.junit.Assert.* -import java.math.BigDecimal - -class Utils { - @Test - fun sum() { - val calculated = listOf(BigDecimal.valueOf(1.0), BigDecimal.valueOf(5.0)).sum() - assert(calculated == BigDecimal.valueOf(6.0)) - } -} \ No newline at end of file