neurostats-API 0.0.3__tar.gz → 0.0.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. neurostats_API-0.0.4/MANIFEST.in +2 -0
  2. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/PKG-INFO +73 -28
  3. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/README.md +72 -27
  4. neurostats_API-0.0.4/neurostats_API/__init__.py +1 -0
  5. neurostats_API-0.0.4/neurostats_API/fetchers/__init__.py +3 -0
  6. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/base.py +4 -6
  7. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/finance_overview.py +5 -7
  8. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/value_invest.py +2 -2
  9. neurostats_API-0.0.4/neurostats_API/tools/finance_overview_dict.yaml +136 -0
  10. neurostats_API-0.0.4/neurostats_API/tools/profit_lose.yaml +93 -0
  11. neurostats_API-0.0.4/neurostats_API/tools/seasonal_data_field_dict.txt +158 -0
  12. neurostats_API-0.0.4/neurostats_API/utils/__init__.py +4 -0
  13. neurostats_API-0.0.4/neurostats_API/utils/data_process.py +18 -0
  14. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/utils/fetcher.py +16 -96
  15. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API.egg-info/PKG-INFO +73 -28
  16. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API.egg-info/SOURCES.txt +5 -0
  17. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/setup.py +4 -3
  18. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/test/test_fetchers.py +31 -5
  19. neurostats_API-0.0.3/neurostats_API/__init__.py +0 -1
  20. neurostats_API-0.0.3/neurostats_API/fetchers/__init__.py +0 -1
  21. neurostats_API-0.0.3/neurostats_API/utils/__init__.py +0 -2
  22. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/cli.py +0 -0
  23. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/balance_sheet.py +0 -0
  24. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/month_revenue.py +0 -0
  25. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/profit_lose.py +0 -0
  26. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/fetchers/tech.py +0 -0
  27. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/main.py +0 -0
  28. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/utils/datetime.py +0 -0
  29. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API/utils/db_client.py +0 -0
  30. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API.egg-info/dependency_links.txt +0 -0
  31. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/neurostats_API.egg-info/top_level.txt +0 -0
  32. {neurostats_API-0.0.3 → neurostats_API-0.0.4}/setup.cfg +0 -0
@@ -0,0 +1,2 @@
1
+ recursive-include neurostats_api/tools *.yaml
2
+ recursive-include neurostats_api/tools *.txt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -12,46 +12,78 @@ Description-Content-Type: text/markdown
12
12
 
