Tuesday, June 27, 2017

Blockchain based total return swaps

Blockchain based total return swaps

Introduction

Blockchain is widely considered in the fintech communities to have disrupted impact on the global financial infrastructure. In a report from the World Economic Forum, Blockchain -- Distributed Ledger Technology -- is considered to one of the emerging disruptive technological forces -- along with Artificial Intelligence, Cloud, and Quantum Computing -- that will reshape business and societies in the coming decades.

Screen Shot 2017-06-08 at 7.13.30 AM.png
Blockchain technology is expected to transform the financial infrastructure to be more efficient, autonomous, and transparent.

There is a wide range of benefits to be realized through blockchain infrastructure in the future capital markets:

Pre-trade
  • Transparency and verification of holdings
  • Reduced credit exposures
  • Simpler KYC/KYCC1 via look through to holdings
Post-trade
  • No central clearing for real-time cash transaction
  • Reduced margin/ collateral requirements
  • Faster and more efficient post-trade processing
  • Fungible use of assets on blockchains as collateral
  • Auto-execution of smart contracts
Custody & Securities Servicing
  • Primary issuance directly onto a blockchain
  • Automation and de- duplication of servicing processes
  • Richer central datasets with flat  accounting hierarchies
  • Fund subscriptions/ redemptions processed automatically on the blockchain
  • Simplification of fund servicing, accounting, allocations, and administration

Conceptual views of blockchain in capital markets

Screen Shot 2017-06-08 at 6.53.19 AM.png
Picture 1: Source: Blockchain in Capital Markets, Oliver Wyman & Euro Clear
There are many blockchain technology use cases in the capital markets, as illustrated in picture 1. This article is to elaborate a use case in derivatives -- total return swaps -- in more details.

What is a total return swap?

Total Return Swap - TRS-Flow.jpegPicture 2

Picture 2 shows the concept of a total return swap: it is an agreement in which one party makes payments based on a set rate, either fixed or variable, while the other party makes payments based on the return of an underlying asset, which includes both the income it generates and any capital gains. In total return swaps, the underlying asset, referred to as the reference asset, is usually an equity index, loans or bonds. The asset is owned by the party receiving the set rate payment.
The total return swap allows one party to derive the economic benefit of owning an asset without putting that asset on its balance and allows the other, which does retain that asset on its balance sheet, to buy protection against loss in its value.

Hedge funds use total return swaps to obtain leverage on the reference assets: receiving the return of the asset, typically from a bank, which has a funding cost advantage, without having to put out the cash to buy the underlying assets.

Problems

  • Swaps pose a systemic risk to the global financial system because of:

    • Limited transparency

    • Immediate demand for liquidity through margin calls

    • Cumbersome tracking

    • Reporting errors


  • The settlement process is complicated, manual driven, inefficient and error-prone
  • Changes in the underlying asset value could trigger margin calls causing a drain on many cash-strapped financial institutions at once

Solution with blockchain

Total Return Swap - Blockchain.jpegPicture 3


Contract As Code

The conceptual steps of the transaction are:
  • After terms are concluded, a swap agreement is coded into a smart contract with each counterparty’s cryptographic “addresses” which their identities and credit reputation “oraclized” (see below) and visible to both parties.
  • Each party will have an asset account and a collateral account. The smart contract will calculate each party’s required collateral and post the amount to the collateral account.
  • The associated contract documents are encrypted and stored in a distributed file system such as IPFS* and the hash of the location information is registered as metadata of the contract.
  • The smart contract will be compiled, “mined”, and posted to the blockchain.
  • The smart contract will calculate the gain/loss of each party based on “oraclized” market data feed at a defined period and adjust collateral requirements accordingly. If either of the parties has exhausted its asset account to post additional collateral required, a margin call alert will be triggered for posting more money or terminating the contract. The values of both accounts will be visible to authorized parties.
  • At the end of the contract term, the smart contact will settle the payout automatically.
It enables financial institutions and regulators to see aggregate exposure and gain risk management insights and reduce risks and manual tracking efforts.

Azure offers a Blockchain as a Service for companies to instantiate a private cloud based blockchain.

