options_library 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -3,4 +3,8 @@ README.md
3
3
  Rakefile
4
4
  lib/options_library.rb
5
5
  lib/options_library/option_calculator.rb
6
+ lib/options_library/option_call.rb
7
+ lib/options_library/option_model.rb
8
+ lib/options_library/option_put.rb
6
9
  options_library.gemspec
10
+ options_library/options_library.iml
data/README.md CHANGED
@@ -30,6 +30,22 @@ Usage
30
30
  require 'rubygems'
31
31
  require 'options_library'
32
32
 
33
+ call = Option::Call.new
34
+ call.underlying = 95.40 # spot price of the underlying
35
+ call.strike = 90.00 # strike price of option
36
+ call.time = 0.015 # time in years
37
+ call.interest = 0.01 # equates to 1% risk free interest
38
+ call.sigma = 0.4875 # equates to 48.75% volatility
39
+ call.dividend = 0.0 # no annual dividend yield
40
+
41
+ price = call.calc_price # theoretical value of the option
42
+ delta = call.calc_delta # option price sensitivity to a change in underlying price
43
+ gamma = call.calc_gamma # option delta sensitivity to a change in underlying price
44
+ vega = call.calc_vega # option price sensitivity to a change in sigma (volatility)
45
+
46
+ implied_vol = call.calc_implied_vol( 1.80 ) # implied volatility based on the target price
47
+
48
+ # Or go straight at the Calculator methods
33
49
  # Option::Calculator.price_call( underlying, strike, time, interest, sigma, dividend )
34
50
  call_price = Option::Calculator.price_call( 94.5, 90.5, 0.015, 0.01, 0.4875, 0.0 )
35
51
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('options_library', '1.0.2') do |p|
5
+ Echoe.new('options_library', '1.0.3') do |p|
6
6
  p.description = 'A gem used to calc the price of an option.'
7
7
  p.url = 'http://github.com/codertrader/options_library'
8
8
  p.author = 'Dan Tylenda-Emmons'
@@ -3,3 +3,6 @@
3
3
  # Based on Black-Scholes forumla for pricing options
4
4
 
5
5
  require "options_library/option_calculator.rb"
6
+ require "options_library/option_model.rb"
7
+ require "options_library/option_call.rb"
8
+ require "options_library/option_put.rb"
@@ -0,0 +1,13 @@
1
+ # Author Dan Tylenda-Emmons
2
+ # Since Feb 18, 2011
3
+ # Based on Black-Scholes forumla for pricing options
4
+
5
+ module Option
6
+ class Call < Model
7
+
8
+ def initialize
9
+ super(:call)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ # Author Dan Tylenda-Emmons
2
+ # Since Feb 18, 2011
3
+ # Based on Black-Scholes forumla for pricing options
4
+
5
+ module Option
6
+ class Model
7
+
8
+ # The two known option types, Call and Put
9
+ KNOWN_OPTION_TYPES = [:call, :put]
10
+
11
+ # A map to define methods to call based on option_type
12
+ CALC_PRICE_METHODS = { :call=>Calculator.method('price_call'), :put=>Calculator.method('price_put') }
13
+ CALC_DELTA_METHODS = { :call=>Calculator.method('delta_call'), :put=>Calculator.method('delta_put') }
14
+ IMPLIED_VOL_METHODS = { :call=>Calculator.method('implied_vol_call'), :put=>Calculator.method('implied_vol_put') }
15
+
16
+ attr_accessor :underlying, :strike, :time, :interest, :sigma, :dividend, :option_type
17
+
18
+ def initialize(option_type)
19
+ self.option_type = option_type
20
+ self.underlying = 0.0
21
+ self.strike = 0.0
22
+ self.time = 0.0
23
+ self.interest = 0.0
24
+ self.sigma = 0.0
25
+ self.dividend = 0.0
26
+ raise 'Unknown option_type' unless KNOWN_OPTION_TYPES.include?(option_type)
27
+ end
28
+
29
+ def calc_price
30
+ CALC_PRICE_METHODS[option_type].call(underlying, strike, time, interest, sigma, dividend)
31
+ end
32
+
33
+ def calc_delta
34
+ CALC_DELTA_METHODS[option_type].call(underlying, strike, time, interest, sigma, dividend)
35
+ end
36
+
37
+ def calc_gamma
38
+ Calculator.gamma(underlying, strike, time, interest, sigma, dividend)
39
+ end
40
+
41
+ def calc_vega
42
+ Calculator.vega(underlying, strike, time, interest, sigma, dividend)
43
+ end
44
+
45
+ def calc_implied_vol(target_price)
46
+ IMPLIED_VOL_METHODS[option_type].call(underlying, strike, time, interest, target_price, dividend)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ # Author Dan Tylenda-Emmons
2
+ # Since Feb 18, 2011
3
+ # Based on Black-Scholes forumla for pricing options
4
+
5
+ module Option
6
+ class Put < Model
7
+
8
+ def initialize
9
+ super(:put)
10
+ end
11
+
12
+ end
13
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{options_library}
5
- s.version = "1.0.2"
5
+ s.version = "1.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Dan Tylenda-Emmons"]
9
- s.date = %q{2011-02-16}
9
+ s.date = %q{2011-02-17}
10
10
  s.description = %q{A gem used to calc the price of an option.}
11
11
  s.email = %q{jrubyist@gmail.com}
12
- s.extra_rdoc_files = ["README.md", "lib/options_library.rb", "lib/options_library/option_calculator.rb"]
13
- s.files = ["Manifest", "README.md", "Rakefile", "lib/options_library.rb", "lib/options_library/option_calculator.rb", "options_library.gemspec"]
12
+ s.extra_rdoc_files = ["README.md", "lib/options_library.rb", "lib/options_library/option_calculator.rb", "lib/options_library/option_call.rb", "lib/options_library/option_model.rb", "lib/options_library/option_put.rb"]
13
+ s.files = ["Manifest", "README.md", "Rakefile", "lib/options_library.rb", "lib/options_library/option_calculator.rb", "lib/options_library/option_call.rb", "lib/options_library/option_model.rb", "lib/options_library/option_put.rb", "options_library.gemspec", "options_library/options_library.iml"]
14
14
  s.homepage = %q{http://github.com/codertrader/options_library}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Options_library", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$/.." />
6
+ <orderEntry type="jdk" jdkName="JRuby SDK 1.6.0.RC1" jdkType="JRUBY_SDK" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
10
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: options_library
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Tylenda-Emmons
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-16 00:00:00 -06:00
13
+ date: 2011-02-17 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -24,13 +24,20 @@ extra_rdoc_files:
24
24
  - README.md
25
25
  - lib/options_library.rb
26
26
  - lib/options_library/option_calculator.rb
27
+ - lib/options_library/option_call.rb
28
+ - lib/options_library/option_model.rb
29
+ - lib/options_library/option_put.rb
27
30
  files:
28
31
  - Manifest
29
32
  - README.md
30
33
  - Rakefile
31
34
  - lib/options_library.rb
32
35
  - lib/options_library/option_calculator.rb
36
+ - lib/options_library/option_call.rb
37
+ - lib/options_library/option_model.rb
38
+ - lib/options_library/option_put.rb
33
39
  - options_library.gemspec
40
+ - options_library/options_library.iml
34
41
  has_rdoc: true
35
42
  homepage: http://github.com/codertrader/options_library
36
43
  licenses: []