rupee 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest CHANGED
@@ -1,4 +1,2 @@
1
- begin
2
- require "test_notifier/runner/autotest"
3
- rescue LoadError
4
- end
1
+ require "autotest/fsevent"
2
+ require "autotest/growl"
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.log
3
3
  .bundle
4
4
  .DS_Store
5
+ .rbx
5
6
  .yardoc
6
7
  Gemfile.lock
7
8
  doc
@@ -110,7 +110,13 @@ bond_ytm(times, cflows, price, len, discrete)
110
110
  return r;
111
111
  };
112
112
 
113
- // Ruby singleton functions
113
+ /*
114
+ * Ruby singleton functions
115
+ *
116
+ * See helper functions below for description broken out by discrete and
117
+ * continuous compounding. +discrete+ is a boolean equal to +true+ for discrete
118
+ * compounding and +false+ for continuous compounding
119
+ */
114
120
 
115
121
  static VALUE
116
122
  convexity(self, _times, _cflows, _r, discrete)
@@ -174,9 +180,28 @@ price(self, _times, _cflows, _r, discrete)
174
180
  return rb_float_new(bond_price(times, cflows, r, len, discrete));
175
181
  }
176
182
 
183
+ static VALUE
184
+ yield_to_maturity(self, _times, _cflows, _price, discrete)
185
+ VALUE self, _times, _cflows, _price;
186
+ bool discrete;
187
+ {
188
+ int len = RARRAY_LEN(_cflows);
189
+ double times[len], cflows[len], price;
190
+
191
+ rtofa(times, _times, len);
192
+ rtofa(cflows, _cflows, len);
193
+ price = NUM2DBL(_price);
194
+
195
+ return rb_float_new(bond_ytm(times, cflows, price, len, discrete));
196
+ };
197
+
177
198
  // Helper functions
178
199
 
179
- // Convexity of a continuously compounded bond
200
+ /* call-seq: convexity_continuous(times, cflows, rates)
201
+ *
202
+ * The bond's convexity based on the provided set of times (in years), cash
203
+ * flows and discount rates, assuming continuous compounding
204
+ */
180
205
  static VALUE
181
206
  convexity_continuous(self, _times, _cflows, _r)
182
207
  VALUE self, _times, _cflows, _r;
@@ -184,7 +209,11 @@ convexity_continuous(self, _times, _cflows, _r)
184
209
  return convexity(self, _times, _cflows, _r, false);
185
210
  }
186
211
 
187
- // Convexity of a discretely compounded bond
212
+ /* call-seq: convexity_discrete(times, cflows, rates)
213
+ *
214
+ * The bond's convexity based on the provided set of times (in years), cash
215
+ * flows and discount rates, assuming discrete compounding
216
+ */
188
217
  static VALUE
189
218
  convexity_discrete(self, _times, _cflows, _r)
190
219
  VALUE self, _times, _cflows, _r;
@@ -192,7 +221,11 @@ convexity_discrete(self, _times, _cflows, _r)
192
221
  return convexity(self, _times, _cflows, _r, true);
193
222
  }
194
223
 
195
- // Duration of a continuously compounded bond
224
+ /* call-seq: duration_continuous(times, cflows, rates)
225
+ *
226
+ * The bond's duration based on the provided set of times (in years), cash
227
+ * flows and discount rates, assuming continuous compounding
228
+ */
196
229
  static VALUE
197
230
  duration_continuous(self, _times, _cflows, _r)
198
231
  VALUE self, _times, _cflows, _r;
@@ -200,7 +233,11 @@ duration_continuous(self, _times, _cflows, _r)
200
233
  return duration(self, _times, _cflows, _r, false);
201
234
  }
202
235
 
203
- // Duration of a discretely compounded bond
236
+ /* call-seq: duration_discrete(times, cflows, rates)
237
+ *
238
+ * The bond's duration based on the provided set of times (in years), cash
239
+ * flows and discount rates, assuming discrete compounding
240
+ */
204
241
  static VALUE
205
242
  duration_discrete(self, _times, _cflows, _r)
206
243
  VALUE self, _times, _cflows, _r;
