OptionMathExternal

Git Source

Functions

optionDelta

Calculate option delta

function optionDelta(
    UD60x18 spot,
    UD60x18 strike,
    UD60x18 timeToMaturity,
    UD60x18 volAnnualized,
    UD60x18 riskFreeRate,
    bool isCall
) public pure returns (SD59x18);

Parameters

NameTypeDescription
spotUD60x18Spot price
strikeUD60x18Strike price
timeToMaturityUD60x18Duration of option contract (in years)
volAnnualizedUD60x18Annualized volatility
riskFreeRateUD60x18
isCallboolwhether to price "call" or "put" option

Returns

NameTypeDescription
<none>SD59x18price Option delta

blackScholesPrice

Calculate the price of an option using the Black-Scholes model

this implementation assumes zero interest

function blackScholesPrice(
    UD60x18 spot,
    UD60x18 strike,
    UD60x18 timeToMaturity,
    UD60x18 volAnnualized,
    UD60x18 riskFreeRate,
    bool isCall
) public pure returns (UD60x18);

Parameters

NameTypeDescription
spotUD60x18Spot price (18 decimals)
strikeUD60x18Strike price (18 decimals)
timeToMaturityUD60x18Duration of option contract (in years) (18 decimals)
volAnnualizedUD60x18Annualized volatility (18 decimals)
riskFreeRateUD60x18The risk-free rate (18 decimals)
isCallboolwhether to price "call" or "put" option

Returns

NameTypeDescription
<none>UD60x18price The Black-Scholes option price (18 decimals)

computeCLevel

Calculates the C-level given a utilisation value and time since last trade value (duration). (https://www.desmos.com/calculator/0uzv50t7jy)

function computeCLevel(
    UD60x18 utilisation,
    UD60x18 duration,
    UD60x18 alpha,
    UD60x18 minCLevel,
    UD60x18 maxCLevel,
    UD60x18 decayRate
) public pure returns (UD60x18);

Parameters

NameTypeDescription
utilisationUD60x18The utilisation after some collateral is utilised
durationUD60x18The time since last trade (hours)
alphaUD60x18(needs to be filled in)
minCLevelUD60x18The minimum C-level
maxCLevelUD60x18The maximum C-level
decayRateUD60x18The decay rate of the C-level back down to minimum level (decay/hour)

Returns

NameTypeDescription
<none>UD60x18The C-level corresponding to the post-utilisation value.

computeCLevelGeoMean

Calculates the geo-mean C-level given a utilisation before and after collateral is utilised.

function computeCLevelGeoMean(
    UD60x18 utilisationBefore,
    UD60x18 utilisationAfter,
    UD60x18 duration,
    UD60x18 alpha,
    UD60x18 minCLevel,
    UD60x18 maxCLevel,
    UD60x18 decayRate
) public pure returns (UD60x18 cLevel);

Parameters

NameTypeDescription
utilisationBeforeUD60x18The utilisation before some collateral is utilised.
utilisationAfterUD60x18The utilisation after some collateral is utilised
durationUD60x18The time since last trade (hours)
alphaUD60x18(needs to be filled in)
minCLevelUD60x18The minimum C-level
maxCLevelUD60x18The maximum C-level
decayRateUD60x18The decay rate of the C-level back down to minimum level (decay/hour)

Returns

NameTypeDescription
cLevelUD60x18The C-level corresponding to the geo-mean of the utilisation value before and after collateral is utilised.