treasury_bond_yield 0.1
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/README.rdoc +50 -0
- data/lib/treasury_bond.rb +44 -0
- metadata +67 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
= Treasury-Bond
|
|
2
|
+
|
|
3
|
+
Treasury-Bond is a Ruby utility to pull US treasury bond yields from http://www.treas.gov website.
|
|
4
|
+
It provides the latest yields for 1 month, 1 year, 5 year, 10 year, 20 year and 30 year treasury bonds.
|
|
5
|
+
|
|
6
|
+
== DEPENDENCIES
|
|
7
|
+
|
|
8
|
+
* Net::HTTP
|
|
9
|
+
* xml-simple
|
|
10
|
+
|
|
11
|
+
== USAGE
|
|
12
|
+
|
|
13
|
+
require 'treasury_bond-yield'
|
|
14
|
+
|
|
15
|
+
To show the 10 year Treasury Bond yield:
|
|
16
|
+
|
|
17
|
+
TreasuryBond.yield[:ten_year]
|
|
18
|
+
|
|
19
|
+
..20 year:
|
|
20
|
+
|
|
21
|
+
TreasuryBond.yield[:twenty_year]
|
|
22
|
+
|
|
23
|
+
To show the date that those fields were applicable from use:
|
|
24
|
+
|
|
25
|
+
TreasuryBond.yield[:date]
|
|
26
|
+
|
|
27
|
+
== LICENSE:
|
|
28
|
+
|
|
29
|
+
(The MIT License)
|
|
30
|
+
|
|
31
|
+
Copyright (c) 2010 Craig Davidson <craig@craigdavidson.co.uk>
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
34
|
+
a copy of this software and associated documentation files (the
|
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
39
|
+
the following conditions:
|
|
40
|
+
|
|
41
|
+
The above copyright notice and this permission notice shall be
|
|
42
|
+
included in all copies or substantial portions of the Software.
|
|
43
|
+
|
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'xmlsimple'
|
|
4
|
+
|
|
5
|
+
class TreasuryBond
|
|
6
|
+
@@t = nil
|
|
7
|
+
attr_accessor :yield_date, :yield
|
|
8
|
+
|
|
9
|
+
def self.yield
|
|
10
|
+
@@t = TreasuryBond.new if @@t == nil
|
|
11
|
+
@@t.yield
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
load_data
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def load_data
|
|
19
|
+
bond_yields = XmlSimple.xml_in(xml)
|
|
20
|
+
weeks = bond_yields["LIST_G_WEEK_OF_MONTH"][0]["G_WEEK_OF_MONTH"]
|
|
21
|
+
latest_week = weeks[weeks.size-1]
|
|
22
|
+
dates = latest_week["LIST_G_NEW_DATE"][0]["G_NEW_DATE"]
|
|
23
|
+
last_day = dates[dates.size-1]
|
|
24
|
+
yield_date = last_day["BID_CURVE_DATE"][0]
|
|
25
|
+
@latest_prices = last_day["LIST_G_BC_CAT"][0]["G_BC_CAT"][0]
|
|
26
|
+
@yield = {
|
|
27
|
+
:date => yield_date,
|
|
28
|
+
:one_month => yield_for("1MONTH"), :one_year => yield_for("1YEAR"),
|
|
29
|
+
:five_year => yield_for("5YEAR"), :ten_year => yield_for("10YEAR"),
|
|
30
|
+
:twenty_year => yield_for("20YEAR"), :thirty_year => yield_for("30YEAR")
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def yield_for duration
|
|
35
|
+
@latest_prices["BC_#{duration}"][0].to_f
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def xml
|
|
39
|
+
Net::HTTP.get_response(URI.parse(url)).body
|
|
40
|
+
end
|
|
41
|
+
def url
|
|
42
|
+
"http://www.treas.gov/offices/domestic-finance/debt-management/interest-rate/yield.xml"
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: treasury_bond_yield
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 9
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: "0.1"
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Craig Davidson
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-05-25 00:00:00 +10:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies: []
|
|
20
|
+
|
|
21
|
+
description: Ruby utility to pull US treasury bond yields from www.treas.gov website.
|
|
22
|
+
email: craig@craigdavidson.co.uk
|
|
23
|
+
executables: []
|
|
24
|
+
|
|
25
|
+
extensions: []
|
|
26
|
+
|
|
27
|
+
extra_rdoc_files: []
|
|
28
|
+
|
|
29
|
+
files:
|
|
30
|
+
- README.rdoc
|
|
31
|
+
- lib/treasury_bond.rb
|
|
32
|
+
has_rdoc: true
|
|
33
|
+
homepage:
|
|
34
|
+
licenses: []
|
|
35
|
+
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
hash: 3
|
|
47
|
+
segments:
|
|
48
|
+
- 0
|
|
49
|
+
version: "0"
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
hash: 3
|
|
56
|
+
segments:
|
|
57
|
+
- 0
|
|
58
|
+
version: "0"
|
|
59
|
+
requirements: []
|
|
60
|
+
|
|
61
|
+
rubyforge_project:
|
|
62
|
+
rubygems_version: 1.3.7
|
|
63
|
+
signing_key:
|
|
64
|
+
specification_version: 3
|
|
65
|
+
summary: Ruby utility to pull US treasury bond yields from www.treas.gov website.
|
|
66
|
+
test_files: []
|
|
67
|
+
|