BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

Option Mark-to-Market Logic #187

Closed patrickdugan closed 1 year ago

patrickdugan commented 4 years ago

The way options work as a hedge requires that the holder of a Put, for example, gets a mark-to-market update on their Put's PNL each block just like their Married Futures position gets an update. Otherwise they'd get no credit for the value of the Put rising as the market drops, and they would still be at risk of liquidation. In practice, if you buy 1 BTC ATM Put and 1 BTC Future at that strike price, you should only risk losing the premium paid for the Put, and have no liquidation price at all.

To make this work, we cannot rely on a VWAP of the contracts. We have to assume that there is only one Option contract that only sees one trade, and that buyer will go long a Futures position of equal size, and that buyer must be guaranteed no liquidation price. The only way to do this is to implement Black Scholes or some other model into the mark-pricing formula. Then each block, the margin logic will see, well according to Black Scholes this option should be worth x, which gives you some PNL, and according to the VWAP of tokens or the TWAP of the Oracle your futures position is losing y, and on balance you're not in danger of liquidation. Black Scholes is simpler to implement in code than the Binomial pricing model, since it's just a differential equation and there are a lot of existing open source implementations, here's one:

function blackScholes(s, k, t, v, r, callPut) { var price = null; var w = (r t + Math.pow(v, 2) t / 2 - Math.log(k / s)) / (v Math.sqrt(t)); if(callPut === "call") { price = s stdNormCDF(w) - k Math.pow(Math.E, -1 r t) stdNormCDF(w - v Math.sqrt(t)); } else // put { price = k Math.pow(Math.E, -1 r t) stdNormCDF(v Math.sqrt(t) - w) - s * stdNormCDF(-w); } return price; }

https://github.com/MattL922/black-scholes/blob/master/black-scholes.js

Alternatively we could do a very simple mark-price based on the intrinsic value of an in-the-money option to test it out before going ham on a Black Scholes implementation. But a BS or something more kurtotic would be good for keeping people leveraged on a lot of spreads in a reasonable mark-to-market PNL without needing a highly liquid option chain.