@haydenr4/black76_wasm
Version:
Black76 option pricing model calculator
873 lines (842 loc) • 26.9 kB
JavaScript
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
let cachedUint8Memory0 = null;
function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}
function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
let cachedFloat32Memory0 = null;
function getFloat32Memory0() {
if (cachedFloat32Memory0 === null || cachedFloat32Memory0.byteLength === 0) {
cachedFloat32Memory0 = new Float32Array(wasm.memory.buffer);
}
return cachedFloat32Memory0;
}
let cachedInt32Memory0 = null;
function getInt32Memory0() {
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachedInt32Memory0;
}
function getObject(idx) { return heap[idx]; }
function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function isLikeNone(x) {
return x === undefined || x === null;
}
/**
* The type of option to be priced (call or put).
*/
export const OptionType = Object.freeze({ Call:0,"0":"Call",Put:1,"1":"Put", });
/**
* The inputs to the Black76 model.
*/
export class Inputs {
static __wrap(ptr) {
const obj = Object.create(Inputs.prototype);
obj.ptr = ptr;
return obj;
}
toJSON() {
return {
option_type: this.option_type,
f: this.f,
k: this.k,
p: this.p,
r: this.r,
t: this.t,
sigma: this.sigma,
};
}
toString() {
return JSON.stringify(this);
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_inputs_free(ptr);
}
/**
* Calculates the delta of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the delta of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let delta = inputs.calc_delta().unwrap();
* ```
* @returns {number}
*/
calc_delta() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_delta(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the gamma of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the gamma of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let gamma = inputs.calc_gamma().unwrap();
* ```
* @returns {number}
*/
calc_gamma() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_gamma(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the theta of the option.
* Uses 365.25 days in a year for calculations.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of theta per day (not per year).
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let theta = inputs.calc_theta().unwrap();
* ```
* @returns {number}
*/
calc_theta() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_theta(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the vega of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the vega of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let vega = inputs.calc_vega().unwrap();
* ```
* @returns {number}
*/
calc_vega() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_vega(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the rho of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the rho of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let rho = inputs.calc_rho().unwrap();
* ```
* @returns {number}
*/
calc_rho() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_rho(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the epsilon of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the epsilon of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let epsilon = inputs.calc_epsilon().unwrap();
* ```
* @returns {number}
*/
calc_epsilon() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_epsilon(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the lambda of the option.
* # Requires
* s, k, r, t, sigma
* # Returns
* f32 of the lambda of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks, Pricing};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let lambda = inputs.calc_lambda().unwrap();
* ```
* @returns {number}
*/
calc_lambda() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_lambda(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the vanna of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the vanna of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let vanna = inputs.calc_vanna().unwrap();
* ```
* @returns {number}
*/
calc_vanna() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_vanna(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let charm = inputs.calc_charm().unwrap();
* ```
* @returns {number}
*/
calc_charm() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_charm(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the veta of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the veta of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let veta = inputs.calc_veta().unwrap();
* ```
* @returns {number}
*/
calc_veta() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_veta(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the vomma of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the vomma of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let vomma = inputs.calc_vomma().unwrap();
* ```
* @returns {number}
*/
calc_vomma() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_vomma(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the speed of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the speed of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let speed = inputs.calc_speed().unwrap();
* ```
* @returns {number}
*/
calc_speed() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_speed(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the zomma of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the zomma of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let zomma = inputs.calc_zomma().unwrap();
* ```
* @returns {number}
*/
calc_zomma() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_zomma(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the color of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the color of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let color = inputs.calc_color().unwrap();
* ```
* @returns {number}
*/
calc_color() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_color(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the ultima of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the ultima of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let ultima = inputs.calc_ultima().unwrap();
* ```
* @returns {number}
*/
calc_ultima() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_ultima(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the dual delta of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the dual delta of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let dual_delta = inputs.calc_dual_delta().unwrap();
* ```
* @returns {number}
*/
calc_dual_delta() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_dual_delta(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates the dual gamma of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* f32 of the dual gamma of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let dual_gamma = inputs.calc_dual_gamma().unwrap();
* ```
* @returns {number}
*/
calc_dual_gamma() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_dual_gamma(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Calculates all Greeks of the option.
* # Requires
* f, k, r, t, sigma
* # Returns
* HashMap of type <String, f32> of all Greeks of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Greeks};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let greeks = inputs.calc_all_greeks().unwrap();
* ```
* @returns {string}
*/
calc_all_greeks() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_all_greeks(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
var ptr0 = r0;
var len0 = r1;
if (r3) {
ptr0 = 0; len0 = 0;
throw takeObject(r2);
}
return getStringFromWasm0(ptr0, len0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export_0(ptr0, len0);
}
}
/**
* Calculates the implied volatility of the option.
* Tolerance is the max error allowed for the implied volatility,
* the lower the tolerance the more iterations will be required.
* Recommended to be a value between 0.001 - 0.0001 for highest efficiency/accuracy.
* Initializes estimation of sigma using Brenn and Subrahmanyam (1998) method of calculating initial iv estimation.
* Uses Newton Raphson algorithm to calculate implied volatility.
* # Requires
* f, k, r, t, p
* # Returns
* f32 of the implied volatility of the option.
* # Example:
* ```
* use black76_wasm::{Inputs, OptionType, ImpliedVolatility};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, Some(0.2), 0.05, 20.0/365.25, None);
* let iv = inputs.calc_iv(0.0001).unwrap();
* ```
* Initial estimation of sigma using Modified Corrado-Miller from ["A MODIFIED CORRADO-MILLER IMPLIED VOLATILITY ESTIMATOR" (2007) by Piotr P√luciennik](https://sin.put.poznan.pl/files/download/37938) method of calculating initial iv estimation.
* Note: While this method is more accurate than Brenn and Subrahmanyam (1998) it will still sometimes fail to converge.
* An example of failure to converge:
* ```
* use black76_wasm::{Inputs, OptionType, ImpliedVolatility};
* let inputs = Inputs::new(OptionType::Call, 105.0, 100.0, Some(30.0), 0.05, 30.0 / 365.25, None).calc_iv(0.0001).unwrap();
* // This will fail to converge, the NaN sigma value is checked in the function and will return an error.
* assert(inputs.calc_iv(0.0001).is_err(), true);
* ```
* @param {number} tolerance
* @returns {number}
*/
calc_iv(tolerance) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_iv(retptr, this.ptr, tolerance);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* The type of the option (call or put)
* @returns {number}
*/
get option_type() {
const ret = wasm.__wbg_get_inputs_option_type(this.ptr);
return ret >>> 0;
}
/**
* The type of the option (call or put)
* @param {number} arg0
*/
set option_type(arg0) {
wasm.__wbg_set_inputs_option_type(this.ptr, arg0);
}
/**
* Futures price
* @returns {number}
*/
get f() {
const ret = wasm.__wbg_get_inputs_f(this.ptr);
return ret;
}
/**
* Futures price
* @param {number} arg0
*/
set f(arg0) {
wasm.__wbg_set_inputs_f(this.ptr, arg0);
}
/**
* Strike price
* @returns {number}
*/
get k() {
const ret = wasm.__wbg_get_inputs_k(this.ptr);
return ret;
}
/**
* Strike price
* @param {number} arg0
*/
set k(arg0) {
wasm.__wbg_set_inputs_k(this.ptr, arg0);
}
/**
* Option price
* @returns {number | undefined}
*/
get p() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.__wbg_get_inputs_p(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getFloat32Memory0()[retptr / 4 + 1];
return r0 === 0 ? undefined : r1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Option price
* @param {number | undefined} arg0
*/
set p(arg0) {
wasm.__wbg_set_inputs_p(this.ptr, !isLikeNone(arg0), isLikeNone(arg0) ? 0 : arg0);
}
/**
* Risk-free rate
* @returns {number}
*/
get r() {
const ret = wasm.__wbg_get_inputs_r(this.ptr);
return ret;
}
/**
* Risk-free rate
* @param {number} arg0
*/
set r(arg0) {
wasm.__wbg_set_inputs_r(this.ptr, arg0);
}
/**
* Time to maturity in years
* @returns {number}
*/
get t() {
const ret = wasm.__wbg_get_inputs_t(this.ptr);
return ret;
}
/**
* Time to maturity in years
* @param {number} arg0
*/
set t(arg0) {
wasm.__wbg_set_inputs_t(this.ptr, arg0);
}
/**
* Volatility
* @returns {number | undefined}
*/
get sigma() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.__wbg_get_inputs_sigma(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getFloat32Memory0()[retptr / 4 + 1];
return r0 === 0 ? undefined : r1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Volatility
* @param {number | undefined} arg0
*/
set sigma(arg0) {
wasm.__wbg_set_inputs_sigma(this.ptr, !isLikeNone(arg0), isLikeNone(arg0) ? 0 : arg0);
}
/**
* Creates instance ot the `Inputs` struct.
* # Arguments
* * `option_type` - The type of option to be priced.
* * `f` - The current price of the underlying asset.
* * `k` - The strike price of the option.
* * `p` - The dividend yield of the underlying asset.
* * `r` - The risk-free interest rate.
* * `t` - The time to maturity of the option in years.
* * `sigma` - The volatility of the underlying asset.
* # Example
* ```
* use black76::{Inputs, OptionType};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* ```
* # Returns
* An instance of the `Inputs` struct.
* @param {number} option_type
* @param {number} f
* @param {number} k
* @param {number | undefined} p
* @param {number} r
* @param {number} t
* @param {number | undefined} sigma
*/
constructor(option_type, f, k, p, r, t, sigma) {
const ret = wasm.inputs_new(option_type, f, k, !isLikeNone(p), isLikeNone(p) ? 0 : p, r, t, !isLikeNone(sigma), isLikeNone(sigma) ? 0 : sigma);
return Inputs.__wrap(ret);
}
/**
* Calculates the price of the option.
* # Requires
* f, k, r, q, t, sigma.
* # Returns
* f32 of the price of the option.
* # Example
* ```
* use black76::{Inputs, OptionType, Pricing};
* let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 20.0/365.25, Some(0.2));
* let price = inputs.calc_price().unwrap();
* ```
* @returns {number}
*/
calc_price() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.inputs_calc_price(retptr, this.ptr);
var r0 = getFloat32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
}
export function __wbindgen_string_new(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};