Whew … those were a lot of buzzwords. Let’s start by breaking each of them down.
Rust is an exciting new programming language from the fine folks over at the Mozilla foundation. It’s a low-level language that offers extreme performance with no run-time since it targets the LLVM. This makes it ideal for embedded/low powered devices. Other notable features are the lack of a garbage collector, strong compile time checks (such as the borrow checker), support for functional programming constructs (such as closures), and object oriented constructs (via traits). If you’d like to learn more, I highly recommend the Rust Book.
Rust also includes first-class support for compiling down to WebAssembly. With its strong memory safety paradigms, it is an ideal language for this purpose.
An option is a derivative financial instrument that gives the buyer the right to purchase/sell an asset at a specific price. It also allows for the seller of the options contract to generate income on assets that they have in their portfolio by taking a view on whether they see an upswing or downswing in the price of an asset.
Let’s take an example. Say you think the price of AAPL is going to go above $125 from its current price of $100 after they announce the next iPhone. In such a situation, you can buy a CALL option for a strike price at $125 that expires at the end of September. What this means is that if by the end of September, the price of the AAPL stock reaches $150, having the option contract gives you the right to buy AAPL stock at $125 and you can instantly pocket the profit of $25 by selling AAPL back at $150 (minus how much it costs to purchase the option contract of course). However, if the price never reaches $125 by the end of September, your investment in the option becomes worthless and you lost your money. Likewise, a PUT option gives you the ability to sell an asset at a price in case you believe the asset will go down by a certain amount.
Pricing an option is not a straightforward task as there are multiple factors associated with the price known as ‘The Greeks’. While the math behind pricing an option goes beyond the scope of this blog post, I recently stumbled upon a blog post by Ronnie Chowdhury entitled Probably the fastest Black Scholes Pricer in the world. I recommend reading through the post but the most interesting technical bit of information for me was a topic called SIMD that allows the CPU to perform multiple operations with one instruction set.
With SIMD, instead we could instead act on multiple numbers together.
From the above we are iterating over each value and adding them one by one. But you would hope the compiler is clever enough to see that actually there’s an instruction _mm_add_ps() that could do 8 additions in 1 instruction. That’s 8x faster.”
I was able to make some small changes to Ronnie’s code which you can find here to allow it to be compiled to WebAssembly.
Here is an image of the application in action:
To run this yourself, follow the instructions in this repo.
Thomas Kunnumpurath is the vice president of systems engineering, Americas at Solace. He enjoys evangelizing the benefits of using Solace to supercharge digital transformation to customers ranging in industries from capital markets to the United States Army.[position] => [url] => https://solace.com/blog/author/thomaskunnumpurath/ ) )