13
13
  - [檔案架構](#檔案架構)
14
14
  - [使用方法](#使用方法)
15
- - [import](#import)
15
+ - [下載](#下載)
16
16
  - [價值投資](#得到最新一期的評價資料與歷年評價)
17
17
  - [財務分析-重要指標](#財務分析-重要指標)
18
18
  - [月營收表](#回傳月營收表)
19
+ - [損益表](#損益表)
19
20
  - [資產負債表](#資產負債表)
20
21
  - [現金流量表](#現金流量表)
21
22
 
22
23
  ## 檔案架構
23
24
 
24
25
  ```
25
- ./
26
- ├── cli.py
27
- ├── main.py
26
+ ├── neurostats_API
27
+ │   ├── __init__.py
28
+ │   ├── cli.py
29
+ │   ├── main.py
30
+ │   ├── fetchers
31
+ │   │   ├── __init__.py
32
+ │   │   ├── base.py
33
+ │   │   ├── finance_overview.py
34
+ │   │   ├── tech.py
35
+ │   │   └── value_invest.py
36
+ │   ├── tools
37
+ │   │   ├── finance_overview_dict.yaml
38
+ │   │   ├── profit_lose.yaml
39
+ │   │   └── seasonal_data_field_dict.txt
40
+ │   └── utils
41
+ │   ├──__init__.py
42
+ │   ├── data_process.py
43
+ │   ├── datetime.py
44
+ │   ├── db_client.py
45
+ │   └── fetcher.py
46
+ ├── test
47
+ │ ├── __init__.py
48
+ │ └── test_fetchers.py
49
+ ├── Makefile
50
+ ├── MANIFEST.in
28
51
  ├── README.md
29
52
  ├── requirement.txt
30
- ├── tw50_company_list.json
31
- └── utils
32
- ├── fetcher.py
33
- ├── __init__.py
34
- ```
35
-
36
- `main.py`: 執行檔
37
- `cli.py`: 命令輸入的檔案
38
- `utils`: 存放fetcher
39
- - `fetcher.py`: Service的主架構
40
- `tw50_company_list.json`: tw50的公司列表
41
-
42
- ## 使用方法
53
+ ├── setup.py
43
54
 
44
- ### import
45
- ```Python
46
- from utils import statsFetcher
47
- stats_fetcher = statsFetcher
55
+ ```
56
+ - `neurostats_API`: 主要的package運行內容
57
+ - `fetchers`: 回傳service內容的fetcher檔案夾
58
+ - `base.py`: 基本架構
59
+ - `value_invest.py`: iFa.ai -> 價值投資
60
+ - `finance_overview.py`: iFa.ai -> 財務分析 -> 重要指標
61
+ - `tech.py`: iFa.ai -> 技術指標
62
+ - `tools`: 存放各種設定檔與資料庫index對應領域的dictionary
63
+ - `utils`:
64
+ - `fetcher.py`: Service的舊主架構, 月營收, 損益表, 資產負債表, 資產收益表目前在這裡
65
+ - `data_process.py`: config資料的讀取
66
+ - `datetime.py`: 時間格式,包括日期,年度,月份,日,季度
67
+
68
+ ## 下載
69
+ ```
70
+ pip install neurostats-API
71
+ ```
72
+ ### 確認下載成功
73
+ ```Python
74
+ >>> import neurostats_API
75
+ >>> print(neurostats_API.__version__)
76
+ 0.0.5
48
77
  ```
49
78
 
50
79
  ### 得到最新一期的評價資料與歷年評價
51
80
  ``` Python
81
+ from neurostats_API.fetchers import ValueFetcher
52
82
  ticker = 2330 # 換成tw50內任意ticker
53
- stats_fetcher.get_value_sheet(ticker)
83
+ fetcher = ValueFetcher(ticker)
84
+ data = stats_fetcher.query_data()
54
85
  ```
86
+
55
87
  #### 回傳(2330為例)
56
88
  ```Python
57
89
  {
@@ -86,8 +118,10 @@ stats_fetcher.get_value_sheet(ticker)
86
118
 
87
119
  ### 回傳月營收表
88
120
  ``` Python
121
+ from neurostats_API.utils import StatsFetcher
89
122
  ticker = 2330 # 換成tw50內任意ticker
90
- stats_fetcher.get_month_revenue_sheet(ticker)
123
+ fetcher = StatsFetcher()
124
+ data = stats_fetcher.get_month_revenue_sheet(ticker)
91
125
  ```
92
126
 
93
127
  #### 回傳
@@ -136,9 +170,10 @@ YoY_10 None None ... None None
136
170
  ### 財務分析: 重要指標
137
171
  對應https://ifa.ai/tw-stock/2330/finance-overview
138
172
  ```Python
139
- from fetchers import FinanceOverviewFetcher
140
- fetcher = FinanceOverviewFetcher(2330) # 參數內可換成其他股票代碼
141
- fetcher.query_data()
173
+ from neurostats_API.fetchers import FinanceOverviewFetcher
174
+ ticker = "2330"
175
+ fetcher = FinanceOverviewFetcher(ticker = "2330")
176
+ data = fetcher.query_data()
142
177
  ```
143
178
 
144
179
  #### 回傳
@@ -218,8 +253,10 @@ markdown
218
253
 
219
254
  ### 損益表
220
255
  ```Python
256
+ from neurostats_API.utils import StatsFetcher
257
+ fetcher = StatsFetcher()
221
258
  ticker = 2330 # 換成tw50內任意ticker
222
- stats_fetcher.get_profit_lose(ticker)
259
+ data = fetcher.get_profit_lose(ticker)
223
260
  ```
224
261
 
225
262
  #### 回傳
@@ -264,6 +301,8 @@ stats_fetcher.get_profit_lose(ticker)
264
301
 
265
302
  ### 資產負債表
266
303
  ``` Python
304
+ from neurostats_API.utils import StatsFetcher
305
+ fetcher = StatsFetcher()
267
306
  ticker = 2330 # 換成tw50內任意ticker
268
307
  stats_fetcher.get_balance_sheet(ticker)
269
308
  ```
@@ -321,6 +360,8 @@ equity 1.094370e+09 53.3 ... 3.390706e+09 56.68
321
360
 
322
361
  ### 現金流量表
323
362
  ``` Python
363
+ from neurostats_API.utils import StatsFetcher
364
+ fetcher = StatsFetcher()
324
365
  ticker = 2330 # 換成tw50內任意ticker
325
366
  stats_fetcher.get_cash_flow(ticker)
326
367
  ```
@@ -400,6 +441,9 @@ stats_fetcher.get_cash_flow(ticker)
400
441
 
401
442
  > 大部分資料缺失是因為尚未計算,僅先填上已經有的資料
402
443
 
444
+
445
+
446
+
403
447
  ## cli 範例輸入
404
448
  ```
405
449
  python ./cli.py --ticker 1101
@@ -437,4 +481,5 @@ daily_data
437
481
  > 這裡有Nan是因為本益比與P/B等資料沒有爬到最新的時間
438
482
 
439
483
  ## TODO
484
+ - 將utils/fetcher.py中的功能切分到fetchers資料夾中
440
485
 
@@ -2,46 +2,78 @@
2
2
 
3
3
  - [檔案架構](#檔案架構)
4
4
  - [使用方法](#使用方法)
5
- - [import](#import)
5
+ - [下載](#下載)
6
6
  - [價值投資](#得到最新一期的評價資料與歷年評價)
7
7
  - [財務分析-重要指標](#財務分析-重要指標)
8
8
  - [月營收表](#回傳月營收表)
9
+ - [損益表](#損益表)
9
10
  - [資產負債表](#資產負債表)
10
11
  - [現金流量表](#現金流量表)
11
12
 
12
13
  ## 檔案架構
13
14
 
14
15
  ```
15
- ./
16
- ├── cli.py
17
- ├── main.py
16
+ ├── neurostats_API
17
+ │   ├── __init__.py
18
+ │   ├── cli.py
19
+ │   ├── main.py
20
+ │   ├── fetchers
21
+ │   │   ├── __init__.py
22
+ │   │   ├── base.py
23
+ │   │   ├── finance_overview.py
24
+ │   │   ├── tech.py
25
+ │   │   └── value_invest.py
26
+ │   ├── tools
27
+ │   │   ├── finance_overview_dict.yaml
28
+ │   │   ├── profit_lose.yaml
29
+ │   │   └── seasonal_data_field_dict.txt
30
+ │   └── utils
31
+ │   ├──__init__.py
32
+ │   ├── data_process.py
33
+ │   ├── datetime.py
34
+ │   ├── db_client.py
35
+ │   └── fetcher.py
36
+ ├── test
37
+ │ ├── __init__.py
38
+ │ └── test_fetchers.py
39
+ ├── Makefile
40
+ ├── MANIFEST.in
18
41
  ├── README.md
19
42
  ├── requirement.txt
20
- ├── tw50_company_list.json
21
- └── utils
22
- ├── fetcher.py
23
- ├── __init__.py
24
- ```
25
-
26
- `main.py`: 執行檔
27
- `cli.py`: 命令輸入的檔案
28
- `utils`: 存放fetcher
29
- - `fetcher.py`: Service的主架構
30
- `tw50_company_list.json`: tw50的公司列表
31
-
32
- ## 使用方法
43
+ ├── setup.py
33
44
 
34
- ### import
35
- ```Python
36
- from utils import statsFetcher
37
- stats_fetcher = statsFetcher
45
+ ```
46
+ - `neurostats_API`: 主要的package運行內容
47
+ - `fetchers`: 回傳service內容的fetcher檔案夾
48
+ - `base.py`: 基本架構
49
+ - `value_invest.py`: iFa.ai -> 價值投資
50
+ - `finance_overview.py`: iFa.ai -> 財務分析 -> 重要指標
51
+ - `tech.py`: iFa.ai -> 技術指標
52
+ - `tools`: 存放各種設定檔與資料庫index對應領域的dictionary
53
+ - `utils`:
54
+ - `fetcher.py`: Service的舊主架構, 月營收, 損益表, 資產負債表, 資產收益表目前在這裡
55
+ - `data_process.py`: config資料的讀取
56
+ - `datetime.py`: 時間格式,包括日期,年度,月份,日,季度
57
+
58
+ ## 下載
59
+ ```
60
+ pip install neurostats-API
61
+ ```
62
+ ### 確認下載成功
63
+ ```Python
64
+ >>> import neurostats_API
65
+ >>> print(neurostats_API.__version__)
66
+ 0.0.5
38
67
  ```
39
68
 
40
69
  ### 得到最新一期的評價資料與歷年評價
41
70
  ``` Python
71
+ from neurostats_API.fetchers import ValueFetcher
42
72
  ticker = 2330 # 換成tw50內任意ticker
43
- stats_fetcher.get_value_sheet(ticker)
73
+ fetcher = ValueFetcher(ticker)
74
+ data = stats_fetcher.query_data()
44
75
  ```
76
+
45
77
  #### 回傳(2330為例)
46
78
  ```Python
47
79
  {
@@ -76,8 +108,10 @@ stats_fetcher.get_value_sheet(ticker)
76
108
 
77
109
  ### 回傳月營收表
78
110
  ``` Python
111
+ from neurostats_API.utils import StatsFetcher
79
112
  ticker = 2330 # 換成tw50內任意ticker
80
- stats_fetcher.get_month_revenue_sheet(ticker)
113
+ fetcher = StatsFetcher()
114
+ data = stats_fetcher.get_month_revenue_sheet(ticker)
81
115
  ```
82
116
 
83
117
  #### 回傳
@@ -126,9 +160,10 @@ YoY_10 None None ... None None
126
160
  ### 財務分析: 重要指標
127
161
  對應https://ifa.ai/tw-stock/2330/finance-overview
128
162
  ```Python
129
- from fetchers import FinanceOverviewFetcher
130
- fetcher = FinanceOverviewFetcher(2330) # 參數內可換成其他股票代碼
131
- fetcher.query_data()
163
+ from neurostats_API.fetchers import FinanceOverviewFetcher
164
+ ticker = "2330"
165
+ fetcher = FinanceOverviewFetcher(ticker = "2330")
166
+ data = fetcher.query_data()
132
167
  ```
133
168
 
134
169
  #### 回傳
@@ -208,8 +243,10 @@ markdown
208
243
 
209
244
  ### 損益表
210
245
  ```Python
246
+ from neurostats_API.utils import StatsFetcher
247
+ fetcher = StatsFetcher()
211
248
  ticker = 2330 # 換成tw50內任意ticker
212
- stats_fetcher.get_profit_lose(ticker)
249
+ data = fetcher.get_profit_lose(ticker)
213
250
  ```
214
251
 
215
252
  #### 回傳
@@ -254,6 +291,8 @@ stats_fetcher.get_profit_lose(ticker)
254
291
 
255
292
  ### 資產負債表
256
293
  ``` Python
294
+ from neurostats_API.utils import StatsFetcher
295
+ fetcher = StatsFetcher()
257
296
  ticker = 2330 # 換成tw50內任意ticker
258
297
  stats_fetcher.get_balance_sheet(ticker)
259
298
  ```
@@ -311,6 +350,8 @@ equity 1.094370e+09 53.3 ... 3.390706e+09 56.68
311
350
 
312
351
  ### 現金流量表
313
352
  ``` Python
353
+ from neurostats_API.utils import StatsFetcher
354
+ fetcher = StatsFetcher()
314
355
  ticker = 2330 # 換成tw50內任意ticker
315
356
  stats_fetcher.get_cash_flow(ticker)
316
357
  ```
@@ -390,6 +431,9 @@ stats_fetcher.get_cash_flow(ticker)
390
431
 
391
432
  > 大部分資料缺失是因為尚未計算,僅先填上已經有的資料
392
433
 
434
+
435
+
436
+
393
437
  ## cli 範例輸入
394
438
  ```
395
439
  python ./cli.py --ticker 1101
@@ -427,4 +471,5 @@ daily_data
427
471
  > 這裡有Nan是因為本益比與P/B等資料沒有爬到最新的時間
428
472
 
429
473
  ## TODO
474
+ - 將utils/fetcher.py中的功能切分到fetchers資料夾中
430
475
 
@@ -0,0 +1 @@
1
+ __version__='0.0.4'
@@ -0,0 +1,3 @@
1
+ from .base import StatsDateTime, StatsFetcher
2
+ from .finance_overview import FinanceOverviewFetcher
3
+ from .value_invest import ValueFetcher
@@ -3,9 +3,10 @@ import pandas as pd
3
3
  import json
4
4
  import pytz
5
5
  from datetime import datetime, timedelta, date
6
- from utils import StatsDateTime
6
+ from ..utils import StatsDateTime, StatsProcessor
7
7
  import yaml
8
- from .utils.db_client import shared_client
8
+ from ..utils import shared_client
9
+
9
10
 
10
11
  class StatsFetcher:
11
12
 
@@ -28,6 +29,7 @@ class StatsFetcher:
28
29
  'grand_total_growth': [f"YoY_{i}" for i in [1, 3, 5, 10]]
29
30
  }
30
31
 
32
+
31
33
  def prepare_query(self):
32
34
  return [
33
35
  {
@@ -53,7 +55,3 @@ class StatsFetcher:
53
55
  season = (month - 1) // 3 + 1
54
56
 
55
57
  return StatsDateTime(date, year, month, day, season)
56
-
57
-
58
- class StatsProcessor:
59
- pass
@@ -1,7 +1,8 @@
1
- from .base import StatsFetcher, StatsProcessor, StatsDateTime
1
+ from .base import StatsFetcher, StatsDateTime
2
2
  import json
3
3
  import pandas as pd
4
- from utils import StatsDateTime
4
+ from ..utils import StatsDateTime, StatsProcessor
5
+ import importlib.resources as pkg_resources
5
6
  import yaml
6
7
 
7
8
 
@@ -13,11 +14,8 @@ class FinanceOverviewFetcher(StatsFetcher):
13
14
  def __init__(self, ticker):
14
15
  super().__init__(ticker)
15
16
 
16
- with open("./tools/finance_overview_dict.yaml") as f:
17
- self.target_fields = yaml.safe_load(f)
18
-
19
- with open("./tools/seasonal_data_field_dict.txt") as f:
20
- self.inverse_dict = json.load(f)
17
+ self.target_fields = StatsProcessor.load_yaml("finance_overview_dict.yaml")
18
+ self.inverse_dict = StatsProcessor.load_txt("seasonal_data_field_dict.txt", json_load=True)
21
19
 
22
20
  def prepare_query(self, target_year, target_season):
23
21
 
@@ -1,7 +1,7 @@
1
- from .base import StatsFetcher, StatsProcessor
1
+ from .base import StatsFetcher
2
2
  from datetime import datetime, timedelta, date
3
3
  import pandas as pd
4
- from utils import StatsDateTime
4
+ from ..utils import StatsDateTime, StatsProcessor
5
5
 
6
6
 
7
7
  class ValueFetcher(StatsFetcher):
@@ -0,0 +1,136 @@
1
+ # 財務概況
2
+ revenue:
3
+ field: 營業收入合計
4
+ value: value
5
+
6
+ gross_profit:
7
+ field: 營業毛利(毛損)淨額
8
+ value: value
9
+
10
+ operating_income:
11
+ field: 營業利益(損失)
12
+ value: value
13
+
14
+ net_income:
15
+ field: 本期淨利(淨損)
16
+ value: value
17
+
18
+ # TODO: 以下所爬到的資料都是累計的,Ifa有額外計算當季的變化量
19
+ operating_cash_flow:
20
+ field: 營業活動之淨現金流入(流出)
21
+ value: value
22
+
23
+ invest_cash_flow:
24
+ field: 投資活動之淨現金流入(流出)
25
+ value: value
26
+
27
+ financing_cash_flow:
28
+ field: 籌資活動之淨現金流入(流出)
29
+ value: value
30
+
31
+ fcf:
32
+ field: 本期現金及約當現金增加(減少)數
33
+ value: value
34
+ # ^^^ 以上皆需要額外在DataBase處理
35
+
36
+ # 每股財務狀況
37
+ capital:
38
+ field: 普通股股本
39
+ value: value
40
+ eps:
41
+ field: 基本每股盈餘
42
+ value: value
43
+
44
+ # 獲利能力
45
+ total_asset:
46
+ field: 資產總額
47
+ value: value
48
+
49
+ equity:
50
+ field: 權益總額
51
+ value: value
52
+
53
+ net_income_before_tax:
54
+ field: 稅前淨利(淨損)
55
+ value: value
56
+
57
+ interest:
58
+ field: 利息收入
59
+ value: value
60
+
61
+ operating_expenses:
62
+ field: 營業費用合計
63
+ value: value
64
+
65
+ net_income_rate:
66
+ field: 本期淨利(淨損)
67
+ value: percentage
68
+ # 成長動能
69
+ revenue_YoY:
70
+ field: 營業收入合計
71
+ value: YoY_1
72
+
73
+ gross_prof_YoY:
74
+ field: 營業毛利(毛損)淨額
75
+ value: YoY_1
76
+
77
+ operating_income_YoY:
78
+ field: 營業利益(損失)
79
+ value: YoY_1
80
+
81
+ net_income_YoY:
82
+ field: 本期淨利(淨損)
83
+ value: YoY_1
84
+
85
+ operating_cash_flow_YoY:
86
+ field: 營業活動之淨現金流入(流出)
87
+ value: YoY_1
88
+
89
+ # operating_cash_flow_per_share_YoY:
90
+ # field: 每股營業現金流年成長率
91
+ # value: YoY_1
92
+ # 營運指標
93
+ account_receive:
94
+ field: 應收帳款淨額
95
+ value: value
96
+
97
+ account_pay:
98
+ field: 應付帳款
99
+ value: value
100
+
101
+ inventories:
102
+ field: 存貨
103
+ value: value
104
+
105
+ operating_cost:
106
+ field: 營業成本合計
107
+ value: value
108
+
109
+ application:
110
+ field: 不動產、廠房及設備
111
+ value: value
112
+
113
+ # 財務韌性
114
+ current_assets:
115
+ field: 流動資產合計
116
+ value: value
117
+
118
+ current_liabilities:
119
+ field: 流動負債合計
120
+ value: value
121
+
122
+ total_liabilities:
123
+ field: 負債總額
124
+ value: value
125
+
126
+ #
127
+ cash_and_cash_equivalents:
128
+ field: 現金及約當現金
129
+ value: value
130
+
131
+ interest_expense:
132
+ field: 利息費用
133
+ value: value
134
+
135
+
136
+
@@ -0,0 +1,93 @@
1
+ profit_lose: # 總營收表
2
+ mode: value_and_percentage
3
+
4
+ grand_total_profit_lose:
5
+ mode: grand_total_values
6
+
7
+ revenue:
8
+ mode: growth
9
+ target_index: 營業收入合計
10
+
11
+ grand_total_revenue:
12
+ mode: grand_total_values
13
+ target_index: 營業收入合計
14
+
15
+ gross_profit:
16
+ mode: growth
17
+ target_index: 營業毛利(毛損)淨額
18
+
19
+ grand_total_gross_profit:
20
+ mode: grand_total_growth
21
+ target_index: 營業毛利(毛損)淨額
22
+
23
+ gross_profit_percentage:
24
+ mode: percentage
25
+ target_index: 營業毛利(毛損)淨額
26
+
27
+ grand_total_gross_profit_percentage:
28
+ mode: grand_total_percentage
29
+ target_index: 營業毛利(毛損)淨額
30
+ # 營利
31
+ operating_income:
32
+ mode: growth
33
+ target_index: 營業利益(損失)
34
+
35
+ grand_total_operating_income:
36
+ mode: grand_total_growth
37
+ target_index: 營業利益(損失)
38
+
39
+ operating_income_percentage:
40
+ mode: percentage
41
+ target_index: 營業利益(損失)
42
+
43
+ grand_total_operating_income_percentage:
44
+ mode: grand_total_percentage
45
+ target_index: 營業利益(損失)
46
+ # 稅前淨利
47
+ net_income_before_tax:
48
+ mode: growth
49
+ target_index: 稅前淨利(淨損)
50
+
51
+ grand_total_net_income_before_tax:
52
+ mode: grand_total_growth
53
+ target_index: 稅前淨利(淨損)
54
+
55
+ net_income_before_tax_percentage:
56
+ mode: percentage
57
+ target_index: 稅前淨利(淨損)
58
+
59
+ grand_total_net_income_before_tax_percentage:
60
+ mode: grand_total_percentage
61
+ target_index: 稅前淨利(淨損)
62
+ # 本期淨利
63
+ net_income:
64
+ mode: growth
65
+ target_index: 本期淨利(淨損)
66
+
67
+ grand_total_net_income:
68
+ mode: grand_total_growth
69
+ target_index: 本期淨利(淨損)
70
+
71
+ net_income_percentage:
72
+ mode: percentage
73
+ target_index: 本期淨利(淨損)
74
+
75
+ grand_total_income_percentage:
76
+ mode: grand_total_percentage
77
+ target_index: 本期淨利(淨損)
78
+ # EPS
79
+ EPS:
80
+ mode: value
81
+ target_index: 稀釋每股盈餘
82
+
83
+ EPS_growth:
84
+ mode: growth
85
+ target_index: 稀釋每股盈餘
86
+
87
+ grand_total_EPS:
88
+ mode: grand_total
89
+ target_index: 稀釋每股盈餘
90
+
91
+ grand_total_EPS_growth:
92
+ mode: grand_total_growth
93
+ target_index: 稀釋每股盈餘
@@ -0,0 +1,158 @@
1
+ {
2
+ "現金及約當現金": "balance_sheet",
3
+ "透過損益按公允價值衡量之金融資產-流動": "balance_sheet",
4
+ "透過其他綜合損益按公允價值衡量之金融資產-流動": "balance_sheet",
5
+ "備供出售金融資產-流動淨額": "balance_sheet",
6
+ "應收票據淨額": "balance_sheet",
7
+ "應收帳款淨額": "balance_sheet",
8
+ "應收帳款-關係人淨額": "balance_sheet",
9
+ "其他應收款淨額": "balance_sheet",
10
+ "其他應收款-關係人淨額": "balance_sheet",
11
+ "本期所得稅資產": "balance_sheet",
12
+ "存貨": "balance_sheet",
13
+ "預付款項": "balance_sheet",
14
+ "其他流動資產": "balance_sheet",
15
+ "流動資產合計": "balance_sheet",
16
+ "以成本衡量之金融資產-非流動淨額": "balance_sheet",
17
+ "採用權益法之投資淨額": "balance_sheet",
18
+ "不動產、廠房及設備": "balance_sheet",
19
+ "投資性不動產淨額": "balance_sheet",
20
+ "無形資產": "balance_sheet",
21
+ "遞延所得稅資產": "balance_sheet",
22
+ "其他非流動資產": "balance_sheet",
23
+ "非流動資產合計": "balance_sheet",
24
+ "資產總額": "balance_sheet",
25
+ "短期借款": "balance_sheet",
26
+ "透過損益按公允價值衡量之金融負債-流動": "balance_sheet",
27
+ "應付票據": "balance_sheet",
28
+ "應付帳款": "balance_sheet",
29
+ "應付帳款-關係人": "balance_sheet",
30
+ "其他應付款": "balance_sheet",
31
+ "其他應付款項-關係人": "balance_sheet",
32
+ "本期所得稅負債": "balance_sheet",
33
+ "負債準備-流動": "balance_sheet",
34
+ "其他流動負債": "balance_sheet",
35
+ "流動負債合計": "balance_sheet",
36
+ "遞延所得稅負債": "balance_sheet",
37
+ "其他非流動負債": "balance_sheet",
38
+ "非流動負債合計": "balance_sheet",
39
+ "負債總額": "balance_sheet",
40
+ "普通股股本": "balance_sheet",
41
+ "股本合計": "balance_sheet",
42
+ "資本公積-發行溢價": "balance_sheet",
43
+ "資本公積-其他": "balance_sheet",
44
+ "資本公積合計": "balance_sheet",
45
+ "法定盈餘公積": "balance_sheet",
46
+ "特別盈餘公積": "balance_sheet",
47
+ "未分配盈餘(或待彌補虧損)": "balance_sheet",
48
+ "保留盈餘合計": "balance_sheet",
49
+ "其他權益合計": "balance_sheet",
50
+ "庫藏股票": "balance_sheet",
51
+ "歸屬於母公司業主之權益合計": "balance_sheet",
52
+ "非控制權益": "balance_sheet",
53
+ "權益總額": "balance_sheet",
54
+ "負債及權益總計": "balance_sheet",
55
+ "待註銷股本股數(單位:股)": "balance_sheet",
56
+ "預收股款(權益項下)之約當發行股數(單位:股)": "balance_sheet",
57
+ "母公司暨子公司所持有之母公司庫藏股股數(單位:股)": "balance_sheet",
58
+ "繼續營業單位稅前淨利(淨損)": "cash_flow",
59
+ "停業單位稅前淨利(淨損)": "cash_flow",
60
+ "本期稅前淨利(淨損)": "cash_flow",
61
+ "折舊費用": "cash_flow",
62
+ "攤銷費用": "cash_flow",
63
+ "透過損益按公允價值衡量金融資產及負債之淨損失(利益)": "cash_flow",
64
+ "利息費用": "cash_flow",
65
+ "利息收入": "cash_flow",
66
+ "採用權益法認列之關聯企業及合資損失(利益)之份額": "cash_flow",
67
+ "處分及報廢不動產、廠房及設備損失(利益)": "cash_flow",
68
+ "不動產、廠房及設備轉列費用數": "cash_flow",
69
+ "處分無形資產損失(利益)": "cash_flow",
70
+ "處分投資損失(利益)": "cash_flow",
71
+ "處分採用權益法之投資損失(利益)": "cash_flow",
72
+ "未實現銷貨利益(損失)": "cash_flow",
73
+ "已實現銷貨損失(利益)": "cash_flow",
74
+ "未實現外幣兌換損失(利益)": "cash_flow",
75
+ "收益費損項目合計": "cash_flow",
76
+ "強制透過損益按公允價值衡量之金融資產(增加)減少": "cash_flow",
77
+ "應收票據(增加)減少": "cash_flow",
78
+ "應收帳款(增加)減少": "cash_flow",
79
+ "存貨(增加)減少": "cash_flow",
80
+ "其他流動資產(增加)減少": "cash_flow",
81
+ "其他營業資產(增加)減少": "cash_flow",
82
+ "與營業活動相關之資產之淨變動合計": "cash_flow",
83
+ "應付票據增加(減少)": "cash_flow",
84
+ "應付帳款增加(減少)": "cash_flow",
85
+ "其他流動負債增加(減少)": "cash_flow",
86
+ "淨確定福利負債增加(減少)": "cash_flow",
87
+ "與營業活動相關之負債之淨變動合計": "cash_flow",
88
+ "與營業活動相關之資產及負債之淨變動合計": "cash_flow",
89
+ "調整項目合計": "cash_flow",
90
+ "營運產生之現金流入(流出)": "cash_flow",
91
+ "收取之利息": "cash_flow",
92
+ "支付之利息": "cash_flow",
93
+ "退還(支付)之所得稅": "cash_flow",
94
+ "營業活動之淨現金流入(流出)": "cash_flow",
95
+ "取得透過其他綜合損益按公允價值衡量之金融資產": "cash_flow",
96
+ "處分透過其他綜合損益按公允價值衡量之金融資產": "cash_flow",
97
+ "取得備供出售金融資產": "cash_flow",
98
+ "處分備供出售金融資產": "cash_flow",
99
+ "取得採用權益法之投資": "cash_flow",
100
+ "處分採用權益法之投資": "cash_flow",
101
+ "取得不動產、廠房及設備": "cash_flow",
102
+ "處分不動產、廠房及設備": "cash_flow",
103
+ "存出保證金增加": "cash_flow",
104
+ "存出保證金減少": "cash_flow",
105
+ "取得無形資產": "cash_flow",
106
+ "其他非流動資產增加": "cash_flow",
107
+ "收取之股利": "cash_flow",
108
+ "投資活動之淨現金流入(流出)": "cash_flow",
109
+ "短期借款增加": "cash_flow",
110
+ "短期借款減少": "cash_flow",
111
+ "存入保證金增加": "cash_flow",
112
+ "存入保證金減少": "cash_flow",
113
+ "發放現金股利": "cash_flow",
114
+ "其他籌資活動": "cash_flow",
115
+ "籌資活動之淨現金流入(流出)": "cash_flow",
116
+ "匯率變動對現金及約當現金之影響": "cash_flow",
117
+ "本期現金及約當現金增加(減少)數": "cash_flow",
118
+ "期初現金及約當現金餘額": "cash_flow",
119
+ "期末現金及約當現金餘額": "cash_flow",
120
+ "資產負債表帳列之現金及約當現金": "cash_flow",
121
+ "其他符合國際會計準則第七號現金及約當現金定義之項目": "cash_flow",
122
+ "銷貨收入": "profit_lose",
123
+ "銷貨退回": "profit_lose",
124
+ "銷貨折讓": "profit_lose",
125
+ "銷貨收入淨額": "profit_lose",
126
+ "營業收入合計": "profit_lose",
127
+ "銷貨成本": "profit_lose",
128
+ "營業成本合計": "profit_lose",
129
+ "營業毛利(毛損)": "profit_lose",
130
+ "未實現銷貨(損)益": "profit_lose",
131
+ "已實現銷貨(損)益": "profit_lose",
132
+ "營業毛利(毛損)淨額": "profit_lose",
133
+ "推銷費用": "profit_lose",
134
+ "管理費用": "profit_lose",
135
+ "研究發展費用": "profit_lose",
136
+ "營業費用合計": "profit_lose",
137
+ "營業利益(損失)": "profit_lose",
138
+ "其他收入": "profit_lose",
139
+ "其他利益及損失淨額": "profit_lose",
140
+ "採用權益法認列之關聯企業及合資損益之份額淨額": "profit_lose",
141
+ "營業外收入及支出合計": "profit_lose",
142
+ "稅前淨利(淨損)": "profit_lose",
143
+ "所得稅費用(利益)合計": "profit_lose",
144
+ "繼續營業單位本期淨利(淨損)": "profit_lose",
145
+ "本期淨利(淨損)": "profit_lose",
146
+ "確定福利計畫之再衡量數": "profit_lose",
147
+ "透過其他綜合損益按公允價值衡量之權益工具投資未實現評價損益": "profit_lose",
148
+ "國外營運機構財務報表換算之兌換差額": "profit_lose",
149
+ "備供出售金融資產未實現評價損益": "profit_lose",
150
+ "其他綜合損益(淨額)": "profit_lose",
151
+ "本期綜合損益總額": "profit_lose",
152
+ "母公司業主(淨利∕損)": "profit_lose",
153
+ "非控制權益(淨利∕損)": "profit_lose",
154
+ "母公司業主(綜合損益)": "profit_lose",
155
+ "非控制權益(綜合損益)": "profit_lose",
156
+ "基本每股盈餘": "profit_lose",
157
+ "稀釋每股盈餘": "profit_lose"
158
+ }
@@ -0,0 +1,4 @@
1
+ from .datetime import StatsDateTime
2
+ from .db_client import shared_client
3
+ from .data_process import StatsProcessor
4
+ from .fetcher import StatsFetcher
@@ -0,0 +1,18 @@
1
+ from importlib.resources import files
2
+ import json
3
+ import yaml
4
+
5
+ class StatsProcessor:
6
+ @classmethod
7
+ def load_txt(cls, filename, json_load = True):
8
+ txt_path = files('neurostats_API.tools').joinpath(filename)
9
+ with open(txt_path, 'r', encoding='utf-8') as f:
10
+ data = json.load(f) if (json_load) else f.read()
11
+ return data
12
+ @classmethod
13
+ def load_yaml(cls, filename):
14
+ yaml_path = files('neurostats_API.tools').joinpath(filename)
15
+ with open(yaml_path, 'r', encoding='utf-8') as f:
16
+ data = yaml.safe_load(f)
17
+
18
+ return data
@@ -1,8 +1,9 @@
1
- from .utils.db_client import shared_client
1
+ from .db_client import shared_client
2
2
  import pandas as pd
3
3
  import json
4
4
  import pytz
5
5
  from datetime import datetime, timedelta, date
6
+ from .data_process import StatsProcessor
6
7
  import yaml
7
8
 
8
9
 
@@ -14,10 +15,7 @@ class StatsFetcher:
14
15
 
15
16
  self.timezone = pytz.timezone("Asia/Taipei")
16
17
 
17
- self.inverse_dict = dict()
18
-
19
- with open("./tools/seasonal_data_field_dict.txt") as f:
20
- self.inverse_dict = json.load(f)
18
+ self.inverse_dict = StatsProcessor.load_txt("seasonal_data_field_dict.txt", json_load=True)
21
19
 
22
20
  self.seasons = ["01", "02", "03", "04"]
23
21
 
@@ -326,28 +324,6 @@ class StatsFetcher:
326
324
  "seasonal_data.season": 1
327
325
  }})
328
326
 
329
- # self.pipeline.append({
330
- # "$group": {
331
- # "_id": {
332
- # "ticker": "$ticker",
333
- # "company_name": "$company_name"
334
- # },
335
- # "seasonal_data": {
336
- # "$push": "$seasonal_data.balance_sheet"
337
- # }
338
- # }
339
- # })
340
-
341
- # self.pipeline.append({
342
- # "$project": {
343
- # "ticker": "$_id.ticker",
344
- # "company_name": "$_id.company_name",
345
- # "seasonal_data": {
346
- # "balance_sheet": "$seasonal_data"
347
- # }
348
- # }
349
- # })
350
-
351
327
  fetched_datas = list(self.collection.aggregate(self.pipeline))
352
328
 
353
329
  return fetched_datas
@@ -640,12 +616,14 @@ class StatsFetcher:
640
616
  """
641
617
  today_dict = self._get_today()
642
618
 
643
- today = today_dict['today'].strftime("%Y-%m-%d")
619
+ today = today_dict['today']
620
+ target_season = ((today.month - 1) // 3) + 1
644
621
 
645
622
  start_date = "2014-01-01"
623
+ end_date = today.strftime("%Y-%m-%d")
646
624
 
647
- query_data = self.query_seasonal_data(ticker, start_date, today,
648
- "balance_sheet")
625
+ query_data = self.query_seasonal_data(ticker, start_date, end_date,
626
+ "balance_sheet", target_season=target_season)
649
627
 
650
628
  return_dict = {
651
629
  "ticker": query_data[0]['ticker'],
@@ -894,8 +872,7 @@ class StatsFetcher:
894
872
  """
895
873
  today_dict = self._get_today()
896
874
 
897
- with open(f"./tools/profit_lose.yaml", 'r') as f:
898
- table_settings = yaml.safe_load(f)
875
+ table_settings = StatsProcessor.load_yaml("profit_lose.yaml")
899
876
  today = today_dict['today'].strftime("%Y-%m-%d")
900
877
  start_date = "2014-01-01"
901
878
 
@@ -972,13 +949,16 @@ class StatsFetcher:
972
949
  """
973
950
  today_dict = self._get_today()
974
951
 
975
- today = today_dict['today'].strftime("%Y-%m-%d")
952
+ today = today_dict['today']
953
+ this_season = (today.month - 1) // 3 + 1
976
954
  start_date = "2014-01-01"
955
+ end_date = today.strftime("%Y-%m-%d")
977
956
 
978
957
  query_data = self.query_seasonal_data(ticker,
979
958
  start_date=start_date,
980
- end_date=today,
981
- sheet='cash_flow')
959
+ end_date=end_date,
960
+ sheet='cash_flow',
961
+ target_season=this_season)
982
962
 
983
963
  index_names = []
984
964
 
@@ -1074,64 +1054,4 @@ class StatsFetcher:
1074
1054
  return_dict['CASHI'] = CASHI_table
1075
1055
  return_dict['CASHF'] = CASHF_table
1076
1056
 
1077
- return return_dict
1078
-
1079
- def get_financial_sheet(self, ticker):
1080
- """
1081
- (尚未完成)
1082
- iFa.ai: 財務分析 -> 重要指標
1083
- """
1084
- # Not implemented !!!!
1085
- return
1086
- today = datetime.today()
1087
- this_year = today.year
1088
- start_date = (f"{this_year}-01-01")
1089
- today = today.strftime("%Y-%m-%d")
1090
-
1091
- this_year_data = self.query_seasonal_data(ticker, start_date, today)
1092
-
1093
- latest_seasonal_data = this_year_data["seasonal_data"][-1]
1094
- all_time_data = this_year_data['seasonal_data']
1095
-
1096
- # retrieved_list = [
1097
- # "營業收入合計",
1098
- # "營業毛利(毛損)淨額",
1099
- # "營業利益(損失)",
1100
- # "本期淨利(淨損)",
1101
- # "營業活動之淨現金流入(流出)",
1102
- # "投資活動之淨現金流入(流出)",
1103
- # "籌資活動之淨現金流入(流出)",
1104
- # ]
1105
-
1106
- try:
1107
- single_month_revenue_dict = {
1108
- "revenue": {
1109
- "value":
1110
- latest_seasonal_data['profit_lose']["營業收入合計"],
1111
- "accumulation":
1112
- self._accumulate(all_time_data, 'profit_lose', "營業收入合計"),
1113
- "name":
1114
- '營業收入'
1115
- }
1116
- }
1117
- except:
1118
- try:
1119
- single_month_revenue_dict = {
1120
- "revenue": {
1121
- "value":
1122
- latest_seasonal_data['profit_lose']["利息收入"],
1123
- "accumulation":
1124
- self._accumulate(all_time_data, 'profit_lose', "利息收入"),
1125
- "name":
1126
- '利息收入'
1127
- }
1128
- }
1129
- except:
1130
- single_month_revenue_dict = {
1131
- "revenue": {
1132
- "value": None,
1133
- "accumulation": None,
1134
- "name": "營業收入"
1135
- }
1136
- }
1137
- return_dict.update()
1057
+ return return_dict
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats-API
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -12,46 +12,78 @@ Description-Content-Type: text/markdown
12
12
 
13
13
  - [檔案架構](#檔案架構)
14
14
  - [使用方法](#使用方法)
15
- - [import](#import)
15
+ - [下載](#下載)
16
16
  - [價值投資](#得到最新一期的評價資料與歷年評價)
17
17
  - [財務分析-重要指標](#財務分析-重要指標)
18
18
  - [月營收表](#回傳月營收表)
19
+ - [損益表](#損益表)
19
20
  - [資產負債表](#資產負債表)
20
21
  - [現金流量表](#現金流量表)
21
22
 
22
23
  ## 檔案架構
23
24
 
24
25
  ```
25
- ./
26
- ├── cli.py
27
- ├── main.py
26
+ ├── neurostats_API
27
+ │   ├── __init__.py
28
+ │   ├── cli.py
29
+ │   ├── main.py
30
+ │   ├── fetchers
31
+ │   │   ├── __init__.py
32
+ │   │   ├── base.py
33
+ │   │   ├── finance_overview.py
34
+ │   │   ├── tech.py
35
+ │   │   └── value_invest.py
36
+ │   ├── tools
37
+ │   │   ├── finance_overview_dict.yaml
38
+ │   │   ├── profit_lose.yaml
39
+ │   │   └── seasonal_data_field_dict.txt
40
+ │   └── utils
41
+ │   ├──__init__.py
42
+ │   ├── data_process.py
43
+ │   ├── datetime.py
44
+ │   ├── db_client.py
45
+ │   └── fetcher.py
46
+ ├── test
47
+ │ ├── __init__.py
48
+ │ └── test_fetchers.py
49
+ ├── Makefile
50
+ ├── MANIFEST.in
28
51
  ├── README.md
29
52
  ├── requirement.txt
30
- ├── tw50_company_list.json
31
- └── utils
32
- ├── fetcher.py
33
- ├── __init__.py
34
- ```
35
-
36
- `main.py`: 執行檔
37
- `cli.py`: 命令輸入的檔案
38
- `utils`: 存放fetcher
39
- - `fetcher.py`: Service的主架構
40
- `tw50_company_list.json`: tw50的公司列表
41
-
42
- ## 使用方法
53
+ ├── setup.py
43
54
 
44
- ### import
45
- ```Python
46
- from utils import statsFetcher
47
- stats_fetcher = statsFetcher
55
+ ```
56
+ - `neurostats_API`: 主要的package運行內容
57
+ - `fetchers`: 回傳service內容的fetcher檔案夾
58
+ - `base.py`: 基本架構
59
+ - `value_invest.py`: iFa.ai -> 價值投資
60
+ - `finance_overview.py`: iFa.ai -> 財務分析 -> 重要指標
61
+ - `tech.py`: iFa.ai -> 技術指標
62
+ - `tools`: 存放各種設定檔與資料庫index對應領域的dictionary
63
+ - `utils`:
64
+ - `fetcher.py`: Service的舊主架構, 月營收, 損益表, 資產負債表, 資產收益表目前在這裡
65
+ - `data_process.py`: config資料的讀取
66
+ - `datetime.py`: 時間格式,包括日期,年度,月份,日,季度
67
+
68
+ ## 下載
69
+ ```
70
+ pip install neurostats-API
71
+ ```
72
+ ### 確認下載成功
73
+ ```Python
74
+ >>> import neurostats_API
75
+ >>> print(neurostats_API.__version__)
76
+ 0.0.5
48
77
  ```
49
78
 
50
79
  ### 得到最新一期的評價資料與歷年評價
51
80
  ``` Python
81
+ from neurostats_API.fetchers import ValueFetcher
52
82
  ticker = 2330 # 換成tw50內任意ticker
53
- stats_fetcher.get_value_sheet(ticker)
83
+ fetcher = ValueFetcher(ticker)
84
+ data = stats_fetcher.query_data()
54
85
  ```
86
+
55
87
  #### 回傳(2330為例)
56
88
  ```Python
57
89
  {
@@ -86,8 +118,10 @@ stats_fetcher.get_value_sheet(ticker)
86
118
 
87
119
  ### 回傳月營收表
88
120
  ``` Python
121
+ from neurostats_API.utils import StatsFetcher
89
122
  ticker = 2330 # 換成tw50內任意ticker
90
- stats_fetcher.get_month_revenue_sheet(ticker)
123
+ fetcher = StatsFetcher()
124
+ data = stats_fetcher.get_month_revenue_sheet(ticker)
91
125
  ```
92
126
 
93
127
  #### 回傳
@@ -136,9 +170,10 @@ YoY_10 None None ... None None
136
170
  ### 財務分析: 重要指標
137
171
  對應https://ifa.ai/tw-stock/2330/finance-overview
138
172
  ```Python
139
- from fetchers import FinanceOverviewFetcher
140
- fetcher = FinanceOverviewFetcher(2330) # 參數內可換成其他股票代碼
141
- fetcher.query_data()
173
+ from neurostats_API.fetchers import FinanceOverviewFetcher
174
+ ticker = "2330"
175
+ fetcher = FinanceOverviewFetcher(ticker = "2330")
176
+ data = fetcher.query_data()
142
177
  ```
143
178
 
144
179
  #### 回傳
@@ -218,8 +253,10 @@ markdown
218
253
 
219
254
  ### 損益表
220
255
  ```Python
256
+ from neurostats_API.utils import StatsFetcher
257
+ fetcher = StatsFetcher()
221
258
  ticker = 2330 # 換成tw50內任意ticker
222
- stats_fetcher.get_profit_lose(ticker)
259
+ data = fetcher.get_profit_lose(ticker)
223
260
  ```
224
261
 
225
262
  #### 回傳
@@ -264,6 +301,8 @@ stats_fetcher.get_profit_lose(ticker)
264
301
 
265
302
  ### 資產負債表
266
303
  ``` Python
304
+ from neurostats_API.utils import StatsFetcher
305
+ fetcher = StatsFetcher()
267
306
  ticker = 2330 # 換成tw50內任意ticker
268
307
  stats_fetcher.get_balance_sheet(ticker)
269
308
  ```
@@ -321,6 +360,8 @@ equity 1.094370e+09 53.3 ... 3.390706e+09 56.68
321
360
 
322
361
  ### 現金流量表
323
362
  ``` Python
363
+ from neurostats_API.utils import StatsFetcher
364
+ fetcher = StatsFetcher()
324
365
  ticker = 2330 # 換成tw50內任意ticker
325
366
  stats_fetcher.get_cash_flow(ticker)
326
367
  ```
@@ -400,6 +441,9 @@ stats_fetcher.get_cash_flow(ticker)
400
441
 
401
442
  > 大部分資料缺失是因為尚未計算,僅先填上已經有的資料
402
443
 
444
+
445
+
446
+
403
447
  ## cli 範例輸入
404
448
  ```
405
449
  python ./cli.py --ticker 1101
@@ -437,4 +481,5 @@ daily_data
437
481
  > 這裡有Nan是因為本益比與P/B等資料沒有爬到最新的時間
438
482
 
439
483
  ## TODO
484
+ - 將utils/fetcher.py中的功能切分到fetchers資料夾中
440
485
 
@@ -1,3 +1,4 @@
1
+ MANIFEST.in
1
2
  README.md
2
3
  setup.py
3
4
  neurostats_API/__init__.py
@@ -15,7 +16,11 @@ neurostats_API/fetchers/month_revenue.py
15
16
  neurostats_API/fetchers/profit_lose.py
16
17
  neurostats_API/fetchers/tech.py
17
18
  neurostats_API/fetchers/value_invest.py
19
+ neurostats_API/tools/finance_overview_dict.yaml
20
+ neurostats_API/tools/profit_lose.yaml
21
+ neurostats_API/tools/seasonal_data_field_dict.txt
18
22
  neurostats_API/utils/__init__.py
23
+ neurostats_API/utils/data_process.py
19
24
  neurostats_API/utils/datetime.py
20
25
  neurostats_API/utils/db_client.py
21
26
  neurostats_API/utils/fetcher.py
@@ -2,15 +2,16 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neurostats_API',
5
- version='0.0.3',
5
+ version='0.0.4',
6
6
  long_description=open('README.md', 'r', encoding='utf-8').read(),
7
7
  long_description_content_type='text/markdown',
8
8
  install_requires=[
9
9
  ],
10
10
  author='JasonWang@Neurowatt',
11
11
  packages=find_packages(exclude=['.venv', 'test*', 'data_in_db', '.pytest_cache']),
12
- package_dir={'neurostats_service': 'src'},
13
- package_data={'neurostats_service': ['tools/*.yaml']},
12
+ include_package_data=True,
13
+ # package_dir={'neurostats_service': 'src'},
14
+ package_data={'neurostats_API': ['tools/*.yaml', 'tools/*.txt']},
14
15
  author_email='jason@neurowatt.ai',
15
16
  description='The service of NeuroStats website',
16
17
  url='https://github.com/NeurowattStats/NeuroStats_API.git',
@@ -1,10 +1,11 @@
1
1
  import pytest
2
2
  import pandas as pd
3
3
  import yaml
4
+ from neurostats_API.utils import StatsProcessor
4
5
 
5
6
 
6
7
  def test_value():
7
- from fetchers.value_invest import ValueFetcher
8
+ from neurostats_API.fetchers import ValueFetcher
8
9
  fetcher = ValueFetcher(ticker='2330')
9
10
 
10
11
  fetched_data = fetcher.query_data()
@@ -16,21 +17,46 @@ def test_value():
16
17
  assert isinstance(fetched_data['yearly_data'], pd.DataFrame)
17
18
 
18
19
  def test_profit_lose():
19
- from utils.fetcher import StatsFetcher
20
+ from neurostats_API.utils import StatsFetcher
20
21
 
21
22
  fetcher = StatsFetcher()
22
23
 
23
24
  data = fetcher.get_profit_lose("2330")
24
25
 
25
- with open(f"./tools/profit_lose.yaml", 'r') as f:
26
- table_settings = yaml.safe_load(f)
26
+ table_settings = StatsProcessor.load_yaml("profit_lose.yaml")
27
27
 
28
28
  for key in table_settings.keys():
29
29
  assert key in data.keys()
30
30
 
31
+ def test_cash_flow():
32
+ from neurostats_API.utils import StatsFetcher
33
+
34
+ fetcher = StatsFetcher()
35
+ data = fetcher.get_cash_flow("2330")
36
+
37
+ assert("cash_flow" in data.keys())
38
+
39
+ def test_month_revenue():
40
+ from neurostats_API.utils import StatsFetcher
41
+
42
+ fetcher = StatsFetcher()
43
+ data = fetcher.get_month_revenue_sheet("2330")
44
+
45
+ assert("month_revenue" in data.keys())
46
+
47
+ def test_balance_sheet():
48
+ from neurostats_API.utils import StatsFetcher
49
+
50
+ fetcher = StatsFetcher()
51
+
52
+ data = fetcher.get_balance_sheet("2330")
53
+
54
+ table_settings = StatsProcessor.load_yaml("profit_lose.yaml")
55
+
56
+ "balance_sheet" in data.keys()
31
57
 
32
58
  def test_finance_overview():
33
- from fetchers import FinanceOverviewFetcher
59
+ from neurostats_API.fetchers import FinanceOverviewFetcher
34
60
  fetcher = FinanceOverviewFetcher(ticker='2330')
35
61
  fetched_data = fetcher.query_data()
36
62
 
@@ -1 +0,0 @@
1
- __version__='0.0.3'
@@ -1 +0,0 @@
1
- from .finance_overview import FinanceOverviewFetcher
@@ -1,2 +0,0 @@
1
- from .fetcher import StatsFetcher
2
- from .datetime import StatsDateTime
File without changes