stock_index 0.5.1 → 0.6.0

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: 8e6777026b7003122d7f84f12773bee96fe7a071
4
- data.tar.gz: e8733b6a09574b44fe59cfc1e4e34485152679ab
3
+ metadata.gz: 0c587529847bd7aec40fb68c34143c97da5bc63b
4
+ data.tar.gz: 391c669017f278afacda495baf32cd4c61d37603
5
5
  SHA512:
6
- metadata.gz: 771b231cabaea517c04ff4df5bfd45c09ce0be016d8bc12685513e042fd128e5c4d631c416d6e8faef8bc70b09bf3fd7f2028ee3f3baedd92b0e8020a5f09e74
7
- data.tar.gz: eeaeece0e07c5f074950a3cfaf317bb645769eda7f7e9e71777202ec91752336400f3cf709b659da15da60f229c190c23806f6850ec7ee5db7b32d6e47991a55
6
+ metadata.gz: 397bc3ba4835c9302f76917d877dfa9217e949f5e178a594cdd3b3a81deb24d6198533214de25cf75a88315071f63de39e183053728544a6e2cda4e82e7da7f4
7
+ data.tar.gz: 74b3386e6fe3d2815fffad3a7df947140bba9826f39ceea7a4fdd511143cb4646609115b81ab9e2a7da098fe87b9e09532a6a36e2040fe0c24477d0d36a44a2b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -25,7 +25,7 @@ There is no a standard for indices symbols, so this gem uses Yahoo Finance symbo
25
25
  | ------ | ---------- | -------------- |
26
26
  | ^DJI | DOW JONES INDUSTRIAL AVERAGE | http://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average |
27
27
  | ^GSPC | S&P 500 | http://en.wikipedia.org/wiki/List_of_S%26P_500_companies |
28
- | ^NDX | NASDAQ 100 | https://indexes.nasdaqomx.com/Index/Weighting/NDX |
28
+ | ^NDX | NASDAQ 100 | http://en.wikipedia.org/wiki/NASDAQ-100 |
29
29
  | ^N225 | NIKKEI 225 | http://indexes.nikkei.co.jp/en/nkave/index/component?idx=nk225 |
30
30
  | ^STOXX50E | EURO STOXX 50 | http://www.stoxx.com/indices/index_information.html?symbol=SX5E |
31
31
  | ^FTSE | FTSE 100 | http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/indices/summary/summary-indices-constituents.html?index=UKX |
@@ -19179,7 +19179,6 @@ HCP,HCP INC,BBG000BKYDP9
19179
19179
  HCN,HEALTH CARE REIT INC,BBG000BKY1G5
19180
19180
  HR,HEALTHCARE REALTY TRUST INC,BBG000BB67F4
19181
19181
  HTA,HEALTHCARE TRUST OF AME-CL A,BBG000PRJCX9
19182
- HREIF,HEALTHLEASE PROPERTIES REAL,BBG0035WSDV4
19183
19182
  HEKRF,HEKTAR REAL ESTATE INVESTMEN,BBG0024571R0
19184
19183
  HT,HERSHA HOSPITALITY TRUST,BBG000BBB8Y5
19185
19184
  HIBRF,HIBERNIA REIT PLC,BBG005ZL7XD9
@@ -19250,6 +19249,7 @@ MAA,MID-AMERICA APARTMENT COMM,BBG000BLMY92
19250
19249
  MSTUF,MILESTONE APARTMENTS REAL ES,BBG00497LRF7
19251
19250
  MRVGF,MIRVAC GROUP,BBG000DS0379
19252
19251
  MNR,MONMOUTH REAL ESTATE INV COR,BBG000BLZD12
19252
+ MORE/WD,MONOGRAM RESIDENTIAL TRST-WD,BBG007MKM787
19253
19253
  MORE,MONOGRAM RESIDENTIAL TRUST I,BBG002PWM5J1
19254
19254
  MNARF,MORGUARD NORTH AMERICAN RESI,BBG004T5DWX7
19255
19255
  MGRUF,MORGUARD REAL ESTATE-TR UTS,BBG000G1JPT2
data/cache/data.pstore CHANGED
Binary file
@@ -5,12 +5,20 @@ class StockIndex
5
5
  require 'csv'
6
6
 
