Module: Math::GreekCalculations
- Included in:
- Math::Greeks::Calculator::GreekCalculations
- Defined in:
- lib/greeks/calculations/iv.rb,
lib/greeks/calculations/rho.rb,
lib/greeks/calculations/vega.rb,
lib/greeks/calculations/delta.rb,
lib/greeks/calculations/gamma.rb,
lib/greeks/calculations/theta.rb,
lib/greeks/calculations/time_values.rb,
lib/greeks/calculations/normal_distribution.rb
Instance Method Summary collapse
-
#annualized_premium_value(opts) ⇒ Object
Annualized Premium The annualized premium is the value of the option divided by the strike price.
-
#annualized_time_value(opts) ⇒ Object
Annualized Time Value The time value of the option divided by the strike price, then annualized.
-
#break_even(opts) ⇒ Object
Chance of Breakeven The probability that a stock will be trading beyond the breakeven price as implied by the option price.
-
#delta(opts) ⇒ Object
Delta A measurement of the change in the price of an option resulting from a change in the price of the underlying security.
-
#gamma(opts = {}) ⇒ Object
Gamma A measurement of the change in delta as the price of the underlying stock changes.
- #iv(opts) ⇒ Object
- #iv_calc(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, option_price, price_vs_rate_vs_expires, price_ratio_log_less_rates, strike_vs_fed_vs_expires) ⇒ Object
- #iv_option_price(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, price_ratio_log_less_rates, price_vs_rate_vs_expires, strike_vs_fed_vs_expires) ⇒ Object
- #iv_vega(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, price_ratio_log_less_rates, price_vs_rate_vs_expires) ⇒ Object
- #iv_volatility_guess0(stock_price, option_strike, option_expires_pct_year, federal_reserve_interest_rate_f, stock_dividend_rate_f) ⇒ Object
- #misc_d1(opts) ⇒ Object
- #misc_d2(opts) ⇒ Object
- #misc_d_normal_distribution(opts) ⇒ Object
- #misc_nd1(opts) ⇒ Object
- #misc_price_ratio_log_less_rates(opts) ⇒ Object
- #misc_price_vs_rate_vs_expires(opts) ⇒ Object
- #misc_rate_vs_expires(opts) ⇒ Object
- #misc_strike_vs_fed_vs_expires(opts) ⇒ Object
- #nil_or_gte0(value) ⇒ Object
-
#normal_distribution(value) ⇒ Object
Moddeled after the Excel NORMSDIST function.
-
#normal_distribution_gaussian(value) ⇒ Object
Normal distribution function (Gaussian bell curve).
-
#premium_value(opts) ⇒ Object
Intrinsic Value The value that the option would pay if it were executed today.
-
#rho(opts = {}) ⇒ Object
Rho The change in the value of an option for a change in the prevailing interest rate that matches the duration of the option, all else held equal.
- #theta(opts = {}) ⇒ Object
-
#time_value(opts) ⇒ Object
Time Value The value of an option that captures the chance of further appreciation before expiration.
-
#vega(opts = {}) ⇒ Object
Vega The change in the price of an option for a change in the implied volatility of the option, all else held equal.
Instance Method Details
#annualized_premium_value(opts) ⇒ Object
Annualized Premium The annualized premium is the value of the option divided by the strike price. You can use annualized premium to develop an intuitive understanding of how much the market is “paying” for a dollar of risk. For example, if a stock is trading at $50 and you sell a $50 strike 6 month call for $4, you are getting paid 8% in 6 months, or about 16% annualized, in exchange for being willing to buy at $50, the current price.
51 52 53 54 55 56 57 |
# File 'lib/greeks/calculations/time_values.rb', line 51 def annualized_premium_value(opts) return nil if opts[:option_price].nil? return nil if opts[:option_price] < 0 opts.requires_fields(:option_price, :option_strike, :option_expires_pct_year) nil_or_gte0(100 * Math.log(1 + opts[:option_price] / opts[:option_strike]) / opts[:option_expires_pct_year]) end |
#annualized_time_value(opts) ⇒ Object
Annualized Time Value The time value of the option divided by the strike price, then annualized. You can use annualized time value to develop an intuitive understanding of how much value the option market is adding to an in-the-money option beyond the intrinsic value. For example, if a stock is trading at $40 and a six month call on that stock with a strike price of $35 has an intrinsic value of $5 and a total value of $7, the time value ($2) divided by the strike is ($2/$40) = 5%. Annualizing that time value to a one year horizon on a continuously compounded basis yields 9.76% (2 × ln(1 + 0.05)).
67 68 69 70 71 72 |
# File 'lib/greeks/calculations/time_values.rb', line 67 def annualized_time_value(opts) return nil if opts[:time_value].nil? || opts[:time_value] < 0 opts.requires_fields(:option_strike, :option_expires_pct_year, :time_value) nil_or_gte0(100 * Math.log(1.0 + opts[:time_value] / opts[:option_strike]) / opts[:option_expires_pct_year]) end |
#break_even(opts) ⇒ Object
Chance of Breakeven The probability that a stock will be trading beyond the breakeven price as implied by the option price. Chance of Breakeven can be used to get a sense for the valuation of the option by comparing the markets’ estimate of Chance of Breakeven to estimates derived from your own fundamental research. If you believe the Chance of Breakeven is less than the probability that a stock will be beyond the breakeven price at option expiration, then you believe the option is undervalued, and visa versa.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/greeks/calculations/time_values.rb', line 81 def break_even(opts) opts.requires_keys_are_present(:option_price, :iv) return nil if opts[:option_price].nil? return nil if opts[:option_price] < 0 return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:option_type, :option_price, :option_strike, :option_expires_pct_year, :option_expires_pct_year_sqrt, :stock_price, :stock_dividend_rate_f, :federal_reserve_interest_rate_f, :iv) part1 = (opts[:federal_reserve_interest_rate_f] - opts[:stock_dividend_rate_f] - opts[:iv] * opts[:iv] / 2) * opts[:option_expires_pct_year] part2 = opts[:iv] * opts[:option_expires_pct_year_sqrt] case opts[:option_type] when :call return normal_distribution((Math.log(opts[:stock_price] / (opts[:option_strike] + opts[:option_price])) + part1) / part2) when :put return normal_distribution(-(Math.log(opts[:stock_price] / (opts[:option_strike] - opts[:option_price])) + part1) / part2) else raise ArgumentError, "Invalid option_type = #{opts[:option_type]}" end end |
#delta(opts) ⇒ Object
Delta A measurement of the change in the price of an option resulting from a change in the price of the underlying security. Delta is positive for calls and negative for puts. Delta can be calculated as the dollar change of the option that an investor can expect for a one-dollar change in the underlying security. For example, let’s say an option on a stock trading at $50 costs $1 and has a delta of $0.50 per dollar of underlying stock price change. If the stock price rises to $52, the price of the option will increase by $1 (the $2 price change times the $0.50 delta). After the stock price movement, the option will be worth $2 ($1 initial cost plus $1 delta). Delta can also be calculated as a percentage change in the option price for a one-percent change in the underlying security; this method of viewing the delta value is also known as “leverage.”
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/greeks/calculations/delta.rb', line 12 def delta(opts) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:option_type, :rate_vs_expires, :d1_normal_distribution, :iv) multiplier = case opts[:option_type] when :call 1.0 when :put -1.0 else raise "Invalid option_type = #{opts[:option_type].inspect}" end multiplier * opts[:rate_vs_expires] * opts[:d1_normal_distribution] end |
#gamma(opts = {}) ⇒ Object
Gamma A measurement of the change in delta as the price of the underlying stock changes. As the underlying stock price changes, the delta of the option changes, too. Gamma indicates how quickly your exposure to the price movement of the underlying security changes as the price of the underlying security varies. For example, if you have a call with a strike of $50 and the stock price is $50, the delta likely will be approximately $0.50 for a one-dollar movement of the stock. At a stock price of $60, the delta will be greater, closer to $0.75. At a stock price of $40, the delta will be less, closer to $0.25. In this example, if the stock price changes from $50 to $60, then the delta will change from $0.50 to $0.75. The $10 change in stock price caused a $0.25 change in delta, so gamma is approximately $0.25/10, or $0.025, in this case.
11 12 13 14 15 16 17 18 |
# File 'lib/greeks/calculations/gamma.rb', line 11 def gamma(opts = {}) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:stock_price, :option_expires_pct_year_sqrt, :nd1, :rate_vs_expires, :iv) opts[:nd1] * opts[:rate_vs_expires] / (opts[:stock_price] * opts[:iv] * opts[:option_expires_pct_year_sqrt]) end |
#iv(opts) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/greeks/calculations/iv.rb', line 3 def iv(opts) opts.requires_keys_are_present(:option_price) return nil if opts[:option_price].nil? return nil if opts[:option_price] <= 0 opts.requires_keys_are_not_nil(:stock_price, :option_strike, :option_expires_pct_year, :option_expires_pct_year_sqrt, :federal_reserve_interest_rate_f, :stock_dividend_rate_f, :option_type, :option_price, :rate_vs_expires, :price_vs_rate_vs_expires, :strike_vs_fed_vs_expires, :price_ratio_log_less_rates) iv_calc( opts[:stock_price], opts[:option_strike], opts[:option_expires_pct_year], opts[:option_expires_pct_year_sqrt], opts[:federal_reserve_interest_rate_f], opts[:stock_dividend_rate_f], opts[:option_type], opts[:option_price], opts[:price_vs_rate_vs_expires], opts[:price_ratio_log_less_rates], opts[:strike_vs_fed_vs_expires] ) end |
#iv_calc(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, option_price, price_vs_rate_vs_expires, price_ratio_log_less_rates, strike_vs_fed_vs_expires) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/greeks/calculations/iv.rb', line 54 def iv_calc(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, option_price, price_vs_rate_vs_expires, price_ratio_log_less_rates, strike_vs_fed_vs_expires) # Contstant values for the calculations price_limit = [0.005, 0.01 * option_price].min # Lambda for short-hand calculations calc_option_price = lambda { |volatility_guess| iv_option_price(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, price_ratio_log_less_rates, price_vs_rate_vs_expires, strike_vs_fed_vs_expires) } # Lambda for short-hand calculations calc_vega = lambda { |volatility_guess| iv_vega(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, price_ratio_log_less_rates, price_vs_rate_vs_expires) } # Lambda for short-hand calculations calc_volatility_guess1 = lambda { |var_volatility_guess, var_option_price, var_vega| var_volatility_guess - (var_option_price - option_price) / var_vega } # Lambda for short-hand calculations is_terminal_volatility_guess = lambda { |var_option_price| ((option_price - var_option_price).abs < price_limit) } # Lambda for short-hand calculations cleanup_volatility_guess = lambda { |volatility_guess| volatility_guess.nil? || volatility_guess <= 0 ? nil : volatility_guess.to_f } var_volatility_guess = iv_volatility_guess0(stock_price, option_strike, option_expires_pct_year, federal_reserve_interest_rate_f, stock_dividend_rate_f) var_volatility_guess = 0.1 if var_volatility_guess <= 0 var_option_price = calc_option_price.call(var_volatility_guess) if is_terminal_volatility_guess.call(var_option_price) return cleanup_volatility_guess.call(var_volatility_guess) end var_vega = calc_vega.call(var_volatility_guess) var_volatility_guess1 = calc_volatility_guess1.call(var_volatility_guess, var_option_price, var_vega) var_step = 1 max_steps = 13 while ((var_volatility_guess - var_volatility_guess1).abs > 0.0001 && var_step < max_steps) var_volatility_guess = var_volatility_guess1 var_option_price = calc_option_price.call(var_volatility_guess) if is_terminal_volatility_guess.call(var_option_price) return cleanup_volatility_guess.call(var_volatility_guess) end var_vega = calc_vega.call(var_volatility_guess) var_volatility_guess1 = calc_volatility_guess1.call(var_volatility_guess, var_option_price, var_vega) if (var_volatility_guess1 < 0) return cleanup_volatility_guess.call(var_volatility_guess1) end var_step += 1 end if (var_step < max_steps) return cleanup_volatility_guess.call(var_volatility_guess1) end var_option_price = calc_option_price.call(var_volatility_guess1) if is_terminal_volatility_guess.call(var_option_price) return cleanup_volatility_guess.call(var_volatility_guess1) else return nil end end |
#iv_option_price(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, price_ratio_log_less_rates, price_vs_rate_vs_expires, strike_vs_fed_vs_expires) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/greeks/calculations/iv.rb', line 33 def iv_option_price(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, option_type, price_ratio_log_less_rates, price_vs_rate_vs_expires, strike_vs_fed_vs_expires) var_d1 = (price_ratio_log_less_rates + volatility_guess * volatility_guess * option_expires_pct_year / 2) / (volatility_guess * option_expires_pct_year_sqrt) var_d2 = var_d1 - volatility_guess * option_expires_pct_year_sqrt case option_type when :call return price_vs_rate_vs_expires * normal_distribution(var_d1) - strike_vs_fed_vs_expires * normal_distribution(var_d2) when :put return strike_vs_fed_vs_expires * normal_distribution(-var_d2) - price_vs_rate_vs_expires * normal_distribution(-var_d1) else raise "Invalid option_type = #{option_type.inspect}" end end |
#iv_vega(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, price_ratio_log_less_rates, price_vs_rate_vs_expires) ⇒ Object
26 27 28 29 30 |
# File 'lib/greeks/calculations/iv.rb', line 26 def iv_vega(stock_price, option_strike, option_expires_pct_year, option_expires_pct_year_sqrt, volatility_guess, federal_reserve_interest_rate_f, stock_dividend_rate_f, price_ratio_log_less_rates, price_vs_rate_vs_expires) var_d1 = (price_ratio_log_less_rates + volatility_guess * volatility_guess * option_expires_pct_year / 2) / (volatility_guess * option_expires_pct_year_sqrt) var_nd = Math.exp(-var_d1 * var_d1 / 2) / Math::sqrt(2 * Math::PI) return price_vs_rate_vs_expires * option_expires_pct_year_sqrt * var_nd end |
#iv_volatility_guess0(stock_price, option_strike, option_expires_pct_year, federal_reserve_interest_rate_f, stock_dividend_rate_f) ⇒ Object
48 49 50 51 |
# File 'lib/greeks/calculations/iv.rb', line 48 def iv_volatility_guess0(stock_price, option_strike, option_expires_pct_year, federal_reserve_interest_rate_f, stock_dividend_rate_f) Math.sqrt( (Math.log(stock_price / option_strike) + (federal_reserve_interest_rate_f - stock_dividend_rate_f) * option_expires_pct_year).abs * 2 / option_expires_pct_year) end |
#misc_d1(opts) ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/greeks/calculations/time_values.rb', line 146 def misc_d1(opts) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:price_ratio_log_less_rates, :iv, :option_expires_pct_year, :option_expires_pct_year_sqrt) (opts[:price_ratio_log_less_rates] + opts[:iv] * opts[:iv] * opts[:option_expires_pct_year] / 2) / (opts[:iv] * opts[:option_expires_pct_year_sqrt]) end |
#misc_d2(opts) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/greeks/calculations/time_values.rb', line 156 def misc_d2(opts) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:d1, :iv, :option_expires_pct_year_sqrt) opts[:d1] - opts[:iv] * opts[:option_expires_pct_year_sqrt] end |
#misc_d_normal_distribution(opts) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/greeks/calculations/time_values.rb', line 165 def misc_d_normal_distribution(opts) opts.requires_keys_are_present(:d_value) return nil if opts[:d_value].nil? opts.requires_keys_are_not_nil(:option_type, :d_value) multiplier = case opts[:option_type] when :call 1.0 when :put -1.0 else raise ArgumentError, "Invalid option_type = #{opts[:option_type]}" end normal_distribution(multiplier * opts[:d_value]) end |
#misc_nd1(opts) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/greeks/calculations/time_values.rb', line 136 def misc_nd1(opts) opts.requires_keys_are_present(:d1) return nil if opts[:d1].nil? opts.requires_keys_are_not_nil(:d1) Math.exp(-0.5 * opts[:d1] * opts[:d1]) / Math.sqrt(2 * Math::PI) end |
#misc_price_ratio_log_less_rates(opts) ⇒ Object
108 109 110 111 112 |
# File 'lib/greeks/calculations/time_values.rb', line 108 def misc_price_ratio_log_less_rates(opts) opts.requires_fields(:stock_price, :option_strike, :option_expires_pct_year, :federal_reserve_interest_rate_f, :stock_dividend_rate_f) Math.log(opts[:stock_price] / opts[:option_strike]) + (opts[:federal_reserve_interest_rate_f] - opts[:stock_dividend_rate_f]) * opts[:option_expires_pct_year] end |
#misc_price_vs_rate_vs_expires(opts) ⇒ Object
122 123 124 125 126 |
# File 'lib/greeks/calculations/time_values.rb', line 122 def misc_price_vs_rate_vs_expires(opts) opts.requires_fields(:stock_price, :option_expires_pct_year, :stock_dividend_rate_f) opts[:stock_price] * misc_rate_vs_expires(opts) end |
#misc_rate_vs_expires(opts) ⇒ Object
115 116 117 118 119 |
# File 'lib/greeks/calculations/time_values.rb', line 115 def misc_rate_vs_expires(opts) opts.requires_fields(:option_expires_pct_year, :stock_dividend_rate_f) Math.exp(opts[:option_expires_pct_year] * -opts[:stock_dividend_rate_f]) end |
#misc_strike_vs_fed_vs_expires(opts) ⇒ Object
129 130 131 132 133 |
# File 'lib/greeks/calculations/time_values.rb', line 129 def misc_strike_vs_fed_vs_expires(opts) opts.requires_fields(:option_strike, :option_expires_pct_year, :federal_reserve_interest_rate_f) opts[:option_strike] * Math.exp(opts[:option_expires_pct_year] * -opts[:federal_reserve_interest_rate_f]) end |
#nil_or_gte0(value) ⇒ Object
4 5 6 |
# File 'lib/greeks/calculations/time_values.rb', line 4 def nil_or_gte0(value) value.nil? || value.to_f < 0.0 ? nil : value end |
#normal_distribution(value) ⇒ Object
Moddeled after the Excel NORMSDIST function
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/greeks/calculations/normal_distribution.rb', line 4 def normal_distribution(value) p = 0.2316419 b1 = 0.319381530 b2 = -0.356563782 b3 = 1.781477937 b4 = -1.821255978 b5 = 1.330274429 y = value.abs z = Math.exp(-y*y/2) / Math.sqrt(2 * Math::PI) t = 1 / ( 1 + p * y) cum = 1 - z * (b1*t + b2*t*t + b3*t*t*t + b4*t*t*t*t + b5*t*t*t*t*t) cum = 1 - cum if (value < 0) cum end |
#normal_distribution_gaussian(value) ⇒ Object
Normal distribution function (Gaussian bell curve)
23 24 25 |
# File 'lib/greeks/calculations/normal_distribution.rb', line 23 def normal_distribution_gaussian(value) Math.exp(-0.5 * value * value) / Math.sqrt(2 * Math::PI) end |
#premium_value(opts) ⇒ Object
Intrinsic Value The value that the option would pay if it were executed today. For example, if a stock is trading at $40, a call on that stock with a strike price of $35 would have $5 of intrinsic value ($40-$35) if it were exercised today. However, the call should actually be worth more than $5 to account for the value of the chance of any further appreciation until expiration, and the difference between the price and the intrinsic value would be the time value.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/greeks/calculations/time_values.rb', line 15 def premium_value(opts) opts.requires_fields(:option_type, :option_strike, :stock_price) value = case opts[:option_type] when :call [opts[:stock_price] - opts[:option_strike], 0].max when :put [opts[:option_strike] - opts[:stock_price], 0].max else raise ArgumentError, "Invalid option_type = #{opts[:option_type]}" end nil_or_gte0(value) end |
#rho(opts = {}) ⇒ Object
Rho The change in the value of an option for a change in the prevailing interest rate that matches the duration of the option, all else held equal. Generally rho is not a big driver of price changes for options, as interest rates tend to be relatively stable.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/greeks/calculations/rho.rb', line 6 def rho(opts = {}) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:option_type, :option_expires_pct_year, :strike_vs_fed_vs_expires, :d2_normal_distribution, :iv) multiplier = case opts[:option_type] when :call 1.0 when :put -1.0 else raise "Invalid option_type = #{opts[:option_type].inspect}" end multiplier * opts[:option_expires_pct_year] * opts[:strike_vs_fed_vs_expires] * opts[:d2_normal_distribution] / 100 end |
#theta(opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/greeks/calculations/theta.rb', line 3 def theta(opts = {}) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:stock_dividend_rate_f, :federal_reserve_interest_rate_f, :option_type, :option_expires_pct_year_sqrt, :iv, :strike_vs_fed_vs_expires, :price_vs_rate_vs_expires, :nd1, :d1_normal_distribution, :d2_normal_distribution) part0 = opts[:price_vs_rate_vs_expires] * opts[:nd1] * opts[:iv] part1 = 2 * opts[:option_expires_pct_year_sqrt] part2 = opts[:stock_dividend_rate_f] * opts[:price_vs_rate_vs_expires] * opts[:d1_normal_distribution] part3 = opts[:federal_reserve_interest_rate_f] * opts[:strike_vs_fed_vs_expires] * opts[:d2_normal_distribution] case opts[:option_type] when :call return (-part0 / part1 + part2 - part3) / 365 when :put return (-part0 / part1 - part2 + part3) / 365 else raise "Invalid option_type = #{opts[:option_type].inspect}" end end |
#time_value(opts) ⇒ Object
Time Value The value of an option that captures the chance of further appreciation before expiration. The value of an option can be broken down into intrinsic value, or the value of the option if it were exercised today, and time value, or the added value of the option over and above the intrinsic value. For example, if a stock is trading at $40 and a call with a strike price of $35 were trading for $7, the call would have a $5 intrinsic value ($40-$35) and a $2 time value ($7-$5). Time value will decay by expiration assuming the underlying security stays at the same price.
38 39 40 41 42 43 |
# File 'lib/greeks/calculations/time_values.rb', line 38 def time_value(opts) return nil if opts[:option_price].nil? || opts[:option_price] < 0 return nil if opts[:premium_value].nil? || opts[:premium_value] < 0 nil_or_gte0(opts[:option_price] - opts[:premium_value]) end |
#vega(opts = {}) ⇒ Object
Vega The change in the price of an option for a change in the implied volatility of the option, all else held equal. In general, as the options market thinks it is more difficult to value a stock, implied volatility and therefore the price of the options will increase. For example, if an option is trading for $1, the implied volatility is 20%, and the vega is $0.05, then a one-percentage-point increase in implied volatility to 21% would correspond to an increase in the price of the option to $1.05. In percentage terms, the vega in this case would be ($0.05/$1.00)/(1 percentage point) = 5%.
9 10 11 12 13 14 15 16 |
# File 'lib/greeks/calculations/vega.rb', line 9 def vega(opts = {}) opts.requires_keys_are_present(:iv) return nil if opts[:iv].nil? opts.requires_keys_are_not_nil(:price_vs_rate_vs_expires, :nd1, :option_expires_pct_year_sqrt, :iv) opts[:price_vs_rate_vs_expires] * opts[:option_expires_pct_year_sqrt] * opts[:nd1] / 100 end |