From 2a3129389914e7fb79e70ddebda6ab7c15ef8e35 Mon Sep 17 00:00:00 2001 From: mrozel Date: Tue, 8 Mar 2016 21:00:52 -0600 Subject: [PATCH 1/2] Changed from Option to OptionLib to keep from interfering with the Option Model --- lib/options_library/option_calculator.rb | 2 +- lib/options_library/option_call.rb | 2 +- lib/options_library/option_model.rb | 2 +- lib/options_library/option_put.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/options_library/option_calculator.rb b/lib/options_library/option_calculator.rb index 6c3c07e..6b1f8a4 100644 --- a/lib/options_library/option_calculator.rb +++ b/lib/options_library/option_calculator.rb @@ -2,7 +2,7 @@ # Since Feb 13, 2011 # Based on Black-Scholes forumla for pricing options -module Option +module OptionLib class Calculator class << self # used for finding implied vol based on a market (target) price diff --git a/lib/options_library/option_call.rb b/lib/options_library/option_call.rb index c0bb4b4..309a9ff 100644 --- a/lib/options_library/option_call.rb +++ b/lib/options_library/option_call.rb @@ -2,7 +2,7 @@ # Since Feb 18, 2011 # Based on Black-Scholes forumla for pricing options -module Option +module OptionLib class Call < Model def initialize diff --git a/lib/options_library/option_model.rb b/lib/options_library/option_model.rb index 0b6ade1..4fa55cc 100644 --- a/lib/options_library/option_model.rb +++ b/lib/options_library/option_model.rb @@ -2,7 +2,7 @@ # Since Feb 18, 2011 # Based on Black-Scholes forumla for pricing options -module Option +module OptionLib class Model # The two known option types, Call and Put diff --git a/lib/options_library/option_put.rb b/lib/options_library/option_put.rb index bc3cba3..f620adc 100644 --- a/lib/options_library/option_put.rb +++ b/lib/options_library/option_put.rb @@ -2,7 +2,7 @@ # Since Feb 18, 2011 # Based on Black-Scholes forumla for pricing options -module Option +module OptionLib class Put < Model def initialize From 78ffa72f97ef2b2fcbce6b3b9099d48452eccb57 Mon Sep 17 00:00:00 2001 From: mrosel Date: Wed, 27 Apr 2016 23:35:28 -0500 Subject: [PATCH 2/2] fixed infinite loop if strike=underlying and time is zero --- lib/options_library/option_calculator.rb | 2 ++ options_library.gemspec | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/options_library/option_calculator.rb b/lib/options_library/option_calculator.rb index 6b1f8a4..b7f967f 100644 --- a/lib/options_library/option_calculator.rb +++ b/lib/options_library/option_calculator.rb @@ -49,6 +49,7 @@ def vega( underlying, strike, time, interest, sigma, dividend ) # computes the fair value of the call based on the knowns and assumed volatility (sigma) def price_call( underlying, strike, time, interest, sigma, dividend ) + return 0 if underlying== strike && time <= 0.00000 d1 = d_one( underlying, strike, time, interest, sigma, dividend ) discounted_underlying = exp(-1.0 * dividend * time) * underlying probability_weighted_value_of_being_exercised = discounted_underlying * norm_sdist( d1 ) @@ -62,6 +63,7 @@ def price_call( underlying, strike, time, interest, sigma, dividend ) # computes the fair value of the put based on the knowns and assumed volatility (sigma) def price_put( underlying, strike, time, interest, sigma, dividend ) + return 0 if underlying== strike && time <= 0.00000 d2 = d_two( underlying, strike, time, interest, sigma, dividend ) discounted_strike = strike * exp(-1.0 * interest * time) probabiltity_weighted_value_of_discounted_strike = discounted_strike * norm_sdist( -1.0 * d2 ) diff --git a/options_library.gemspec b/options_library.gemspec index c1a989e..de24d0f 100644 --- a/options_library.gemspec +++ b/options_library.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = %q{options_library} - s.version = "1.0.3" + s.version = "1.0.32" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Dan Tylenda-Emmons"]