7
7
  FILES = {
8
- us: 'csv/US.csv'
8
+ us: 'bsym/US.csv'
9
+ }
10
+
11
+ EXCEPTIONS = {
12
+ 'BIDU' => {name: 'BAIDU INC', bbgid: 'BBG000QXWHD1'},
13
+ 'LVNTA' => {name: 'LIBERTY VENTURES', bbgid: 'BBG0038K9G41'},
14
+ 'VIP' => {name: 'VIMPELCOM LTD', bbgid: 'BBG000QCW561'},
15
+ 'VOD' => {name: 'VODAFONE GROUP PLC', bbgid: 'BBG000C4R6H6'}
9
16
  }
10
17
 
11
18
  class << self
12
19
 
13
20
  def find(symbol, pricing_source = :us)
21
+ return {name: EXCEPTIONS[symbol][:name], bbgid: EXCEPTIONS[symbol][:bbgid]} if EXCEPTIONS.keys.include? symbol
14
22
  CSV.foreach(FILES[pricing_source]) do |row|
15
23
  return {name: row[1], bbgid: row[2]} if row[0] == symbol
16
24
  end
@@ -32,23 +32,18 @@ class StockIndex
32
32
  end
33
33
 
34
34
  def attributes_lookup
35
- puts "--> #{@symbol}"
36
35
  bsym = StockIndex::BsymSearch.find(@symbol)
37
- edgar = Cik.lookup(parse_symbol(@symbol))
38
- a = {market: @market, symbol: @symbol, name: bsym[:name], wikipedia: @wikipedia, cik: edgar[:cik], bbgid: bsym[:bbgid]}
39
- cache_write(a)
40
- end
41
-
42
- def parse_symbol(symbol)
43
- case symbol
44
- # BRK/B => 0001067983 Berkshire Hathaway Inc
45
- # BF/B => 0000014693 Brown-Forman Corp
46
- when 'BRK/B'
47
- '0001067983'
48
- when 'BF/B'
49
- '0000014693'
36
+ if bsym.nil?
37
+ puts "bsym --> #{@symbol}"
38
+ return
39
+ else
40
+ edgar = Cik.lookup(SymbolParser.new(@symbol).bsym_to_cik)
41
+ if edgar.nil?
42
+ puts "cik --> #{@symbol}"
50
43
  else
51
- symbol
44
+ a = {market: @market, symbol: @symbol, name: bsym[:name], wikipedia: @wikipedia, cik: edgar[:cik], bbgid: bsym[:bbgid]}
45
+ cache_write(a)
46
+ end
52
47
  end
53
48
  end
54
49
 
@@ -10,7 +10,7 @@ class StockIndex
10
10
  },
11
11
  '^NDX' => {
12
12
  name: 'NASDAQ 100',
13
- url: 'https://indexes.nasdaqomx.com/Index/Weighting/NDX'
13
+ url: 'http://en.wikipedia.org/wiki/NASDAQ-100'
14
14
  },
