histock-filter 0.2.0 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe636cff439c19edee8a99b5d7fd6193ca13ca75c3fbf811477e96fa11ecd78e
4
- data.tar.gz: 40449e937af952c0ad38d220a16d9e842a467921898154014fd814e65f875077
3
+ metadata.gz: 8fe953be3755323081d13bff4178eebb148599d0f88a9faf48aa89b59295cb8b
4
+ data.tar.gz: d229157e246d008d9818803e234398fd079a17965f444a696dd90fbc574e52df
5
5
  SHA512:
6
- metadata.gz: 5281ac2c58f71ada2be303b41110d06776d0ccb19ad6b49e67b156ffae19a98fd733fc2471f8c42f95ef61edb4276482478eb9c94b02d2a1190a191aed035383
7
- data.tar.gz: b7f3f191f4594a72edeeb5a0dd718a4412918807900987c0af9e5a5be22caea4812992b8f37e2c34f323ea8161f128a1030190ea542990f3cb02a77a1c0f020a
6
+ metadata.gz: 6e7da0c6963a5b457084088d3295b86cd9c807b34b71f3bed501631e48435e630eac42785d4e7de9066a8de93991f4366ca80384a57cde6650b063c4f462d7ea
7
+ data.tar.gz: a1038892726671334f9b04cdc3660e10ee73765cef9040c2e8871dab45bef537bb37605aed73636ab21f88be2a3add8a1049eba327a710826a38ab6bc3edd762
@@ -1,3 +1,37 @@
1
+ ## v1.2.0
2
+ [full changelog](http://github.com/ysato5654/histock-filter/compare/v1.1.0...v1.2.0)
3
+
4
+ * support new request
5
+ - company profile
6
+
7
+ ## v1.1.0
8
+ [full changelog](http://github.com/ysato5654/histock-filter/compare/v1.0.0...v1.1.0)
9
+
10
+ * support new request
11
+ - price to earning ratio
12
+ - price book ratio
13
+
14
+ ## v1.0.0
15
+ [full changelog](http://github.com/ysato5654/histock-filter/compare/v0.4.1...v1.0.0)
16
+
17
+ * change class of output date
18
+ - String -> Integer / Float
19
+
20
+ ## v0.4.1
21
+ [full changelog](http://github.com/ysato5654/histock-filter/compare/v0.4.0...v0.4.1)
22
+
23
+ * 'month' option is not supported from this version
24
+
25
+ ## v0.4.0
26
+ [full changelog](http://github.com/ysato5654/histock-filter/compare/v0.2.0...v0.4.0)
27
+
28
+ * change request name
29
+ - before: financial statements
30
+ after: monthly revenue
31
+ * support new request
32
+ - profit ratio
33
+ - income rate
34
+
1
35
  ## v0.2.0
2
36
  [full changelog](http://github.com/ysato5654/histock-filter/compare/v0.1.0...v0.2.0)
3
37
 
data/README.md CHANGED
@@ -4,7 +4,10 @@
4
4
 
5
5
  # Histock::Filter
6
6
 
7
- [HiStock嗨投資理財社群](https://histock.tw/) filter by Ruby
7
+ histock-filter is Ruby library to get the finance data of listed stock on the Taiwan stock exchange market from [HiStock嗨投資理財社群](https://histock.tw/).
8
+
9
+ If you would like to get more basic data (row data), refer to [histock-simplefilter](https://github.com/ysato5654/histock-simplefilter).
10
+
8
11
 
9
12
  ## Installation
10
13
 
@@ -28,29 +31,232 @@ $ gem install histock-filter
28
31
 
29
32
  ## Usage
30
33
 
31
- ### Dividend policy
34
+ ### Dividend Policy
32
35
 
33
36
  ```rb
37
+ require 'histock/filter'
38
+
34
39
  histock = Histock::Filter.new
35
40
  histock.dividend_policy('2330')
36
41
  # [
37
- # {"所屬年度" => "2019", "發放年度" => "2020", "除權日" => "", "除息日" => "06/18", "除權息前股價" => "297.5", "股票股利" => "0", "現金股利" => "2.5", EPS" => "13.32", "配息率" => "18.77%", "現金殖利率" => "0.84%", "扣抵稅率" => "0.00%", "增資配股率" => "0", "增資認購價" => "0"},
38
- # {"所屬年度" => "2019", "發放年度" => "2020", "除權日" => "", "除息日" => "03/19", "除權息前股價" => "260", "股票股利" => "0", "現金股利" => "2.5", "EPS" => "13.32", "配息率" => "18.77%", "現金殖利率" => "0.96%", "扣抵稅率" => "0.00%", "增資配股率" => "0", "增資認購價" => "0"},
39
- # {"所屬年度" => "2018", "發放年度" => "2019", "除權日" => "", "除息日" => "12/19", "除權息前股價" => "344.5", "股票股利" => "0", "現金股利" => "2.5", "EPS" => "13.54", "配息率" => "18.46%", "現金殖利率" => "0.73%", "扣抵稅率" => "0.00%", "增資配股率" => "0", "增資認購價" => "0"},
40
- # {"所屬年度" => "2018", "發放年度" => "2019", "除權日" => "", "除息日" => "09/19", "除權息前股價" => "267", "股票股利" => "0", "現金股利" => "2", "EPS" => "13.54", "配息率" => "14.77%", "現金殖利率" => "0.75%", "扣抵稅率" => "0.00%", "增資配股率" => "0", "增資認購價" => "0"},
42
+ # {
43
+ # "所屬年度" => "2019",
44
+ # "發放年度" => "2020",
45
+ # "除權日" => "",
46
+ # "除息日" => "06/18",
47
+ # "除權息前股價" => 297.5,
48
+ # "股票股利" => 0,
49
+ # "現金股利" => 2.5,
50
+ # "EPS" => 13.32,
51
+ # "配息率" => 18.77,
52
+ # "現金殖利率" => 0.84,
53
+ # "扣抵稅率" => 0.00,
54
+ # "增資配股率" => 0,
55
+ # "增資認購價" => 0
56
+ # },
57
+ # {},
58
+ # :
59
+ # ]
60
+ ```
61
+
62
+ ### Basic Financial Statements
63
+
64
+ #### Monthly Revenue
65
+
66
+ | key | type |
67
+ |-----|------|
68
+ | 年度/月份 | string |
69
+ | 單月營收 | integer |
70
+ | 去年同月營收 | integer |
71
+ | 單月月增率 | float |
72
+ | 單月年增率 | float |
73
+ | 累計營收 | integer |
74
+ | 去年累計營收 | integer |
75
+ | 累積年增率 | float |
76
+
77
+ ```rb
78
+ require 'histock/filter'
79
+
80
+ histock = Histock::Filter.new
81
+ histock.monthly_revenue('2330')
82
+ # [
83
+ # {
84
+ # "年度/月份" => "2020/04",
85
+ # "單月營收" => 96001568,
86
+ # "去年同月營收" => 74693616,
87
+ # "單月月增率" => -15.4,
88
+ # "單月年增率" => 28.5,
89
+ # "累計營收" => 406598784,
90
+ # "去年累計營收" => 293398112,
91
+ # "累積年增率" => 38.6
92
+ # },
93
+ # {},
94
+ # :
95
+ # ]
96
+ ```
97
+
98
+ #### Income Statement
99
+
100
+ | key | type |
101
+ |-----|------|
102
+ | 年度/季別 | string |
103
+ | 營收 | integer |
104
+ | 毛利 | integer |
105
+ | 營業利益 | integer |
106
+ | 稅前淨利 | integer |
107
+ | 稅後淨利 | integer |
108
+
109
+ ```rb
110
+ histock = Histock::Filter.new
111
+ histock.income_statement('2330')
112
+ # [
113
+ # {
114
+ # "年度/季別"" => "2019Q4",
115
+ # "營收" => 317237065,
116
+ # "毛利" => 159240985,
117
+ # "營業利益" => 124243722,
118
+ # "稅前淨利" => 128781973,
119
+ # "稅後淨利" => 116078194
120
+ # },
121
+ # {},
122
+ # :
123
+ # ]
124
+ ```
125
+
126
+ ### Profitability
127
+
128
+ #### Profit Ratio
129
+
130
+ | key | type |
131
+ |-----|------|
132
+ | 年度/季別 | string |
133
+ | 毛利率 | float |
134
+ | 營業利益率 | float |
135
+ | 稅前淨利率 | float |
136
+ | 稅後淨利率 | float |
137
+
138
+ ```rb
139
+ histock = Histock::Filter.new
140
+ histock.profit_ratio('2330')
141
+ # [
142
+ # {
143
+ # "年度/季別" => "2019Q4",
144
+ # "毛利率" => 50.20,
145
+ # "營業利益率" => 39.16,
146
+ # "稅前淨利率" => 40.59,
147
+ # "稅後淨利率" => 36.59
148
+ # },
149
+ # {},
150
+ # :
151
+ # ]
152
+ ```
153
+
154
+ #### Income Rate
155
+
156
+ ##### Monthly Data
157
+
158
+ | key | type |
159
+ |-----|------|
160
+ | 年度/季別 | string |
161
+ | ROE | float |
162
+ | ROA | float |
163
+
164
+ ```rb
165
+ histock = Histock::Filter.new
166
+ histock.income_rate('2330', 'month')
167
+ # [
168
+ # {
169
+ # "年度/季別" => "2020Q1",
170
+ # "ROE" => 7.10,
171
+ # "ROA" => 5.08
172
+ # },
173
+ # {},
174
+ # :
41
175
  # ]
42
176
  ```
43
177
 
44
- ### Financial statements
178
+ ##### Quarterly Data
179
+
180
+ | key | type |
181
+ |-----|------|
182
+ | 年度/季別 | string |
183
+ | 近四季ROE | float |
184
+ | 近四季ROA | float |
45
185
 
46
186
  ```rb
47
- histock = Histock::Simplefilter.new
48
- histock.financial_statements('2330')
187
+ histock = Histock::Filter.new
188
+ histock.income_rate('2330', 'quarter')
189
+ # [
190
+ # {
191
+ # "年度/季別" => "2020Q1",
192
+ # "近四季ROE" => 23.45,
193
+ # "近四季ROA" => 17.70
194
+ # },
195
+ # {},
196
+ # :
197
+ # ]
198
+ ```
199
+
200
+ ##### Yearly Data
201
+
202
+ | key | type |
203
+ |-----|------|
204
+ | 年度 | string |
205
+ | 年度ROE | float |
206
+ | 年度ROA | float |
207
+
208
+ ```rb
209
+ histock = Histock::Filter.new
210
+ histock.income_rate('2330', 'year')
211
+ # [
212
+ # {
213
+ # "年度" => "2019",
214
+ # "年度ROE" => 20.93,
215
+ # "年度ROA" => 15.86
216
+ # },
217
+ # {},
218
+ # :
219
+ # ]
220
+ ```
221
+
222
+ ### Corporate Value
223
+
224
+ #### PER
225
+
226
+ | key | type |
227
+ |-----|------|
228
+ | 年度/月份 | string |
229
+ | 本益比 | float |
230
+
231
+ ```rb
232
+ histock = Histock::Filter.new
233
+ histock.price_to_earning_ratio('2330')
234
+ # [
235
+ # {
236
+ # "年度/月份" => "2020/06",
237
+ # "本益比" => 20.44
238
+ # },
239
+ # {},
240
+ # :
241
+ # ]
242
+ ```
243
+
244
+ #### PBR
245
+
246
+ | key | type |
247
+ |-----|------|
248
+ | 年度/月份 | string |
249
+ | 股價淨值比 | float |
250
+
251
+ ```rb
252
+ histock = Histock::Filter.new
253
+ histock.price_book_ratio('2330')
49
254
  # [
50
- # {"年度/月份" => "2020/04", "單月營收" => "96,001,568", "去年同月營收" => "74,693,616", "單月月增率" => "-15.4%", "單月年增率" => "28.5%", "累計營收" => "406,598,784", "去年累計營收" => "293,398,112", "累積年增率" => "38.6%"},
51
- # {"年度/月份" => "2020/03", "單月營收" => "113,519,600", "去年同月營收" => "79,721,584", "單月月增率" => "21.5%", "單月年增率" => "42.4%", "累計營收" => "310,597,184", "去年累計營收" => "218,704,496", "累積年增率" => "42%"},
52
- # {"年度/月份" => "2020/02", "單月營收" => "93,394,448", "去年同月營收" => "60,889,060", "單月月增率" => "-9.9%", "單月年增率" => "53.4%", "累計營收" => "197,077,600", "去年累計營收" => "138,982,896", "累積年增率" => "41.8%"},
53
- # {"年度/月份" => "2020/01", "單月營收" => "103,683,104", "去年同月營收" => "78,093,824", "單月月增率" => "0.3%", "單月年增率" => "32.8%", "累計營收" => "103,683,104", "去年累計營收" => "78,093,824", "累積年增率" => "32.8%"},
54
- # {"年度/月份" => "2019/12", "單月營收" => "103,313,104", "去年同月營收" => "89,830,600", "單月月增率" => "-4.2%", "單月年增率" => "15%", "累計營收" => "1,069,985,024", "去年累計營收" => "1,031,473,984", "累積年增率" => "3.7%"}
255
+ # {
256
+ # "年度/月份" => "2020/06",
257
+ # "股價淨值比" => 4.89
258
+ # },
259
+ # {},
260
+ # :
55
261
  # ]
56
262
  ```
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '~> 2.5'
28
28
 
29
- spec.add_runtime_dependency 'histock-simplefilter', '~> 0.2.0'
29
+ spec.add_runtime_dependency 'histock-simplefilter', '~> 0.6.0'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '~> 2.0'
32
- spec.add_development_dependency 'rake', '>= 12.3.3'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
34
  spec.add_development_dependency 'travis', '>= 1.9.0'
35
35
  end
@@ -1,20 +1,71 @@
1
1
  require 'histock/simplefilter'
2
2
  require File.expand_path(File.dirname(__FILE__)) + '/filter/version'
3
+ require File.expand_path(File.dirname(__FILE__)) + '/filter/helper'
3
4
 
4
5
  module Histock
5
6
  class Filter
6
- CONFIG = ['dividend_policy', 'financial_statements']
7
+ CONFIG = [
8
+ # one argument
9
+ [
10
+ 'monthly_revenue',
11
+ 'income_statement',
12
+ 'dividend_policy',
13
+ 'profit_ratio',
14
+ 'price_to_earning_ratio',
15
+ 'price_book_ratio'
16
+ ],
17
+ # two arguments
18
+ [
19
+ 'income_rate'
20
+ ]
21
+ ]
7
22
 
8
23
  def initialize
9
24
  end
10
25
 
11
- CONFIG.each do |method_name|
26
+ CONFIG.first.each do |method_name|
12
27
  define_method method_name do |param|
13
28
  histock = Histock::Simplefilter.new
14
29
  table = histock.send(method_name, param)
15
30
 
16
- table[1..-1].map { |e| table.first.zip(e).to_h }
31
+ parse(table)
17
32
  end
18
33
  end
34
+
35
+ CONFIG.last.each do |method_name|
36
+ define_method method_name do |param, param2|
37
+ histock = Histock::Simplefilter.new
38
+ table = histock.send(method_name, param, param2)
39
+
40
+ parse(table)
41
+ end
42
+ end
43
+
44
+ def company_profile(param)
45
+ histock = Histock::Simplefilter.new
46
+ table = histock.send(__method__, param)
47
+
48
+ table[0..1].transpose.to_h.merge(table[2..3].transpose.to_h)
49
+ end
50
+
51
+ private
52
+
53
+ def parse(table)
54
+ list = table[1..-1].map { |e| table.first.zip(e).to_h }
55
+
56
+ list.each do |hash|
57
+ hash.each do |key, val|
58
+ if Histock::Helper.is_persentage?(val)
59
+ hash[key] = Histock::Helper.persentage_to_number(val)
60
+ elsif Histock::Helper.is_currency?(val)
61
+ hash[key] = Histock::Helper.currency_to_number(val)
62
+ elsif Histock::Helper.is_float?(val)
63
+ hash[key] = val.to_f
64
+ end
65
+ end
66
+ end
67
+
68
+ list
69
+ end
19
70
  end
20
71
  end
@@ -0,0 +1,27 @@
1
+ module Histock
2
+ class Helper
3
+ class << self
4
+ def is_persentage?(str)
5
+ str.match(/^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)%$/).nil? ? false : true
6
+ end
7
+
8
+ def is_currency?(str)
9
+ str.match(/^[+-]?\d{1,3}(,\d{3})*$/).nil? ? false : true
10
+ end
11
+
12
+ def is_float?(str)
13
+ str.match(/^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)$/).nil? ? false : true
14
+ end
15
+
16
+ # should check str by 'is_persentage?' method before calling this method
17
+ def persentage_to_number(str)
18
+ str.to_s.gsub(/%/,'').to_f
19
+ end
20
+
21
+ # should check str by 'is_currency?' method before calling this method
22
+ def currency_to_number(str)
23
+ str.to_s.gsub(/[$,]/,'').to_i
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Histock
2
2
  class Filter
3
- VERSION = '0.2.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: histock-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Sato
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-09 00:00:00.000000000 Z
11
+ date: 2020-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: histock-simplefilter
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 12.3.3
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 12.3.3
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.9.0
83
- description:
83
+ description:
84
84
  email:
85
85
  - ysato.5654@gmail.com
86
86
  executables: []
@@ -99,6 +99,7 @@ files:
99
99
  - bin/setup
100
100
  - histock-filter.gemspec
101
101
  - lib/histock/filter.rb
102
+ - lib/histock/filter/helper.rb
102
103
  - lib/histock/filter/version.rb
103
104
  homepage: https://github.com/ysato5654/histock-filter
104
105
  licenses:
@@ -107,7 +108,7 @@ metadata:
107
108
  homepage_uri: https://github.com/ysato5654/histock-filter
108
109
  source_code_uri: https://github.com/ysato5654/histock-filter
109
110
  changelog_uri: https://github.com/ysato5654/histock-filter/blob/master/CHANGELOG.md
110
- post_install_message:
111
+ post_install_message:
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib
@@ -122,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 3.1.3
126
- signing_key:
126
+ rubygems_version: 3.1.4
127
+ signing_key:
127
128
  specification_version: 4
128
129
  summary: HiStock (https://histock.tw/) filter
129
130
  test_files: []