@@ -208,7 +245,11 @@ duration_discrete(self, _times, _cflows, _r)
208
245
  return duration(self, _times, _cflows, _r, true);
209
246
  }
210
247
 
211
- // Macaulay duration of a continuously compounded bond
248
+ /* call-seq: macaulay_continuous(times, cflows, price)
249
+ *
250
+ * The bond's Macaulay duration based on the provided set of times (in years),
251
+ * cash flows and price, assuming continuous compounding
252
+ */
212
253
  static VALUE
213
254
  macaulay_continuous(self, _times, _cflows, _price)
214
255
  VALUE self, _times, _cflows, _price;
@@ -216,7 +257,11 @@ macaulay_continuous(self, _times, _cflows, _price)
216
257
  return macaulay(self, _times, _cflows, _price, false);
217
258
  }
218
259
 
219
- // Macaulay duration of a discretely compounded bond
260
+ /* call-seq: macaulay_discrete(times, cflows, price)
261
+ *
262
+ * The bond's Macaulay duration based on the provided set of times (in years),
263
+ * cash flows and price, assuming discrete compounding
264
+ */
220
265
  static VALUE
221
266
  macaulay_discrete(self, _times, _cflows, _price)
222
267
  VALUE self, _times, _cflows, _price;
@@ -224,7 +269,11 @@ macaulay_discrete(self, _times, _cflows, _price)
224
269
  return macaulay(self, _times, _cflows, _price, true);
225
270
  }
226
271
 
227
- // Modified duration of a discretely compounded bond
272
+ /* call-seq: modified_discrete(times, cflows, price)
273
+ *
274
+ * The bond's duration based on the provided set of times (in years), cash
275
+ * flows and price, assuming discrete compounding
276
+ */
228
277
  static VALUE
229
278
  modified_discrete(self, _times, _cflows, _price)
230
279
  VALUE self, _times, _cflows, _price;
@@ -242,7 +291,11 @@ modified_discrete(self, _times, _cflows, _price)
242
291
  return rb_float_new(D / (1 + y));
243
292
  };
244
293
 
245
- // Price of a continuously compounded bond
294
+ /* call-seq: price_continuous(times, cflows, rates)
295
+ *
296
+ * The bond's price based on the provided set of times (in years), cash flows
297
+ * and discount rates, assuming continuous compounding
298
+ */
246
299
  static VALUE
247
300
  price_continuous(self, _times, _cflows, _r)
248
301
  VALUE self, _times, _cflows, _r;
@@ -250,7 +303,11 @@ price_continuous(self, _times, _cflows, _r)
250
303
  return price(self, _times, _cflows, _r, false);
251
304
  }
252
305
 
253
- // Price of a discretely compounded bond
306
+ /* call-seq: price_discrete(times, cflows, rates)
307
+ *
308
+ * The bond's price based on the provided set of times (in years), cash flows
309
+ * and discount rates, assuming discrete compounding
310
+ */
254
311
  static VALUE
255
312
  price_discrete(self, _times, _cflows, _r)
256
313
  VALUE self, _times, _cflows, _r;
@@ -258,22 +315,12 @@ price_discrete(self, _times, _cflows, _r)
258
315
  return price(self, _times, _cflows, _r, true);
259
316
  }
260
317
 
261
- static VALUE
262
- yield_to_maturity(self, _times, _cflows, _price, discrete)
263
- VALUE self, _times, _cflows, _price;
264
- bool discrete;
265
- {
266
- int len = RARRAY_LEN(_cflows);
267
- double times[len], cflows[len], price;
268
-
269
- rtofa(times, _times, len);
270
- rtofa(cflows, _cflows, len);
271
- price = NUM2DBL(_price);
272
-
273
- return rb_float_new(bond_ytm(times, cflows, price, len, discrete));
274
- };
275
318
 
276
- // Yield to maturity of a continuously compounded bond
319
+ /* call-seq: yield_to_maturity_continuous(times, cflows, rates)
320
+ *
321
+ * The bond's yield to maturity based on the provided set of times (in years),
322
+ * cash flows and price, assuming continuous compounding
323
+ */
277
324
  static VALUE
