neurostats-API 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- neurostats_API/__init__.py +1 -1
- neurostats_API/fetchers/__init__.py +3 -1
- neurostats_API/fetchers/base.py +4 -6
- neurostats_API/fetchers/finance_overview.py +5 -7
- neurostats_API/fetchers/value_invest.py +2 -2
- neurostats_API/tools/finance_overview_dict.yaml +136 -0
- neurostats_API/tools/profit_lose.yaml +93 -0
- neurostats_API/tools/seasonal_data_field_dict.txt +158 -0
- neurostats_API/utils/__init__.py +4 -2
- neurostats_API/utils/data_process.py +18 -0
- neurostats_API/utils/fetcher.py +16 -96
- {neurostats_API-0.0.3.dist-info → neurostats_API-0.0.4.dist-info}/METADATA +73 -28
- neurostats_API-0.0.4.dist-info/RECORD +23 -0
- neurostats_API-0.0.3.dist-info/RECORD +0 -19
- {neurostats_API-0.0.3.dist-info → neurostats_API-0.0.4.dist-info}/WHEEL +0 -0
- {neurostats_API-0.0.3.dist-info → neurostats_API-0.0.4.dist-info}/top_level.txt +0 -0
neurostats_API/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__='0.0.
|
1
|
+
__version__='0.0.4'
|
neurostats_API/fetchers/base.py
CHANGED
@@ -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
|
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,
|
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
|
-
|
17
|
-
|
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
|
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
|
+
}
|
neurostats_API/utils/__init__.py
CHANGED
@@ -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
|
neurostats_API/utils/fetcher.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
from .
|
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 =
|
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']
|
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,
|
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
|
-
|
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']
|
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=
|
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
|
+
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
|
-
- [
|
15
|
+
- [下載](#下載)
|
16
16
|
- [價值投資](#得到最新一期的評價資料與歷年評價)
|
17
17
|
- [財務分析-重要指標](#財務分析-重要指標)
|
18
18
|
- [月營收表](#回傳月營收表)
|
19
|
+
- [損益表](#損益表)
|
19
20
|
- [資產負債表](#資產負債表)
|
20
21
|
- [現金流量表](#現金流量表)
|
21
22
|
|
22
23
|
## 檔案架構
|
23
24
|
|
24
25
|
```
|
25
|
-
|
26
|
-
├──
|
27
|
-
├──
|
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
|
-
├──
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
141
|
-
fetcher
|
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
|
-
|
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
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
neurostats_API/__init__.py,sha256=NPQFEcbIrOIy8ny94U7Q-qMa0Plu6CXlbLuNwykqxyk,19
|
2
|
+
neurostats_API/cli.py,sha256=UJSWLIw03P24p-gkBb6JSEI5dW5U12UvLf1L8HjQD-o,873
|
3
|
+
neurostats_API/main.py,sha256=QcsfmWivg2Dnqw3MTJWiI0QvEiRs0VuH-BjwQHFCv00,677
|
4
|
+
neurostats_API/fetchers/__init__.py,sha256=k-pPWen3gQNr6d6DPFEXP1Q6SPC6TGIuIFf8w6r75YQ,137
|
5
|
+
neurostats_API/fetchers/balance_sheet.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
neurostats_API/fetchers/base.py,sha256=OxSCzvr9k-VS1n62skcjkSuGaeTBEQ2wNWlSPfXVSGE,1692
|
7
|
+
neurostats_API/fetchers/finance_overview.py,sha256=1D0k-beaXBZmBdSDgsZobLYvnMs1WtboGe_pW_38Atc,18287
|
8
|
+
neurostats_API/fetchers/month_revenue.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
neurostats_API/fetchers/profit_lose.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
neurostats_API/fetchers/tech.py,sha256=5XlIkiQvquRMpA-cFNlnb5_fDxVd8Hj3-ttZzbyZwuY,11396
|
11
|
+
neurostats_API/fetchers/value_invest.py,sha256=o0ZliV5ZwMPTtDV5oBSoZC_pZgcT7CsKVM39HznZYR4,2864
|
12
|
+
neurostats_API/tools/finance_overview_dict.yaml,sha256=Vvf8bv23NwJP8Yyw8DPS8c0_jjT_Wctnnz51SHS4AeI,2335
|
13
|
+
neurostats_API/tools/profit_lose.yaml,sha256=f8balMTcK9elMW0k1PtbZ_6kEobTQ51fcBzqpbMObkk,2086
|
14
|
+
neurostats_API/tools/seasonal_data_field_dict.txt,sha256=KlIIdTTdbvUd9TSDE9-gpzk2jt2ck_LdisX8cnrWMD4,7869
|
15
|
+
neurostats_API/utils/__init__.py,sha256=4av4zVMgUfsKY1Nb0TKOjOABt3gvgSRWsXaU-_PWttU,147
|
16
|
+
neurostats_API/utils/data_process.py,sha256=AeDWS9eHlHRqzfDKph-14GXERtHLSMKijsIrzZ0pPPo,595
|
17
|
+
neurostats_API/utils/datetime.py,sha256=I9CIgZdE5OMzUciOS5wvapOVEIrXG_0Qb6iDKfIod6c,574
|
18
|
+
neurostats_API/utils/db_client.py,sha256=Q3oDIhUdVY8S9-Jd7KcZ5X8fj2kz90Yv4e0w3uo77Tw,249
|
19
|
+
neurostats_API/utils/fetcher.py,sha256=EW7yA9LddX_fekYTCcfKB96URaetjzvqtE9aMLP8SPw,40957
|
20
|
+
neurostats_API-0.0.4.dist-info/METADATA,sha256=bzpZPqN4jrCw6UE-C090nCaCvOgjYDlEEvQOq6gNrjY,20285
|
21
|
+
neurostats_API-0.0.4.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
22
|
+
neurostats_API-0.0.4.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
|
23
|
+
neurostats_API-0.0.4.dist-info/RECORD,,
|
@@ -1,19 +0,0 @@
|
|
1
|
-
neurostats_API/__init__.py,sha256=qlp5d6WrvsWpBMMTlS9u6vXJyf2cioGX8eRd6yXw4pA,19
|
2
|
-
neurostats_API/cli.py,sha256=UJSWLIw03P24p-gkBb6JSEI5dW5U12UvLf1L8HjQD-o,873
|
3
|
-
neurostats_API/main.py,sha256=QcsfmWivg2Dnqw3MTJWiI0QvEiRs0VuH-BjwQHFCv00,677
|
4
|
-
neurostats_API/fetchers/__init__.py,sha256=9phlTye7iUXKKw3E0roPXjgfmCF2NMEH8NSrXQwc7pI,52
|
5
|
-
neurostats_API/fetchers/balance_sheet.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
neurostats_API/fetchers/base.py,sha256=JQNW-KDDLiXUc6aKmySZJvJLkrrRO5K1MrPU8oMIpK8,1713
|
7
|
-
neurostats_API/fetchers/finance_overview.py,sha256=RNWwTL2nJ15hG6eIF1D14eVq16oEGXjvI0MQUvCGQE4,18280
|
8
|
-
neurostats_API/fetchers/month_revenue.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
neurostats_API/fetchers/profit_lose.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
neurostats_API/fetchers/tech.py,sha256=5XlIkiQvquRMpA-cFNlnb5_fDxVd8Hj3-ttZzbyZwuY,11396
|
11
|
-
neurostats_API/fetchers/value_invest.py,sha256=vF1Ue11Du1g4UUWHl16iCSbj2j9UUG-F26Zn6OCkNKs,2862
|
12
|
-
neurostats_API/utils/__init__.py,sha256=kv9e0KvU8OMuyPV7VTeeXOVqtUFkI-5b1rBz6RrN098,69
|
13
|
-
neurostats_API/utils/datetime.py,sha256=I9CIgZdE5OMzUciOS5wvapOVEIrXG_0Qb6iDKfIod6c,574
|
14
|
-
neurostats_API/utils/db_client.py,sha256=Q3oDIhUdVY8S9-Jd7KcZ5X8fj2kz90Yv4e0w3uo77Tw,249
|
15
|
-
neurostats_API/utils/fetcher.py,sha256=1HAhDplJywjMWYn3uzU5--A2ux9rMQ-XTiDRm82Scmg,43498
|
16
|
-
neurostats_API-0.0.3.dist-info/METADATA,sha256=7gkcbJODqILoVd-16Yy-YG6bBrMcBI-r3sNuKjQc7Zk,18584
|
17
|
-
neurostats_API-0.0.3.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
18
|
-
neurostats_API-0.0.3.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
|
19
|
-
neurostats_API-0.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|