histock-filter 0.1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile +4 -0
- data/README.md +229 -6
- data/histock-filter.gemspec +2 -2
- data/lib/histock/filter.rb +47 -3
- data/lib/histock/filter/helper.rb +27 -0
- data/lib/histock/filter/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88873eae7ffb99f849806fa79ab0b4ac67e5bf729f9ed2dff867d3a78f266c6c
|
4
|
+
data.tar.gz: cdb11409acbb672c4545ff8e5af195add6c68acdef301fd8d5e8bbd3fefd6b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 968f1e689116b47e3638f0ec920e7c80d4b53c17334a3593f165f66268c6985af54cf938baa78b84c3bd0bada415f5dff6aff574d75bf9004c33d6b89a27601f
|
7
|
+
data.tar.gz: d0a7c60edb131d9e4701b82bc14429335b94e98eef3af5828667dc617aaf9d1b924cbae91b0eddfbdc23692a61cb3bd6dbe4c0d991abdd0e8b6af9c805143d91
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## v1.1.0
|
2
|
+
[full changelog](http://github.com/ysato5654/histock-filter/compare/v1.0.0...v1.1.0)
|
3
|
+
|
4
|
+
* support new request
|
5
|
+
- price to earning ratio
|
6
|
+
- price book ratio
|
7
|
+
|
8
|
+
## v1.0.0
|
9
|
+
[full changelog](http://github.com/ysato5654/histock-filter/compare/v0.4.1...v1.0.0)
|
10
|
+
|
11
|
+
* change class of output date
|
12
|
+
- String -> Integer / Float
|
13
|
+
|
14
|
+
## v0.4.1
|
15
|
+
[full changelog](http://github.com/ysato5654/histock-filter/compare/v0.4.0...v0.4.1)
|
16
|
+
|
17
|
+
* 'month' option is not supported from this version
|
18
|
+
|
19
|
+
## v0.4.0
|
20
|
+
[full changelog](http://github.com/ysato5654/histock-filter/compare/v0.2.0...v0.4.0)
|
21
|
+
|
22
|
+
* change request name
|
23
|
+
- before: financial statements
|
24
|
+
after: monthly revenue
|
25
|
+
* support new request
|
26
|
+
- profit ratio
|
27
|
+
- income rate
|
28
|
+
|
29
|
+
## v0.2.0
|
30
|
+
[full changelog](http://github.com/ysato5654/histock-filter/compare/v0.1.0...v0.2.0)
|
31
|
+
|
32
|
+
* support new request
|
33
|
+
- financial statements
|
34
|
+
|
1
35
|
## v0.1.0
|
2
36
|
|
3
37
|
* first beta release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/histock-filter.svg)](https://badge.fury.io/rb/histock-filter)
|
2
2
|
[![Build Status](https://travis-ci.org/ysato5654/histock-filter.svg?branch=master)](https://travis-ci.org/ysato5654/histock-filter)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/ysato5654/histock-filter/badge.svg?branch=master)](https://coveralls.io/github/ysato5654/histock-filter?branch=master)
|
3
4
|
|
4
5
|
# Histock::Filter
|
5
6
|
|
6
|
-
[HiStock嗨投資理財社群](https://histock.tw/)
|
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
|
+
|
7
11
|
|
8
12
|
## Installation
|
9
13
|
|
@@ -27,13 +31,232 @@ $ gem install histock-filter
|
|
27
31
|
|
28
32
|
## Usage
|
29
33
|
|
34
|
+
### Dividend Policy
|
35
|
+
|
36
|
+
```rb
|
37
|
+
require 'histock/filter'
|
38
|
+
|
39
|
+
histock = Histock::Filter.new
|
40
|
+
histock.dividend_policy('2330')
|
41
|
+
# [
|
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
|
+
# :
|
175
|
+
# ]
|
176
|
+
```
|
177
|
+
|
178
|
+
##### Quarterly Data
|
179
|
+
|
180
|
+
| key | type |
|
181
|
+
|-----|------|
|
182
|
+
| 年度/季別 | string |
|
183
|
+
| 近四季ROE | float |
|
184
|
+
| 近四季ROA | float |
|
185
|
+
|
186
|
+
```rb
|
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
|
+
|
30
251
|
```rb
|
31
252
|
histock = Histock::Filter.new
|
32
|
-
histock.
|
253
|
+
histock.price_book_ratio('2330')
|
33
254
|
# [
|
34
|
-
# {
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
255
|
+
# {
|
256
|
+
# "年度/月份" => "2020/06",
|
257
|
+
# "股價淨值比" => 4.89
|
258
|
+
# },
|
259
|
+
# {},
|
260
|
+
# :
|
38
261
|
# ]
|
39
262
|
```
|
data/histock-filter.gemspec
CHANGED
@@ -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', '
|
29
|
+
spec.add_runtime_dependency 'histock-simplefilter', '~> 0.5.0'
|
30
30
|
|
31
31
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
|
-
spec.add_development_dependency 'rake', '
|
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
|
data/lib/histock/filter.rb
CHANGED
@@ -1,20 +1,64 @@
|
|
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 = [
|
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
|
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
|
+
private
|
45
|
+
|
46
|
+
def parse(table)
|
47
|
+
list = table[1..-1].map { |e| table.first.zip(e).to_h }
|
48
|
+
|
49
|
+
list.each do |hash|
|
50
|
+
hash.each do |key, val|
|
51
|
+
if Histock::Helper.is_persentage?(val)
|
52
|
+
hash[key] = Histock::Helper.persentage_to_number(val)
|
53
|
+
elsif Histock::Helper.is_currency?(val)
|
54
|
+
hash[key] = Histock::Helper.currency_to_number(val)
|
55
|
+
elsif Histock::Helper.is_float?(val)
|
56
|
+
hash[key] = val.to_f
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
list
|
62
|
+
end
|
19
63
|
end
|
20
64
|
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
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: histock-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuya Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: histock-simplefilter
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.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.
|
26
|
+
version: 0.5.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:
|
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:
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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:
|
@@ -122,7 +123,7 @@ 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.
|
126
|
+
rubygems_version: 3.1.3
|
126
127
|
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: HiStock (https://histock.tw/) filter
|