*: IPFS (https://github.com/ipfs/ipfs)  is a distributed peer-to-peer file system.

What does oraclize mean?


“Oraclize” services allow smart contracts to break free from their constraints by providing a trustless way to access data from the web. It allows blockchain applications to easily and efficiently access data from any data source (e.g. Web APIs): existing data sources can be used without needing to adapt them for the blockchain and can continue providing data via existing channels (typically a Web API).

“Oraclize” can be seen as an intermediary in a world designed to exist without intermediaries. While this can be seen as a “weakness”, it actually provides significant benefits.

OraclizeFlow.png
Picture 4

Example: a simple swap contract

This example contract is written in Solidity -- a language for writing smart contract in the Ethereum blockchain. Another language for Ether is Serpent. A browser based solidity compiler (Remix)  is available this link.

Ethereum is a public blockchain originally developed for crypto-coin Ether, which currently has about 28 billion USD in market cap -- see Picture 5 This Ethereum white paper describes the proposal for its proposal a decentralized smart contract and application platform.

//Simple swap contracts in solidity for a swap agreement swap-contract-example.sol
pragma solidity ^0.4.0;

// a contract to store and retrieve contract document and data
contract Oracle{
   address owner;

   event Printuint(uint _value);

   modifier onlyOwner{if (msg.sender != owner){throw;}else{_;}}
   function Oracle(){owner = msg.sender;}
   struct DocumentStruct{uint value;}
   mapping(bytes32 => DocumentStruct) public documentStructs;

   function StoreDocument(bytes32 key, uint value) onlyOwner returns (bool success) {
       documentStructs[key].value = value;
       return true;
   }

   function RetrieveData(bytes32 key) public constant returns(uint) {
       var d = documentStructs[key].value;
       Printuint(d);
       return d;
    }
}

//A swap contract

contract Swap {
 enum SwapState {available,open,started,ended}
 SwapState public currentState;
 address public counterparty1;
 address public counterparty2;
 uint public notional;
 bool public long;
 uint public margin;
 address public oracleID;
 bytes32 public endDate;
 address public creator;
 uint256 public startValue;

 event Printuint(uint _value);

modifier onlyState(SwapState expectedState) { if (expectedState == currentState) {_;} else {throw; } }
modifier onlyCreator{if (msg.sender != creator){throw;}else{_;}}

function Swap(address OAddress){
   d = Oracle(OAddress);
   oracleID = OAddress;
   creator = msg.sender;
   currentState = SwapState.available;
}

Oracle d;

 function CreateSwap(uint _notional, bool _long, bytes32 _startDate, bytes32 _endDate) onlyState(SwapState.available) payable returns (bool) {
     margin = msg.value;
     counterparty1 = msg.sender;
     notional = _notional;
     long = _long;
     currentState = SwapState.open;
     endDate = _endDate;
     startValue = RetrieveData(_startDate);
     Printuint(startValue);
     Printuint(margin);
     log0("Testing Log");
     return true;
 }

 function EnterSwap() onlyState(SwapState.open) payable returns (bool) {
     if(msg.value == margin) {
         counterparty2 = msg.sender;
         currentState = SwapState.started;
         return true;
     } else {
       throw;
     }
 }
   mapping(address => uint256) balances;
   mapping(address => mapping (address => uint256)) allowed;

 function PaySwap() onlyState(SwapState.started) returns (bool){
     var endValue = RetrieveData(endDate);
     var change = (notional * (startValue - endValue) / startValue) * 1000000000000000000; //convert wei to ETH
     var lvalue = change >= margin ? (this.balance) : (margin + change);
     var svalue = change <= -margin ? (this.balance) : (margin - change);
     var lparty = long == true ? counterparty1 : counterparty2;
     var sparty = long == true ? counterparty2 : counterparty1;
     if (lvalue > 0 ){
           lparty.send(lvalue);
     }
     if (svalue > 0){
         sparty.send(svalue);
     }
     currentState = SwapState.ended;
     return true;
 }

 struct DocumentStruct{
   uint value;
 }    
 function RetrieveData(bytes32 key) public constant returns(uint) {
   DocumentStruct memory doc;
   doc.value = d.documentStructs(key);
   return doc.value;
 }
}
Contracts can be visualized using solgraph and “dot”:
  • To install solgraph:  npm install --save -g solgraph
  • To convert to graph with dot:  solgraph swap-contract-example.sol > swap-contract-example.dot
  • To convert dot to png: dot -Tpng swap-contract-example.dot > swap-contract-example.png

mySwapContract.png
Screen Shot 2017-06-29 at 9.39.43 AM.png
          Picture 5: Historical price chart of Ether


Current blockchain technology landscape

Current major blockchain technologies and players are shown in the picture as follows.
Blockchain-technology-landscape-infographic-xbrl-us.pngPicture 5 (source: XBRL)

Conclusion

There are many other promising use cases for blockchain applications in capital markets, especially in OTC securities such as swaps, to help reduce risks, frauds, and costs; automate processing and compliance. In the near term, there are still many challenges to overcome in realizing the potential of blockchains in the capital markets, including:

  • Fragmented architectures, protocols and development tools
  • Integration to existing systems, such as accounting and reporting systems
  • A need for easy-to-use and user-friendly cross-platform contract specification language, and contract analyzers, e.g. Oyente,  and testing tools
  • A need for standard an inter-ledger protocol