Class: Rupee::Option

Inherits:
Security show all
Defined in:
lib/rupee/option.rb,
ext/rupee/option.c

Direct Known Subclasses

Call, Put

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Security

attr_alias, #initialize

Constructor Details

This class inherits a constructor from Rupee::Security

Instance Attribute Details

#div_yieldObject

The dividend yield


16
17
18
# File 'lib/rupee/option.rb', line 16

def div_yield
  @div_yield
end

#priceObject

The price of the option


20
21
22
# File 'lib/rupee/option.rb', line 20

def price
  @price
end

#rateObject

The risk-free rate


14
15
16
# File 'lib/rupee/option.rb', line 14

def rate
  @rate
end

#strikeObject

The strike price of the underlying security


10
11
12
# File 'lib/rupee/option.rb', line 10

def strike
  @strike
end

#timeObject

The remaining time to maturity


12
13
14
# File 'lib/rupee/option.rb', line 12

def time
  @time
end

#typeObject

The type of the option. Accepts "call" and "put".


6
7
8
# File 'lib/rupee/option.rb', line 6

def type
  @type
end

#underlyingObject

The price of the underlying security


8
9
10
# File 'lib/rupee/option.rb', line 8

def underlying
  @underlying
end

#volatilityObject

The annualized price volatility


18
19
20
# File 'lib/rupee/option.rb', line 18

def volatility
  @volatility
end

Class Method Details

.black76(call_put_flag, forward, strike_price, time_to_expiry) ⇒ Object .risk_free_rateObject

The Black-76 valuation for options on futures and forwards

Arguments

  • call_put_flag - Whether the instrument is a call © or a put (p)

  • forward - The current forward value

  • strike_price - The option’s strike price

  • time_to_expiry - The time to maturity in years

  • risk_free_rate - The risk-free rate through expiry

  • volatility - The implied volatility at expiry


611
612
613
# File 'ext/rupee/option.c', line 611

static VALUE
rupee_black76(self, _call_put_flag, _S, _K, _T, _r, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _v;

.black_scholes(call_put_flag, underlying, strike, time, rate) ⇒ Object

volatility)

The Black-Scholes European call/put valuation

Arguments

  • call_put_flag - Whether the instrument is a call © or a put (p)

  • forward - The current forward value

  • strike_price - The option’s strike price

  • time_to_expiry - The time to maturity in years

  • risk_free_rate - The risk-free rate through expiry

  • dividend_yield - The annual dividend yield

  • volatility - The implied volatility at expiry


512
513
514
# File 'ext/rupee/option.c', line 512

static VALUE
rupee_black_scholes(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.charm(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the charm options Greek (sensitivity of delta to the passage of time)


250
251
252
# File 'ext/rupee/option.c', line 250

static VALUE
rupee_charm(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.color(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the color options Greek (sensitivity of gamma to the passage of time)


332
333
334
# File 'ext/rupee/option.c', line 332

static VALUE
rupee_color(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.delta(call_put_flag, underlying, strike, time, rate, div_yield) ⇒ Object

volatility)

Returns the delta options Greek (sensitivity to changes in the underlying’s price)


109
110
111
# File 'ext/rupee/option.c', line 109

static VALUE
rupee_delta(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.dual_delta(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the dual delta options Greek (probability of finishing in-the-money)


409
410
411
# File 'ext/rupee/option.c', line 409

static VALUE
rupee_dual_delta(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.dual_gamma(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the dual gamma options Greek.


436
437
438
# File 'ext/rupee/option.c', line 436

static VALUE
rupee_dual_gamma(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.dvega_dtime(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the dvega dtime options Greek (sensitivity of vega to the passage of time)


359
360
361
# File 'ext/rupee/option.c', line 359

static VALUE
rupee_dvega_dtime(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.gamma(call_put_flag, underlying, strike, time, rate, div_yield) ⇒ Object

volatility)

Returns the gamma options Greek (sensitivity to changes in delta; convexity)


202
203
204
# File 'ext/rupee/option.c', line 202

static VALUE
rupee_gamma(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.generalized_black_scholes(call_put_flag, forward, strike_price) ⇒ Object .time_to_expiryObject

The generalized Black-Scholes European call/put valuation

Arguments

  • call_put_flag - Whether the instrument is a call © or a put (p)

  • forward - The current forward value

  • strike_price - The option’s strike price

  • time_to_expiry - The time to maturity in years

  • risk_free_rate - The risk-free rate through expiry

  • cost_of_carry - The annualized cost of carry

  • volatility - The implied volatility at expiry


562
563
564
# File 'ext/rupee/option.c', line 562

static VALUE
rupee_generalized_black_scholes(self, _call_put_flag, _S, _K, _T, _r, _b, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _b, _v;

.implied_volatility(call_put_flag, underlying, strike, time, rate) ⇒ Object

div_yield, price)

Returns the Black-Scholes implied volatility using the Newton-Raphson method


462
463
464
# File 'ext/rupee/option.c', line 462

static VALUE
rupee_impl_vol(self, _call_put_flag, _S, _K, _T, _r, _q, _cm)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _cm;

.rho(call_put_flag, underlying, strike, time, rate, div_yield) ⇒ Object

volatility)

Returns the rho options Greek (sensitivity to the risk-free rate)


179
180
181
# File 'ext/rupee/option.c', line 179

static VALUE
rupee_rho(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.rupee_speed(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the speed options Greek (sensitivity of gamma to changes in the underlying’s price).


281
282
283
# File 'ext/rupee/option.c', line 281

static VALUE
rupee_speed(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.theta(call_put_flag, underlying, strike, time, rate, div_yield) ⇒ Object

volatility)

returns the theta options greek (sensitivity to the passage of time; time decay)


156
157
158
# File 'ext/rupee/option.c', line 156

static VALUE
rupee_theta(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.vanna(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the vanna options Greek (sensitivity of delta to changes in volatility)


225
226
227
# File 'ext/rupee/option.c', line 225

static VALUE
rupee_vanna(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.vega(call_put_flag, underlying, strike, time, rate, div_yield) ⇒ Object

volatility)

Returns the vega options Greek (sensitivity to changes in volatility)


132
133
134
# File 'ext/rupee/option.c', line 132

static VALUE
rupee_vega(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.vomma(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the vomma options Greek (sensitivity of vega to changes in volatility)


385
386
387
# File 'ext/rupee/option.c', line 385

static VALUE
rupee_vomma(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

.zomma(call_put_flag, S, K, T, r, q, v) ⇒ Object

Returns the zomma options Greek (sensitivity of gamma to changes in volatility)


306
307
308
# File 'ext/rupee/option.c', line 306

static VALUE
rupee_zomma(self, _call_put_flag, _S, _K, _T, _r, _q, _v)
VALUE self, _call_put_flag, _S, _K, _T, _r, _q, _v;

Instance Method Details

#black_scholesObject


26
27
28
29
# File 'lib/rupee/option.rb', line 26

def black_scholes
  @value = self.class.black_scholes @type.to_s, @underlying, @strike,
    @time, @rate, @div_yield, @volatility
end