15
15
  '^N225' => {
16
16
  name: 'NIKKEI 225',
@@ -10,7 +10,7 @@ class SP500Scraper < StockIndex::BaseScraper
10
10
  def symbol(tr)
11
11
  symbol_td = td(tr, 0)
12
12
  s = symbol_td ? symbol_td.css('a').first.text : nil
13
- parse_symbol(s)
13
+ SymbolParser.new(s).sp500_to_bsym
14
14
  end
15
15
 
16
16
  def market(tr)
@@ -19,7 +19,7 @@ class SP500Scraper < StockIndex::BaseScraper
19
19
  StockIndex::Market.new(parse_market_link(market_link)).to_iso10383
20
20
  end
21
21
 
22
- def wikipedia(tr)
22
+ def wikipedia_link(tr)
23
23
  wikipedia_position(tr, 1)
24
24
  end
25
25
 
@@ -32,15 +32,4 @@ class SP500Scraper < StockIndex::BaseScraper
32
32
  end
33
33
  end
34
34
 
35
- def parse_symbol(symbol)
36
- case symbol
37
- # BRK.B => BRK/B Berkshire Hathaway Inc
38
- # BF.B => BF/B Brown-Forman Corp
39
- when /(\w+)\.B/
40
- "#{$1}/B"
41
- else
42
- symbol
43
- end
44
- end
45
-
46
35
  end
@@ -9,7 +9,7 @@ class StockIndex
9
9
  symbol = symbol(tr)
10
10
  market = market(tr)
11
11
  if symbol && market
12
- component = StockIndex::Component.new(symbol, market, wikipedia(tr))
12
+ component = StockIndex::Component.new(symbol, market, wikipedia_link(tr))
13
13
  array << component.attributes if component.valid?
14
14
  end
15
15
  array
@@ -23,6 +23,10 @@ class StockIndex
23
23
  def wikipedia_position(tr, position)
24
24
  wikipedia_td = tr.css('td')[position]
25
25
  wikipedia_path = wikipedia_td ? wikipedia_td.css('a').first.attributes['href'].value : nil
26
+ build_wikipedia_link(wikipedia_path)
27
+ end
28
+
29
+ def build_wikipedia_link(wikipedia_path)
26
30
  URI::HTTP.build({:host => 'en.wikipedia.org', :path => wikipedia_path}).to_s rescue nil
27
31
  end
28
32
 
@@ -18,7 +18,7 @@ class DjiScraper < StockIndex::BaseScraper
18
18
  StockIndex::Market.new(market).to_iso10383
19
19
  end
20
20
 
21
- def wikipedia(tr)
21
+ def wikipedia_link(tr)
22
22
  wikipedia_position(tr, 0)
23
23
  end
24
24
 
@@ -0,0 +1,25 @@
1
+ class NasdaqScraper < StockIndex::BaseScraper
2
+
3
+ def scrape
4
+ doc = Nokogiri::HTML(open(StockIndex::INDICES['^NDX'][:url]))
5
+ parse_rows doc.css('ol')[0].css('li')
6
+ end
7
+
8
+ def parse_rows(rows)
9
+ rows.inject([]) do |array, li|
10
+ symbol = /.+\((\w+)\)/.match(li)[1]
11
+ market = 'XNAS'
12
+ if symbol && market
13
+ component = StockIndex::Component.new(symbol, market, wikipedia(li))
14
+ array << component.attributes if component.valid?
15
+ end
16
+ array
17
+ end
18
+ end
19
+
20
+ def wikipedia(li)
21
+ wikipedia_path = li.css('a')[0].attributes['href'].value
22
+ build_wikipedia_link(wikipedia_path)
23
+ end
24
+
25
+ end
@@ -10,6 +10,8 @@ class StockIndex
10
10
  DjiScraper.new.scrape
11
11
  when '^GSPC'
12
12
  SP500Scraper.new.scrape
13
+ when '^NDX'
14
+ NasdaqScraper.new.scrape
13
15
  else
14
16
  []
15
17
  end
@@ -0,0 +1,37 @@
1
+ class SymbolParser
2
+
3
+ def initialize(symbol)
4
+ @symbol = symbol
5
+ end
6
+
7
+ def sp500_to_bsym
8
+ case @symbol
9
+ # BRK.B => BRK/B (Berkshire Hathaway Inc)
10
+ # BF.B => BF/B (Brown-Forman Corp)
11
+ when /(\w+)\.B/
12
+ "#{$1}/B"
13
+ else
14
+ @symbol
15
+ end
16
+ end
17
+
18
+ def bsym_to_cik
19
+ case @symbol
20
+ # BRK/B (Berkshire Hathaway Inc)
21
+ when 'BRK/B'
22
+ '0001067983'
23
+ # BF/B (Brown-Forman Corp)
24
+ when 'BF/B'
25
+ '0000014693'
26
+ # QVCA (Liberty Interactive Corp)
27
+ when 'QVCA'
28
+ '0001355096'
29
+ # LMCK (Liberty Media Corp)
30
+ when 'LMCK'
31
+ '0001560385'
32
+ else
33
+ @symbol
34
+ end
35
+ end
36
+
37
+ end
@@ -1,3 +1,3 @@
1
1
  class StockIndex
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/stock_index.rb CHANGED
@@ -5,6 +5,8 @@ require 'stock_index/indices'
5
5
  require 'stock_index/market'
6
6
  require 'stock_index/component'
7
7
  require 'stock_index/bsym_search'
8
+ require 'stock_index/symbol_parser'
8
9
  require 'stock_index/scrapers/base_scraper'
9
10
  require 'stock_index/scrapers/dji_scraper'
10
- require 'stock_index/scrapers/SP500_scraper'
11
+ require 'stock_index/scrapers/SP500_scraper'
12
+ require 'stock_index/scrapers/nasdaq_scraper'
@@ -0,0 +1,181 @@
1
+ ---
2
+ - :market: XNYS
3
+ :symbol: MMM
4
+ :name: 3M CO
5
+ :wikipedia: http://en.wikipedia.org/wiki/3M
6
+ :cik: '0000066740'
7
+ :bbgid: BBG000BP52R2
8
+ - :market: XNYS
9
+ :symbol: AXP
10
+ :name: AMERICAN EXPRESS CO
11
+ :wikipedia: http://en.wikipedia.org/wiki/American_Express_Co
12
+ :cik: 0000004962
13
+ :bbgid: BBG000BCQZS4
14
+ - :market: XNYS
15
+ :symbol: T
16
+ :name: AT&T INC
17
+ :wikipedia: http://en.wikipedia.org/wiki/AT%26T_Inc
18
+ :cik: '0000732717'
19
+ :bbgid: BBG000BSJK37
20
+ - :market: XNYS
21
+ :symbol: BA
22
+ :name: BOEING CO/THE
23
+ :wikipedia: http://en.wikipedia.org/wiki/Boeing_Company
24
+ :cik: 0000012927
25
+ :bbgid: BBG000BCSST7
26
+ - :market: XNYS
27
+ :symbol: CAT
28
+ :name: CATERPILLAR INC
29
+ :wikipedia: http://en.wikipedia.org/wiki/Caterpillar_Inc.
30
+ :cik: 0000018230
31
+ :bbgid: BBG000BF0K17
32
+ - :market: XNYS
33
+ :symbol: CVX
34
+ :name: CHEVRON CORP
35
+ :wikipedia: http://en.wikipedia.org/wiki/Chevron_Corp.
36
+ :cik: 0000093410
37
+ :bbgid: BBG000K4ND22
38
+ - :market: XNAS
39
+ :symbol: CSCO
40
+ :name: CISCO SYSTEMS INC
41
+ :wikipedia: http://en.wikipedia.org/wiki/Cisco_Systems
42
+ :cik: 0000858877
43
+ :bbgid: BBG000C3J3C9
44
+ - :market: XNYS
45
+ :symbol: KO
46
+ :name: COCA-COLA CO/THE
47
+ :wikipedia: http://en.wikipedia.org/wiki/The_Coca_Cola_Company
48
+ :cik: '0000021344'
49
+ :bbgid: BBG000BMX289
50
+ - :market: XNYS
51
+ :symbol: DD
52
+ :name: DU PONT (E.I.) DE NEMOURS
53
+ :wikipedia: http://en.wikipedia.org/wiki/Du_Pont_(E.I.)
54
+ :cik: '0000030554'
55
+ :bbgid: BBG000BH13K9
56
+ - :market: XNYS
57
+ :symbol: XOM
58
+ :name: EXXON MOBIL CORP
59
+ :wikipedia: http://en.wikipedia.org/wiki/Exxon_Mobil_Corp.
60
+ :cik: 0000034088
61
+ :bbgid: BBG000GZQ728
62
+ - :market: XNYS
63
+ :symbol: GE
64
+ :name: GENERAL ELECTRIC CO
65
+ :wikipedia: http://en.wikipedia.org/wiki/General_Electric
66
+ :cik: '0000040545'
67
+ :bbgid: BBG000BK6MB5
68
+ - :market: XNYS
69
+ :symbol: GS
70
+ :name: GOLDMAN SACHS GROUP INC
71
+ :wikipedia: http://en.wikipedia.org/wiki/Goldman_Sachs_Group
72
+ :cik: 0000886982
73
+ :bbgid: BBG000C6CFJ5
74
+ - :market: XNYS
75
+ :symbol: HD
76
+ :name: HOME DEPOT INC
77
+ :wikipedia: http://en.wikipedia.org/wiki/Home_Depot
78
+ :cik: 0000354950
79
+ :bbgid: BBG000BKZB36
80
+ - :market: XNAS
81
+ :symbol: INTC
82
+ :name: INTEL CORP
83
+ :wikipedia: http://en.wikipedia.org/wiki/Intel_Corp.
84
+ :cik: 0000050863
85
+ :bbgid: BBG000C0G1D1
86
+ - :market: XNYS
87
+ :symbol: IBM
88
+ :name: INTL BUSINESS MACHINES CORP
89
+ :wikipedia: http://en.wikipedia.org/wiki/International_Bus._Machines
90
+ :cik: '0000051143'
91
+ :bbgid: BBG000BLNNH6
92
+ - :market: XNYS
93
+ :symbol: JNJ
94
+ :name: JOHNSON & JOHNSON
95
+ :wikipedia: http://en.wikipedia.org/wiki/Johnson_%26_Johnson
96
+ :cik: '0000200406'
97
+ :bbgid: BBG000BMHYD1
98
+ - :market: XNYS
99
+ :symbol: JPM
100
+ :name: JPMORGAN CHASE & CO
101
+ :wikipedia: http://en.wikipedia.org/wiki/JPMorgan_Chase_%26_Co.
102
+ :cik: 0000019617
103
+ :bbgid: BBG000DMBXR2
104
+ - :market: XNYS
105
+ :symbol: MCD
106
+ :name: MCDONALD'S CORP
107
+ :wikipedia: http://en.wikipedia.org/wiki/McDonald%27s_Corp.
108
+ :cik: 0000063908
109
+ :bbgid: BBG000BNSZP1
110
+ - :market: XNYS
111
+ :symbol: MRK
112
+ :name: MERCK & CO. INC.
113
+ :wikipedia: http://en.wikipedia.org/wiki/Merck_%26_Co.
114
+ :cik: 0000310158
115
+ :bbgid: BBG000BPD168
116
+ - :market: XNAS
117
+ :symbol: MSFT
118
+ :name: MICROSOFT CORP
119
+ :wikipedia: http://en.wikipedia.org/wiki/Microsoft_Corp.
120
+ :cik: 0000789019
121
+ :bbgid: BBG000BPH459
122
+ - :market: XNYS
123
+ :symbol: NKE
124
+ :name: NIKE INC -CL B
125
+ :wikipedia: http://en.wikipedia.org/wiki/NIKE_Inc.
126
+ :cik: 0000320187
127
+ :bbgid: BBG000C5HS04
128
+ - :market: XNYS
129
+ :symbol: PFE
130
+ :name: PFIZER INC
131
+ :wikipedia: http://en.wikipedia.org/wiki/Pfizer_Inc.
132
+ :cik: 0000078003
133
+ :bbgid: BBG000BR2B91
134
+ - :market: XNYS
135
+ :symbol: PG
136
+ :name: PROCTER & GAMBLE CO/THE
137
+ :wikipedia: http://en.wikipedia.org/wiki/Procter_%26_Gamble
138
+ :cik: 0000080424
139
+ :bbgid: BBG000BR2TH3
140
+ - :market: XNYS
141
+ :symbol: TRV
142
+ :name: TRAVELERS COS INC/THE
143
+ :wikipedia: http://en.wikipedia.org/wiki/The_Travelers_Companies_Inc.
144
+ :cik: 0000086312
145
+ :bbgid: BBG000BJ81C1
146
+ - :market: XNYS
147
+ :symbol: UNH
148
+ :name: UNITEDHEALTH GROUP INC
149
+ :wikipedia: http://en.wikipedia.org/wiki/United_Health_Group_Inc.
150
+ :cik: '0000731766'
151
+ :bbgid: BBG000CH5208
152
+ - :market: XNYS
153
+ :symbol: UTX
154
+ :name: UNITED TECHNOLOGIES CORP
155
+ :wikipedia: http://en.wikipedia.org/wiki/United_Technologies
156
+ :cik: 0000101829
157
+ :bbgid: BBG000BW8S60
158
+ - :market: XNYS
159
+ :symbol: VZ
160
+ :name: VERIZON COMMUNICATIONS INC
161
+ :wikipedia: http://en.wikipedia.org/wiki/Verizon_Communications
162
+ :cik: '0000732712'
163
+ :bbgid: BBG000HS77T5
164
+ - :market: XNYS
165
+ :symbol: V
166
+ :name: VISA INC-CLASS A SHARES
167
+ :wikipedia: http://en.wikipedia.org/wiki/Visa_Inc.
168
+ :cik: '0001403161'
169
+ :bbgid: BBG000PSKYX7
170
+ - :market: XNYS
171
+ :symbol: WMT
172
+ :name: WAL-MART STORES INC
173
+ :wikipedia: http://en.wikipedia.org/wiki/Wal-Mart_Stores
174
+ :cik: 0000104169
175
+ :bbgid: BBG000BWXBC2
176
+ - :market: XNYS
177
+ :symbol: DIS
178
+ :name: WALT DISNEY CO/THE
179
+ :wikipedia: http://en.wikipedia.org/wiki/The_Walt_Disney_Company
180
+ :cik: 0001001039
181
+ :bbgid: BBG000BH4R78