278
325
  yield_to_maturity_continuous(self, _times, _cflows, _price)
279
326
  VALUE self, _times, _cflows, _price;
@@ -281,7 +328,11 @@ yield_to_maturity_continuous(self, _times, _cflows, _price)
281
328
  return yield_to_maturity(self, _times, _cflows, _price, false);
282
329
  }
283
330
 
284
- // Yield to maturity of a discretely compounded bond
331
+ /* call-seq: yield_to_maturity_discrete(times, cflows, rates)
332
+ *
333
+ * The bond's yield to maturity based on the provided set of times (in years),
334
+ * cash flows and price, assuming discrete compounding
335
+ */
285
336
  static VALUE
286
337
  yield_to_maturity_discrete(self, _times, _cflows, _price)
287
338
  VALUE self, _times, _cflows, _price;
@@ -7,6 +7,11 @@ future_price(S, r, ttm)
7
7
  return S * exp(r * ttm);
8
8
  }
9
9
 
10
+ /* call-seq: price(underlying, rate, time_to_maturity)
11
+ *
12
+ * The future's price based on the provided underlying, risk-free rate and time
13
+ * to maturity
14
+ */
10
15
  static VALUE
11
16
  price(self, _S, _r, _ttm)
12
17
  VALUE self, _S, _r, _ttm;
@@ -22,14 +22,15 @@ module Rupee
22
22
  autoload :Benchmark, "rupee/benchmark"
23
23
  autoload :BusinessDay, "rupee/business_day"
24
24
  autoload :Calendar, "rupee/calendar"
25
- autoload :FixedIncome, "rupee/fixed_income"
26
25
  autoload :Call, "rupee/option"
26
+ autoload :Curve, "rupee/curve"
27
+ autoload :FixedIncome, "rupee/fixed_income"
27
28
  autoload :Currency, "rupee/currency"
28
29
  autoload :DayCount, "rupee/day_count"
29
30
  autoload :Frequency, "rupee/frequency"
30
31
  autoload :Option, "rupee/option"
31
32
  autoload :Put, "rupee/option"
32
33
  autoload :Quote, "rupee/quote"
34
+ autoload :Rate, "rupee/rate"
33
35
  autoload :Source, "rupee/source"
34
- autoload :YieldCurve, "rupee/yield_curve"
35
36
  end
@@ -0,0 +1,27 @@
1
+ module Rupee
2
+ # A class representing a yield or basis curve
3
+ class Curve
4
+ include FindInstance
5
+
6
+ autoload :LIBOR_3M, "rupee/curve/libor_3m"
7
+
8
+ # The curve's currency
9
+ attr :currency
10
+ # A description for the curve
11
+ attr :description
12
+ # The interpolation method
13
+ attr :interpolation
14
+
15
+ # Create a new curve
16
+ def initialize(description = "", opts = {})
17
+ opts = {
18
+ :currency => :usd,
19
+ :interpolation => :cubic_spline
20
+ }.merge opts
21
+
22
+ @description = description
23
+ @currency = opts[:currency]
24
+ @interpolation = opts[:interpolation]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Rupee
2
+ class Curve
3
+ LIBOR_3M = Curve.new("3-month LIBOR")
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Rupee
2
+ # A class representing a rate
3
+ class Rate
4
+ # Create a new rate
5
+ def initialize(opts = {})
6
+
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
1
  module Rupee
2
2
  # The current version
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.8"
4
4
  end
@@ -27,4 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency "bundler", "~> 1.0"
28
28
  s.add_development_dependency "rspec", "~> 2.0"
29
29
  s.add_development_dependency "sdoc", "~> 0.3"
30
+ s.add_development_dependency "autotest"
31
+ s.add_development_dependency "autotest-fsevent"
32
+ s.add_development_dependency "autotest-growl"
30
33
  end
@@ -42,8 +42,9 @@ describe Statistics do
42
42
  end
43
43
 
44
44
  it "should return an accurate correlation" do
