Blockchain: Distributed Consensus Protocols

•August 11, 2015 • Leave a Comment

Dom Steil article on Distributed Consensus Protocols provides an overview of a few of the implements available.

Asset creation built from the Bitcoin blockchain = Sidechains

Asset creation built off the Bitcoin blockchain = Counterparty

Asset ledger creation built on distributed nodes = Hyperledger

Application and smart contract creation = Ethereum (AWS mining and “Create your own Crypto-Currency”)

Application framework built on top of Ethereum = Eris. Ethereum has gained further press recently around Adept and Provenance.

One would assume that the investment banking arena is most interested in Hyperledger, MultiChain and Ethereum from an asset trading and post trade perspective – due to Confidential Transactions.  Curious also as to what banks are looking at t0 (the trade is the settlement)

Blockchain: Smart Contracts

•August 10, 2015 • Leave a Comment

ABN AMRO Head of Innovation Arjan van Os make a number of excellent comments worth repeating in the blog posting, “The Next Big Thing”:

“Each node maintains an identical copy of a shared transaction ledger – the so-called ‘single source of truth,’” says van Os. “As transactions take place, the nodes communicate with each other to verify that the transaction is valid. If the ledgers don’t match up, the transaction is rejected. That virtually eliminates the single point of failure: If one server is hacked, the other nodes will recognize the intrusion and block the hacking attempt. The more nodes added to the Blockchain, the more security the transaction has.”

Making explicit reference to Smart Contracts:

One of the ‘hidden gems’ of Blockchain technology comes in the form of Smart Contracts. Through specific scripts in the Blockchain, all conditions of any contractual agreement can be stored, verified and secured within the system. In this way, users can program the exact conditions under which a contract can be executed, thereby mitigating risk and increasing trust for all stakeholders.

Its probably an understatement to say that most banks are in a race to identify how to use cryptocurrencies in the financial sector and get ahead of the competition – as noted by Italian banking group Intesa Sanpaolo:

[the bitcoin protocol’s] potential is far from being fully explored especially as a means to transfer rights and value in a very secure way

Richard Brown has a good posting on smart contracts, and shared ledger, and more interestingly, shared business logic – think collateral management and other such business problems.

Blockchain Distributed Ledger Thoughts

•July 30, 2015 • Leave a Comment

If you interested in what CitiCoin and others in finance are doing with blockchain technology, I suspect you may want to start by reading Alternative chain.  Storing trades into blockchain will involve a custom transaction and a new network – a bank/exchange network one has to assume.  Maybe we’ll see a bank lead consortium setup similar to what the banks did with regards to secure chat services.  This leads us to Eris, which is probably worth a look due to its custom blockchain and docker play containers – and bank examples.

Also check out Hyperledger.

FX Trading Tile with Clojure/ClojureScript

•July 22, 2015 • Leave a Comment

Anyone who subscribes to any of my social network feeds would have seen an increase in Clojure noise over the last time period.  Clojure is interesting not just from a language perspective (Lisp) but from the few financial projects that have made the conferences over the last few years.  Although a niche language in many ways, it has a lot going for it, if like most things, you are prepared to invest a little time and effort.

What follows is my FX trading work in progress hack that will hopefully offer food for thought ;)

The main aim of the code hack was to get a simple FX currency pair tile in a browser built using ClojureScript, backed by a Clojure server.  Starting point for the project as lein-figwheel with Reagent.

Remember the code below (client followed by server code) has been hacked up, so ignore the hard coding et al.  The primary aim is as a learning tool, never to enter production :)

