neurostats-API 0.0.21b0__py3-none-any.whl → 0.0.23__py3-none-any.whl

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.
Files changed (31) hide show
  1. neurostats_API/__init__.py +1 -1
  2. neurostats_API/fetchers/balance_sheet.py +152 -102
  3. neurostats_API/fetchers/base.py +93 -74
  4. neurostats_API/fetchers/cash_flow.py +143 -113
  5. neurostats_API/fetchers/finance_overview.py +28 -28
  6. neurostats_API/fetchers/institution.py +211 -97
  7. neurostats_API/fetchers/margin_trading.py +121 -94
  8. neurostats_API/fetchers/month_revenue.py +139 -105
  9. neurostats_API/fetchers/profit_lose.py +203 -108
  10. neurostats_API/fetchers/tech.py +117 -42
  11. neurostats_API/fetchers/tej_finance_report.py +248 -338
  12. neurostats_API/fetchers/value_invest.py +32 -12
  13. neurostats_API/tools/company_list/tw.json +2175 -0
  14. neurostats_API/tools/tej_db/tej_db_percent_index.yaml +0 -3
  15. neurostats_API/tools/tej_db/tej_db_skip_index.yaml +14 -1
  16. neurostats_API/tools/tej_db/tej_db_thousand_index.yaml +0 -5
  17. neurostats_API/utils/__init__.py +0 -1
  18. neurostats_API/utils/calculate_value.py +102 -1
  19. neurostats_API/utils/data_process.py +53 -19
  20. neurostats_API/utils/logger.py +21 -0
  21. {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23.dist-info}/METADATA +2 -2
  22. neurostats_API-0.0.23.dist-info/RECORD +35 -0
  23. neurostats_API/utils/fetcher.py +0 -1056
  24. neurostats_API-0.0.21b0.dist-info/RECORD +0 -34
  25. /neurostats_API/tools/{balance_sheet.yaml → twse/balance_sheet.yaml} +0 -0
  26. /neurostats_API/tools/{cash_flow_percentage.yaml → twse/cash_flow_percentage.yaml} +0 -0
  27. /neurostats_API/tools/{finance_overview_dict.yaml → twse/finance_overview_dict.yaml} +0 -0
  28. /neurostats_API/tools/{profit_lose.yaml → twse/profit_lose.yaml} +0 -0
  29. /neurostats_API/tools/{seasonal_data_field_dict.txt → twse/seasonal_data_field_dict.txt} +0 -0
  30. {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23.dist-info}/WHEEL +0 -0
  31. {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,11 @@ class ValueFetcher(StatsFetcher):
8
8
 
9
9
  def __init__(self, ticker: str, db_client):
10
10
  super().__init__(ticker, db_client)
11
+ self.value_keys = [
12
+ "P_E", "P_FCF", "P_B", "P_S",
13
+ "EV_OPI", "EV_EBIT", "EV_EBITDA", "EV_S",
14
+ "Yield"
15
+ ]
11
16
 
12
17
  def prepare_query(self, start_date, end_date):
13
18
  pipeline = super().prepare_query()
@@ -54,7 +59,8 @@ class ValueFetcher(StatsFetcher):
54
59
  "EV_OPI": "$$daily_item.EV_OPI",
55
60
  "EV_EBIT": "$$daily_item.EV_EBIT",
56
61
  "EV_EBITDA": "$$daily_item.EV_EBITDA",
57
- "EV_S": "$$daily_item.EV_S"
62
+ "EV_S": "$$daily_item.EV_S",
63
+ "Yield": "$$daily_item.Yield"
58
64
  }
59
65
  }
60
66
  },
@@ -89,10 +95,13 @@ class ValueFetcher(StatsFetcher):
89
95
  fetched_data = self.collect_data(start_date, end_date)
90
96
 
91
97
  fetched_data['daily_data'] = fetched_data['daily_data'][-1]
98
+ for key in self.value_keys:
99
+ fetched_data['daily_data'][key] = fetched_data['daily_data'].get(key, None)
92
100
 
93
101
  fetched_data['yearly_data'] = ValueProcessor.transform_to_df(
94
102
  fetched_data['daily_data'],
95
103
  fetched_data['yearly_data'],
104
+ required_keys=self.value_keys
96
105
  )
97
106
 
98
107
  return fetched_data
@@ -110,7 +119,8 @@ class ValueFetcher(StatsFetcher):
110
119
  EV_OPI,
111
120
  EV_EBIT,
112
121
  EV_EBITDA,
113
- EV_S
122
+ EV_S,
123
+ Yield
114
124
  }
115
125
  """
116
126
 
@@ -142,7 +152,8 @@ class ValueFetcher(StatsFetcher):
142
152
  "EV_OPI": "$$daily.EV_OPI",
143
153
  "EV_EBIT": "$$daily.EV_EBIT",
144
154
  "EV_EBITDA": "$$daily.EV_EBITDA",
145
- "EV_S": "$$daily.EV_S"
155
+ "EV_S": "$$daily.EV_S",
156
+ "Yield": "$$daily.Yield"
146
157
  }
147
158
  }
148
159
  }
@@ -153,15 +164,12 @@ class ValueFetcher(StatsFetcher):
153
164
  fetched_data = self.collection.aggregate(pipeline).to_list()
154
165
  fetched_data = fetched_data[0]
155
166
 
156
- value_keys = ["P_E", "P_FCF", "P_B", "P_S", "EV_OPI", "EV_EBIT", "EV_EVITDA", "EV_S"]
157
- return_dict = {value_key: dict() for value_key in value_keys}
167
+ return_dict = {value_key: dict() for value_key in self.value_keys}
168
+
169
+ for data in fetched_data['daily_data']:
170
+ for value_key in self.value_keys:
171
+ return_dict[value_key].update({data['date']: data.get(value_key, None)})
158
172
 
159
- for value_key in value_keys:
160
- for data in fetched_data['daily_data']:
161
- if (value_key not in data.keys()):
162
- continue
163
- else:
164
- return_dict[value_key].update({data['date']: data[value_key]})
165
173
 
166
174
  return_dict = {
167
175
  value_key: pd.DataFrame.from_dict(value_dict, orient='index', columns=[value_key])
@@ -173,7 +181,7 @@ class ValueFetcher(StatsFetcher):
173
181
  class ValueProcessor(StatsProcessor):
174
182
 
175
183
  @staticmethod
176
- def transform_to_df(daily_dict, yearly_dict):
184
+ def transform_to_df(daily_dict: dict, yearly_dict: dict, required_keys: list):
177
185
  latest_data = {"year": f"過去4季"}
178
186
 
179
187
  latest_data.update(daily_dict)
@@ -184,4 +192,16 @@ class ValueProcessor(StatsProcessor):
184
192
 
185
193
  yearly_dict = pd.DataFrame.from_dict(yearly_dict)
186
194
 
195
+ total_keys = [
196
+ # 年度評價
197
+ 'year', 'P_E', 'P_FCF', 'P_B', 'P_S',
198
+ 'EV_OPI', 'EV_EBIT', 'EV_EBITDA','EV_S',
199
+
200
+ # 最新一日交易
201
+ 'open', 'high', 'low', 'close', 'volume', 'dividends',
202
+ 'stock splits', 'Yield', 'dividend_year', 'finance_report_time'
203
+ ]
204
+
205
+ total_keys_list = list(total_keys)
206
+ yearly_dict = yearly_dict.reindex(columns=total_keys, fill_value=None)
187
207
  return yearly_dict