45
- Statistics.correlation(@values, @more_values).should == 0.95
46
- Statistics.corr(@values, @more_values).should == 0.95
47
- Statistics.correl(@values, @more_values).should == 0.95
45
+ @result = Statistics.correlation(@values, @more_values)
46
+ @result.should be_within(@tolerance).of 0.95
47
+ Statistics.corr(@values, @more_values).should == @result
48
+ Statistics.correl(@values, @more_values).should == @result
48
49
  end
49
50
  end
@@ -6,16 +6,18 @@ CURRENT=`rvm current`
6
6
 
7
7
  # Prints the name of the Ruby, sets it to use under RVM, installs, tests
8
8
  function test_ruby {
9
- echo -e "\n\033[1m$1\033[0m"
9
+ echo -e "\n\033[1m$2\033[0m"
10
10
  rvm use $1
11
11
  rake install
12
12
  rspec spec
13
13
  }
14
14
 
15
15
  # Run tests on these versions
16
- test_ruby 1.8.7
17
- test_ruby 1.9.2
18
- test_ruby 1.9.3
16
+ test_ruby 1.8.7 "Ruby 1.8.7 (MRI)"
17
+ test_ruby 1.9.2 "Ruby 1.9.2 (MRI)"
18
+ test_ruby 1.9.3 "Ruby 1.9.3 (MRI)"
19
+ test_ruby jruby JRuby
20
+ test_ruby rbx Rubinius
19
21
 
20
22
  # Restore original Ruby in use
21
23
  rvm use $CURRENT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rupee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000 Z
12
+ date: 2011-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &74290000 !ruby/object:Gem::Requirement
16
+ requirement: &70214885187220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *74290000
24
+ version_requirements: *70214885187220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &74289630 !ruby/object:Gem::Requirement
27
+ requirement: &70214885201400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *74289630
35
+ version_requirements: *70214885201400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sdoc
38
- requirement: &74289230 !ruby/object:Gem::Requirement
38
+ requirement: &70214885198020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,40 @@ dependencies:
43
43
  version: '0.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *74289230
46
+ version_requirements: *70214885198020
47
+ - !ruby/object:Gem::Dependency
48
+ name: autotest
49
+ requirement: &70214885197200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70214885197200
58
+ - !ruby/object:Gem::Dependency
59
+ name: autotest-fsevent
60
+ requirement: &70214885196560 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70214885196560
69
+ - !ruby/object:Gem::Dependency
70
+ name: autotest-growl
71
+ requirement: &70214885195960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70214885195960
47
80
  description: ! " rupee aims to provide user-friendly tools for
48
81
  use in\n financial gems and applications.\n"
49
82
  email:
@@ -83,6 +116,8 @@ files:
83
116
  - lib/rupee/currency/gbp.rb
84
117
  - lib/rupee/currency/jpy.rb
85
118
  - lib/rupee/currency/usd.rb
119
+ - lib/rupee/curve.rb
120
+ - lib/rupee/curve/libor_3m.rb
86
121
  - lib/rupee/day_count.rb
87
122
  - lib/rupee/day_count/30_360.rb
88
123
  - lib/rupee/day_count/30e+_360.rb
@@ -96,13 +131,13 @@ files:
96
131
  - lib/rupee/mixins/find_instance.rb
97
132
  - lib/rupee/option.rb
98
133
  - lib/rupee/quote.rb
134
+ - lib/rupee/rate.rb
99
135
  - lib/rupee/security.rb
100
136
  - lib/rupee/source.rb
101
137
  - lib/rupee/source/bloomberg.rb
102
138
  - lib/rupee/source/google.rb
103
139
  - lib/rupee/source/yahoo.rb
104
140
  - lib/rupee/version.rb
105
- - lib/rupee/yield_curve.rb
106
141
  - rupee.gemspec
107
142
  - spec/native/bond_spec.rb
108
143
  - spec/native/future_spec.rb
@@ -1,14 +0,0 @@
1
- module Rupee
2
- class YieldCurve
3
- include FindInstance
4
-
5
- def initialize(description = "", opts = {})
6
- opts = {
7
- :currency => :usd,
8
- :interpolation => :cubic_spline
9
- }.merge opts
10
-
11
- @description = description
12
- end
13
- end
14
- end