(ns ^:figwheel-always clojurefxtitle.core
              [reagent.core :as reagent :refer [atom]]
              [clojurefxtitle.pricecomponent :as t]


(defonce app-state (atom {:text "FX Dashboard"
                        :counters {"USDGBP" {:id 1
                                             :name "USDGBP"}
                                   "USDEUR" {:id 2
                                             :name "USDEUR"}
                                   "USDJPY" {:id 3
                                             :name "USDJPY"}

(defn pricetitle-component []

(defn fxtile [c]
  [:div {:style {:background "green" :width "300" :float "left" :border-style "solid"} }
    [:h1 {:style {:text-align "center" :margin "0" }} (:name c) ]
          [t/price-component (:name c)  "Buy"]
          [t/price-component (:name c)  "Sell"]

(defn dashboard []
  [:div {:style {:width "100%"} }
    (for [counter (vals (:counters @app-state))]
      ^{:key (:name counter)} [fxtile counter]

(reagent/render-component [dashboard]
                          (. js/document (getElementById "app")))

(defn on-js-reload []

With the pricing component as per reference above, as follows:

(defn handler [response]
  (println "handler: " (str response))

(defn error-handler  [{:keys [status status-text]}]
  (println "error handler: " (str "something bad happened: " status " " status-text))

(defn my-click-handler [ccypair side price]
  (println (str "order " ccypair " " side " " price))
  (POST "/order"
          {:params {:price price
                    :side side
                    :ccypair ccypair}
           :handler handler
           :format :json
           :error-handler error-handler})    
(defn rand-price [val]
  (rand-nth val))

(defn price-component [ccypair side]
  (let [seconds-elapsed (atom 0)
       whole_number (range 95000 100000)]
    (fn []
      (js/setTimeout #(reset! seconds-elapsed (rand-price whole_number)) 1000)
;;      (js/setTimeout #(swap! seconds-elapsed inc) 1000)
      (let [price (/ @seconds-elapsed 1000)]
        [:button {:style {:background "red" :width "150" :float "left" :text-align "center"}
           :on-click #(my-click-handler ccypair side price)}
         side (gstring/format " %0.3f" price )])))

Clearly the code is using atom’s, as one would expect. I had a few problems with the JSON web service “order” method, but ended up resolving the issue with cljs-ajax. Also using the ring server and handler to handle the routing.  Had a few issues with http-kit deserialisation of the request, but I think that was partly my own silliness.

(ns server
   [ring.middleware.resource :refer [wrap-resource]]
   [ring.middleware.json :as middleware]
   [ring.middleware.file-info :refer [wrap-file-info]]
   [ring.util.response :refer [redirect]]
   [compojure.handler :as handler]
   [compojure.core :refer :all]
   [compojure.route :as route]

(defn handler [request]
  (case (request :uri)
    "/" (redirect "index.html")

(defn order-handler [req]
;;  (let [body (-> req :body)]
;;    (println "Request: " req " Body: " body)
;;  )
  (let [price (-> req :params :price)
    ccypair (-> req :params :ccypair)
    side (-> req :params :side)]
      (println (str "Order: " price side ccypair)) 
  {:status 200 }
(defroutes app-routes
  (GET "/" [] (redirect "index.html"))
  (POST "/order" [] order-handler) 
  (route/not-found "<h1>Custom - Page not found</h1>"))
(def app
  (-> (handler/api app-routes)

Items to work on next:

  • Moving the simply price generator to the Clojure server, and streaming the prices via Websockets – possible using chord or Sente.
  • Look at agents for the server.  Avout and onyx also look interesting.
  • Dependency injection (e.g. clj-di) and MVC would be nice client side.

Summer Finance Tech Coding – Neo4j, Clojure/Om and Spark

•July 15, 2015 • Leave a Comment

I’m playing with a number of different technologies at the moment.  Mostly extensions of ideas I’ve previously blogged about.

  • Timelines and Neo4j
    • Specifically I’m interested in modelling the trade lifecycle in Neo4j (as discussed here) and also Skill Cloud (here) and avoiding the “current” view graphs that most applications/samples use.  Primarily leveraging ES6 code with Seraph as I’m not concerned about performance for this prototype.
    • There are a few interesting references documents that are worth a read:
      • Representing time dependent graphs in Neo4j
      • Time-Based Versioned Graphs – Ian’s solutions is quite clear in that it primarily leverages properties on relationships:

Each relationship has a from property with a long millisecond value representing 1 January 2014, and a to property with a very large long value (End-Of-Time, or EOT, which is a magic number – in this case Long.MAX_VALUE) that effectively means there is no current upper bound to the period associated with the relationship.

  • Spark
  • Clojure
    • Om Next – David Nolen presentation has rekindled my interested in ClojureScript.  Push Technologies offer a simple but FX bias demo of ClojureScript streaming prices – although not overly complex the demo does offer food for though with regards to Clojure in the electronic trading space. “Brandon Bloom – Building CircleCI’s Front end With Om” provide some insight into the challenges of an Om project.  Deployment to production is offered by lein-ring, IDE of choice is Cursive.  Clojure compiling to the JVM should avoid a degree of issues in the corporate space.

ES6 and Visual Studio Code

•July 10, 2015 • Leave a Comment

The July update of Visual Studio Code finally offer some sense in the ES6 world.  Add in a jsconfig.json to the root folder of your project, and at a minimum add the following to the file:

     "compilerOptions": {
          "target": "ES6"

Post-Trade Blockchain

•July 6, 2015 • Leave a Comment

BNP Paribas Quintessence  provide an interesting view on how Blockchain could affect the post-trade world:

  1. Distributed blockchain system allowing all market participants direct access to the DSD (Decentralised Securities Depositary), to the exchange and to the post trade infrastructure (clearing & settlement)
  2. Standardised post trade integration – custodians or settlement infrastructures might use the blockchain to record the ownership and trades between themselves.

The BNP Paribas comments come at a time when Nasdaq is also trailing blockchain around trade ledger processing.   Its probably also worth watching what comes out of Digital Assets.


Get every new post delivered to your Inbox.

Join 699 other followers