greeks 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad37eae3c2ce021e59725e537dc1b77d8ee2eab
4
- data.tar.gz: 555eb9d63d90e5765dada93c6c28d402c6c48298
3
+ metadata.gz: 6ce6ee63e7be1cf00d2a33bf5fabc7384edbd151
4
+ data.tar.gz: 319eddb79151564febe9384bb402057f78e3c4d6
5
5
  SHA512:
6
- metadata.gz: 826582e8578e102704518e97a18c4d0d54e3e4bc3dd0f3d53981557b4499c657692d55cc736076623e05082f33be01c7f9e6955e9a5880fe9bd5c876b5ad8d4f
7
- data.tar.gz: 7b172c97033ffacc91d37a6d60b934dd6b9e41a33d61285daa4893e2a4f57c881aa09d2092480f69a04ca8e9909965450195b3c709d58a3683ac607eae975d60
6
+ metadata.gz: cc93e88a7ef6f8096a0c18c003faf6005ee46f11e7eb7d77b0539b367c8fecb99266a315896d18b0ab866860f471cfd8073ef0de9167f1a64ae6829b092aaa64
7
+ data.tar.gz: 359124006d77696012957a0c4633632ef62ab1dd67c64041b67d41fb93b6e481f2bedeb15cd370e11ff1ec5991f5a2fd2417c6029f66eed7fa788ebb1ecfcef3
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "greeks"
5
- gem.version = '1.1'
5
+ gem.version = '1.2'
6
6
  gem.authors = ["Glenn Nagel"]
7
7
  gem.email = ["glenn@mercury-wireless.com"]
8
8
  gem.homepage = "https://github.com/gnagel/greeks"
@@ -289,7 +289,6 @@ module Math
289
289
  :option_type => option_type,
290
290
  :option_strike => option_strike,
291
291
  :option_price => option_price,
292
- :break_even => (NilMath.new(break_even) * 100.0).to_f, # break_even * 100
293
292
  :iv => (NilMath.new(iv) * 100.0).to_f, # iv * 100
294
293
  :delta => (NilMath.new(delta) * stock_price / option_price).to_f, # delta * stock_price / option_price
295
294
  :gamma => (NilMath.new(gamma) * stock_price / delta).to_f, # gamma * stock_price / delta
@@ -297,6 +296,7 @@ module Math
297
296
  :rho => (NilMath.new(rho) * 100.0 / option_price).to_f, # rho * 100 / option_price
298
297
  :theta => (NilMath.new(theta) * 100.0 / option_price).to_f, # theta * 100 / option_price
299
298
  :deta_vs_theta => nil,
299
+ :break_even => (NilMath.new(break_even) * 100.0).to_f, # break_even * 100
300
300
  }
301
301
 
302
302
  # Delta/Theta
@@ -81,11 +81,12 @@ module Math
81
81
  # If you believe the Chance of Breakeven is less than the probability that a stock will be beyond the
82
82
  # breakeven price at option expiration, then you believe the option is undervalued, and visa versa.
83
83
  def break_even(opts)
84
- opts.requires_fields(: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)
85
-
84
+ opts.requires_keys_are_present(:option_price, :iv)
86
85
  return nil if opts[:option_price].nil?
87
86
  return nil if opts[:option_price] < 0
88
87
  return nil if opts[:iv].nil?
88
+
89
+ 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)
89
90
 
90
91
  part1 = (opts[:federal_reserve_interest_rate_f] - opts[:stock_dividend_rate_f] - opts[:iv] * opts[:iv] / 2) * opts[:option_expires_pct_year]
91
92
  part2 = opts[:iv] * opts[:option_expires_pct_year_sqrt]
@@ -135,35 +136,39 @@ module Math
135
136
 
136
137
 
137
138
  def misc_nd1(opts)
138
- opts.requires_fields(:d1)
139
-
139
+ opts.requires_keys_are_present(:d1)
140
140
  return nil if opts[:d1].nil?
141
141
 
142
+ opts.requires_keys_are_not_nil(:d1)
143
+
142
144
  Math.exp(-0.5 * opts[:d1] * opts[:d1]) / Math.sqrt(2 * Math::PI)
143
145
  end
144
146
 
145
147
 
146
148
  def misc_d1(opts)
147
- opts.requires_fields(:price_ratio_log_less_rates, :iv, :option_expires_pct_year, :option_expires_pct_year_sqrt)
148
-
149
+ opts.requires_keys_are_present(:iv)
149
150
  return nil if opts[:iv].nil?
151
+
152
+ opts.requires_keys_are_not_nil(:price_ratio_log_less_rates, :iv, :option_expires_pct_year, :option_expires_pct_year_sqrt)
150
153
 
151
154
  (opts[:price_ratio_log_less_rates] + opts[:iv] * opts[:iv] * opts[:option_expires_pct_year] / 2) / (opts[:iv] * opts[:option_expires_pct_year_sqrt])
152
155
  end
153
156
 
154
157
 
155
158
  def misc_d2(opts)
156
- opts.requires_fields(:d1, :iv, :option_expires_pct_year_sqrt)
157
-
159
+ opts.requires_keys_are_present(:iv)
158
160
  return nil if opts[:iv].nil?
161
+
162
+ opts.requires_keys_are_not_nil(:d1, :iv, :option_expires_pct_year_sqrt)
159
163
 
160
164
  opts[:d1] - opts[:iv] * opts[:option_expires_pct_year_sqrt]
161
165
  end
162
166
 
163
167
  def misc_d_normal_distribution(opts)
164
- opts.requires_fields(:option_type, :d_value)
165
-
168
+ opts.requires_keys_are_present(:d_value)
166
169
  return nil if opts[:d_value].nil?
170
+
171
+ opts.requires_keys_are_not_nil(:option_type, :d_value)
167
172
 
168
173
  multiplier = case opts[:option_type]
169
174
  when :call
@@ -28,6 +28,10 @@ describe "Math::GreekCalculations::iv" do
28
28
  :price_ratio_log_less_rates => 1.0,
29
29
  ).should === 21453795590575736000000.0
30
30
  }
31
+
32
+ it {
33
+ iv(:stock_price=>1558.86, :stock_dividend_rate_f=>0.0, :federal_reserve_interest_rate_f=>0.0, :option_type=>:put, :option_price=>0.0, :option_strike=>800.0, :option_expires_pct_year=>0.00821917808219178, :option_expires_pct_year_sqrt=>0.09065968278232492, :iv=>nil).should be_nil
34
+ }
31
35
 
32
36
  it {
33
37
  iv(
@@ -107,4 +107,10 @@ describe Math::Greeks::Calculator do
107
107
  it { calc.to_hash[:rho].should === put[:rho] }
108
108
  it { calc.to_hash[:break_even].round(2).should === put[:break_even] }
109
109
  end
110
+
111
+ it {
112
+ calculator = Math::Greeks::Calculator.new(:stock_price=>1558.86, :stock_dividend_rate=>0.0, :federal_reserve_interest_rate=>0.0, :option_type=>:call, :option_price=>751.50, :option_strike=>800.00, :option_expires_in_days=>2)
113
+ calculator.iv.should be_nil
114
+ calculator.to_hash[:iv].should be_nil
115
+ }
110
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greeks
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Nagel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-20 00:00:00.000000000 Z
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: require_all