Real Time Example

Overview

The first robust model of pricing a derivative came with the Black Scholes Model.

In the following example, we assume that we are pricing a single plain vanilla call option.

  • {% S %} - the underlying price is {% 100 %}
  • d
  • {% K %} - the strike price is {% 100 %}
  • The volatility is {% 0.2 %}
  • The interest rate is set to be {% 0.01 %}
  • The time to maturity is 5 years

We use the black scholes library to compute the black scholes price.
(async ()=>{ let bs = await import('/lib/finance/derivatives/black-scholes/v1.0.0/black-scholes.mjs'); let price = bs.call(100,100,0.2,0.01,5); $console.log(price); })();`

Real Time Data

The following is a simple real time data source. It represents a list of options on a single stock, whose real time price is given by {% S %}.

(async ()=>{ let bs = await import('/code/black-scholes/v1.0.0/black-scholes.mjs'); let portfolio = $val('black-scholes'); let rate = 0.05 let data = portfolio.map(p=>{ return { ...p, "call-price":bs.call(p.S,p.K,p.vol,rate,p.t) } }); $val.set('portfolio', data); })();