options_library 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +4 -0
- data/README.md +16 -0
- data/Rakefile +1 -1
- data/lib/options_library.rb +3 -0
- data/lib/options_library/option_call.rb +13 -0
- data/lib/options_library/option_model.rb +50 -0
- data/lib/options_library/option_put.rb +13 -0
- data/options_library.gemspec +4 -4
- data/options_library/options_library.iml +10 -0
- metadata +9 -2
data/Manifest
CHANGED
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.
|
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'
|
data/lib/options_library.rb
CHANGED
@@ -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
|
data/options_library.gemspec
CHANGED
@@ -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.
|
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-
|
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.
|
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-
|
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: []
|