FinMind 2.1.0__tar.gz → 2.1.1__tar.gz

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 (59) hide show
  1. {finmind-2.1.0 → finmind-2.1.1}/FinMind/data/__init__.py +1 -0
  2. {finmind-2.1.0 → finmind-2.1.1}/FinMind/data/data_loader.py +4 -0
  3. {finmind-2.1.0 → finmind-2.1.1}/FinMind/data/finmind_api.py +29 -2
  4. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/institutional_investors_follower.py +1 -1
  5. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/institutional_investors_over_buy.py +1 -2
  6. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/base.py +8 -3
  7. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/institutional_investors_follower.py +1 -1
  8. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/short_sale_margin_purchase_ratio.py +1 -2
  9. {finmind-2.1.0/finmind.egg-info → finmind-2.1.1}/PKG-INFO +21 -1
  10. {finmind-2.1.0 → finmind-2.1.1}/README.md +20 -0
  11. {finmind-2.1.0 → finmind-2.1.1/finmind.egg-info}/PKG-INFO +21 -1
  12. {finmind-2.1.0 → finmind-2.1.1}/FinMind/__init__.py +0 -0
  13. {finmind-2.1.0 → finmind-2.1.1}/FinMind/_version.py +0 -0
  14. {finmind-2.1.0 → finmind-2.1.1}/FinMind/crawler/__init__.py +0 -0
  15. {finmind-2.1.0 → finmind-2.1.1}/FinMind/crawler/base.py +0 -0
  16. {finmind-2.1.0 → finmind-2.1.1}/FinMind/crawler/commodities.py +0 -0
  17. {finmind-2.1.0 → finmind-2.1.1}/FinMind/crawler/demo.py +0 -0
  18. {finmind-2.1.0 → finmind-2.1.1}/FinMind/crawler/government_bonds.py +0 -0
  19. {finmind-2.1.0 → finmind-2.1.1}/FinMind/data/data_subscriber.py +0 -0
  20. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/__init__.py +0 -0
  21. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/bias.py +0 -0
  22. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/continue_holding.py +0 -0
  23. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/kd.py +0 -0
  24. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/kd_crossover.py +0 -0
  25. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/ma_cross_orver.py +0 -0
  26. {finmind-2.1.0 → finmind-2.1.1}/FinMind/indicators/short_sale_margin_purchase_ratio.py +0 -0
  27. {finmind-2.1.0 → finmind-2.1.1}/FinMind/plotting/__init__.py +0 -0
  28. {finmind-2.1.0 → finmind-2.1.1}/FinMind/plotting/bar.py +0 -0
  29. {finmind-2.1.0 → finmind-2.1.1}/FinMind/plotting/kline.py +0 -0
  30. {finmind-2.1.0 → finmind-2.1.1}/FinMind/plotting/line.py +0 -0
  31. {finmind-2.1.0 → finmind-2.1.1}/FinMind/plotting/pie.py +0 -0
  32. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/__init__.py +0 -0
  33. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/data.py +0 -0
  34. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/indicators.py +0 -0
  35. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/info.py +0 -0
  36. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/plot.py +0 -0
  37. {finmind-2.1.0 → finmind-2.1.1}/FinMind/schema/rule.py +0 -0
  38. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/__init__.py +0 -0
  39. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/bias.py +0 -0
  40. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/continue_holding.py +0 -0
  41. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/kd.py +0 -0
  42. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/kd_crossover.py +0 -0
  43. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/ma_crossover.py +0 -0
  44. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/macd_crossover.py +0 -0
  45. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/max_min_period_bias.py +0 -0
  46. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/naive_kd.py +0 -0
  47. {finmind-2.1.0 → finmind-2.1.1}/FinMind/strategies/utils.py +0 -0
  48. {finmind-2.1.0 → finmind-2.1.1}/FinMind/templates/post.html +0 -0
  49. {finmind-2.1.0 → finmind-2.1.1}/FinMind/utility/__init__.py +0 -0
  50. {finmind-2.1.0 → finmind-2.1.1}/FinMind/utility/request.py +0 -0
  51. {finmind-2.1.0 → finmind-2.1.1}/FinMind/utility/rule.py +0 -0
  52. {finmind-2.1.0 → finmind-2.1.1}/LICENSE +0 -0
  53. {finmind-2.1.0 → finmind-2.1.1}/finmind.egg-info/SOURCES.txt +0 -0
  54. {finmind-2.1.0 → finmind-2.1.1}/finmind.egg-info/dependency_links.txt +0 -0
  55. {finmind-2.1.0 → finmind-2.1.1}/finmind.egg-info/requires.txt +0 -0
  56. {finmind-2.1.0 → finmind-2.1.1}/finmind.egg-info/top_level.txt +0 -0
  57. {finmind-2.1.0 → finmind-2.1.1}/pyproject.toml +0 -0
  58. {finmind-2.1.0 → finmind-2.1.1}/setup.cfg +0 -0
  59. {finmind-2.1.0 → finmind-2.1.1}/setup.py +0 -0
@@ -1,4 +1,5 @@
1
1
  from FinMind.data.finmind_api import FinMindApi
2
+ from FinMind.data.finmind_api import RealtimeProfileRequiredError
2
3
  from FinMind.data.data_loader import DataLoader
3
4
  from FinMind.data.data_subscriber import DataSubscriber
4
5
  from FinMind.data.data_subscriber import Stock
@@ -2484,6 +2484,10 @@ class DataLoader(FinMindApi):
2484
2484
  timeout: int = None,
2485
2485
  ) -> pd.DataFrame:
2486
2486
  """get 台股即時資訊 taiwan_stock_tick_snapshot (只限 sponsor 會員使用)
2487
+ 依臺灣證券交易所規定,使用台股即時資料須於 2027-01-31 前在會員中心
2488
+ 填寫姓名、電話、地址,逾期未填寫將無法使用
2489
+ (https://finmindtrade.com/analysis/#/account/user)。
2490
+ 未填寫時會提醒一次;逾期未填寫會 raise RealtimeProfileRequiredError。
2487
2491
  :param stock_id (Union(str, List[str])): 股票代號("2330"),也支援 3 碼指數代號
2488
2492
  (例 "001"=加權指數, "101"=櫃買加權);完整指數對照表:
2489
2493
  https://finmind.github.io/tutor/TaiwanMarket/IndexCodes/
@@ -16,6 +16,14 @@ from FinMind.utility.request import (
16
16
  logger.remove()
17
17
  logger.add(sys.stderr, level="INFO")
18
18
 
19
+ # 台股即時資料用戶資料(姓名、電話、地址)提醒,同一個 process 只印一次,
20
+ # 避免輪詢 taiwan_stock_tick_snapshot 時洗版
21
+ _realtime_profile_notice_logged = False
22
+
23
+
24
+ class RealtimeProfileRequiredError(Exception):
25
+ """未於會員中心填寫姓名、電話、地址,無法使用台股即時資料(HTTP 403)"""
26
+
19
27
 
20
28
  class FinMindApi:
21
29
  def __init__(self, token: str = ""):
@@ -307,14 +315,33 @@ class FinMindApi:
307
315
  f"{self.__api_url}/{self.__api_version}/taiwan_stock_tick_snapshot"
308
316
  )
309
317
  logger.debug(params)
310
- response = request_get(
318
+ resp = request_get(
311
319
  self.__session,
312
320
  url,
313
321
  params=params,
314
322
  timeout=timeout,
315
- ).json()
323
+ )
324
+ response = resp.json()
325
+ self._check_realtime_profile(resp.status_code, response)
316
326
  return pd.DataFrame(self._extract_data(response))
317
327
 
328
+ @staticmethod
329
+ def _check_realtime_profile(status_code: int, response_json: dict):
330
+ """
331
+ 依臺灣證券交易所規定,使用台股即時資料須於會員中心填寫姓名、電話、地址。
332
+ 未填寫者在期限前回應會多 profile_notice(提醒一次),期限後回 403。
333
+ """
334
+ global _realtime_profile_notice_logged
335
+ if not isinstance(response_json, dict):
336
+ return
337
+ msg = response_json.get("msg") or ""
338
+ if status_code == 403 and "姓名、電話、地址" in msg:
339
+ raise RealtimeProfileRequiredError(msg)
340
+ profile_notice = response_json.get("profile_notice")
341
+ if profile_notice and not _realtime_profile_notice_logged:
342
+ logger.warning(profile_notice)
343
+ _realtime_profile_notice_logged = True
344
+
318
345
  def get_taiwan_futures_snapshot(
319
346
  self,
320
347
  dataset: Dataset,
@@ -26,7 +26,7 @@ def add_institutional_investors_follower(
26
26
  )
27
27
  institutional_investors_buy_sell = institutional_investors_buy_sell.groupby(
28
28
  ["date", "stock_id"], as_index=False
29
- ).agg({"buy": np.sum, "sell": np.sum})
29
+ ).agg({"buy": "sum", "sell": "sum"})
30
30
  institutional_investors_buy_sell["diff"] = (
31
31
  institutional_investors_buy_sell["buy"]
32
32
  - institutional_investors_buy_sell["sell"]
@@ -1,4 +1,3 @@
1
- import numpy as np
2
1
  import pandas as pd
3
2
 
4
3
  from FinMind.schema.data import Dataset
@@ -15,7 +14,7 @@ def _taiwan_stock_institutional_investors_buy_sell_group_by(
15
14
  taiwan_stock_institutional_investors_buy_sell = (
16
15
  taiwan_stock_institutional_investors_buy_sell.groupby(
17
16
  ["date", "stock_id"], as_index=False
18
- ).agg({"buy": np.sum, "sell": np.sum})
17
+ ).agg({"buy": "sum", "sell": "sum"})
19
18
  )
20
19
  taiwan_stock_institutional_investors_buy_sell[
21
20
  "InstitutionalInvestorsOverBuy"
@@ -567,9 +567,10 @@ class BackTest:
567
567
  self._trade_detail = pd.DataFrame(_trade_detail_dict_list)
568
568
  self._trade_detail["date"] = self.stock_price["date"]
569
569
  self._trade_detail = self._trade_detail.drop(["fee", "tax"], axis=1)
570
+ # 權益 = 初始資金 + 累積已實現與未實現損益(= 現金 + 持股清算價值)。
571
+ # trader_fund 是買進後剩下的現金,不含持股價值,不能直接加損益。
570
572
  self._trade_detail["EverytimeTotalProfit"] = (
571
- self._trade_detail["trader_fund"]
572
- + self._trade_detail["EverytimeProfit"]
573
+ self.trader_fund + self._trade_detail["EverytimeProfit"]
573
574
  )
574
575
  self.__compute_final_stats()
575
576
  self.__compute_compare_market()
@@ -689,9 +690,13 @@ class BackTest:
689
690
  )
690
691
  self._compare_market_detail = self._compare_market_detail.dropna()
691
692
  self._compare_market_stats = pd.Series()
693
+ # CumTaiExDailyReturn 是累積對數報酬,年化前要先換回一般報酬
694
+ taiex_log_return = self._compare_market_detail[
695
+ "CumTaiExDailyReturn"
696
+ ].values[-1]
692
697
  self._compare_market_stats["AnnualTaiexReturnPer"] = (
693
698
  period_return2annual_return(
694
- self._compare_market_detail["CumTaiExDailyReturn"].values[-1],
699
+ np.exp(taiex_log_return) - 1,
695
700
  self._trade_period_years,
696
701
  )
697
702
  * 100
@@ -33,7 +33,7 @@ class InstitutionalInvestorsFollower(Strategy):
33
33
  institutional_investors_buy_sell = (
34
34
  institutional_investors_buy_sell.groupby(
35
35
  ["date", "stock_id"], as_index=False
36
- ).agg({"buy": np.sum, "sell": np.sum})
36
+ ).agg({"buy": "sum", "sell": "sum"})
37
37
  )
38
38
  institutional_investors_buy_sell["diff"] = (
39
39
  institutional_investors_buy_sell["buy"]
@@ -1,4 +1,3 @@
1
- import numpy as np
2
1
  import pandas as pd
3
2
 
4
3
  from FinMind.data import DataLoader
@@ -69,7 +68,7 @@ class ShortSaleMarginPurchaseRatio(Strategy):
69
68
  self.InstitutionalInvestorsBuySell = (
70
69
  self.InstitutionalInvestorsBuySell.groupby(
71
70
  ["date", "stock_id"], as_index=False
72
- ).agg({"buy": np.sum, "sell": np.sum})
71
+ ).agg({"buy": "sum", "sell": "sum"})
73
72
  )
74
73
  self.InstitutionalInvestorsBuySell["diff"] = (
75
74
  self.InstitutionalInvestorsBuySell["buy"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finmind
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: financial mining
5
5
  Author-email: linsam <finmind.tw@gmail.com>
6
6
  License: Apache License
@@ -326,6 +326,26 @@ without having to collect the data by yourself.
326
326
 
327
327
  - 本專案提供的所有內容均用於教育、非商業用途。資料僅供參考,使用者依本資料交易發生交易損失需自行負責,本專案不對資料內容錯誤、更新延誤或傳輸中斷負任何責任。
328
328
 
329
+ ## 資訊來源與使用規定 / Data Source & Usage Rules
330
+
331
+ 資訊來源:臺灣證券交易所「TWSE」|本資訊由芬麥數據股份有限公司處理提供
332
+
333
+ 1. 使用者須遵守臺灣證券交易所『交易資訊使用管理辦法』等交易資訊管理相關規定。
334
+ 2. 所有資訊以臺灣證券交易所公告資料為準。
335
+
336
+ - **台股即時資料**:依臺灣證券交易所規定,使用台股即時資料(`taiwan_stock_tick_snapshot`)須於 **2027-01-31** 前在[會員中心](https://finmindtrade.com/analysis/#/account/user)填寫姓名、電話、地址。2027-01-31 前未填寫仍可使用,API 回應會附 `profile_notice` 提醒;2027-01-31 起未填寫者將無法取得台股即時資料(HTTP 403)。資料用途請見[隱私權政策](https://finmind.github.io/PrivacyPolicy/#realtime-profile)。
337
+ - **券商分點類資料**(台股分點、權證分點、當日卷商分點統計、鉅額交易買賣日報表):任何方案(包含 Sponsor Pro)皆僅限用戶自行使用,不得以任何形式再傳輸或提供予第三人。
338
+ - 詳見[免責聲明與資料授權](https://finmind.github.io/Disclaimer/)。
339
+
340
+ Source: Taiwan Stock Exchange (TWSE) | This information is processed and provided by 芬麥數據股份有限公司 (FinMind)
341
+
342
+ 1. Users must comply with the TWSE Regulations Governing the Use of Trading Information and other applicable rules on trading information.
343
+ 2. All information is subject to the data announced by the Taiwan Stock Exchange.
344
+
345
+ - **Taiwan stock real-time data**: under Taiwan Stock Exchange regulations, users of Taiwan stock real-time data (`taiwan_stock_tick_snapshot`) must fill in their name, phone number, and address in the [Member Center](https://finmindtrade.com/analysis/#/account/user) by **2027-01-31**. Before then, users who have not filled it in can still use the data, with a `profile_notice` reminder in API responses; from 2027-01-31 they will no longer be able to get Taiwan stock real-time data (HTTP 403). See the [Privacy Policy](https://finmind.github.io/en/PrivacyPolicy/#realtime-profile).
346
+ - **Broker branch data** (stock and warrant broker branch trading reports, daily branch aggregate statistics, block trading daily report): for your own use only under every plan, including Sponsor Pro; must not be retransmitted or provided to third parties in any form.
347
+ - See [Disclaimer & Data Licensing](https://finmind.github.io/en/Disclaimer/).
348
+
329
349
  ## Project of Contents
330
350
 
331
351
  - Dataset
@@ -84,6 +84,26 @@ without having to collect the data by yourself.
84
84
 
85
85
  - 本專案提供的所有內容均用於教育、非商業用途。資料僅供參考,使用者依本資料交易發生交易損失需自行負責,本專案不對資料內容錯誤、更新延誤或傳輸中斷負任何責任。
86
86
 
87
+ ## 資訊來源與使用規定 / Data Source & Usage Rules
88
+
89
+ 資訊來源:臺灣證券交易所「TWSE」|本資訊由芬麥數據股份有限公司處理提供
90
+
91
+ 1. 使用者須遵守臺灣證券交易所『交易資訊使用管理辦法』等交易資訊管理相關規定。
92
+ 2. 所有資訊以臺灣證券交易所公告資料為準。
93
+
94
+ - **台股即時資料**:依臺灣證券交易所規定,使用台股即時資料(`taiwan_stock_tick_snapshot`)須於 **2027-01-31** 前在[會員中心](https://finmindtrade.com/analysis/#/account/user)填寫姓名、電話、地址。2027-01-31 前未填寫仍可使用,API 回應會附 `profile_notice` 提醒;2027-01-31 起未填寫者將無法取得台股即時資料(HTTP 403)。資料用途請見[隱私權政策](https://finmind.github.io/PrivacyPolicy/#realtime-profile)。
95
+ - **券商分點類資料**(台股分點、權證分點、當日卷商分點統計、鉅額交易買賣日報表):任何方案(包含 Sponsor Pro)皆僅限用戶自行使用,不得以任何形式再傳輸或提供予第三人。
96
+ - 詳見[免責聲明與資料授權](https://finmind.github.io/Disclaimer/)。
97
+
98
+ Source: Taiwan Stock Exchange (TWSE) | This information is processed and provided by 芬麥數據股份有限公司 (FinMind)
99
+
100
+ 1. Users must comply with the TWSE Regulations Governing the Use of Trading Information and other applicable rules on trading information.
101
+ 2. All information is subject to the data announced by the Taiwan Stock Exchange.
102
+
103
+ - **Taiwan stock real-time data**: under Taiwan Stock Exchange regulations, users of Taiwan stock real-time data (`taiwan_stock_tick_snapshot`) must fill in their name, phone number, and address in the [Member Center](https://finmindtrade.com/analysis/#/account/user) by **2027-01-31**. Before then, users who have not filled it in can still use the data, with a `profile_notice` reminder in API responses; from 2027-01-31 they will no longer be able to get Taiwan stock real-time data (HTTP 403). See the [Privacy Policy](https://finmind.github.io/en/PrivacyPolicy/#realtime-profile).
104
+ - **Broker branch data** (stock and warrant broker branch trading reports, daily branch aggregate statistics, block trading daily report): for your own use only under every plan, including Sponsor Pro; must not be retransmitted or provided to third parties in any form.
105
+ - See [Disclaimer & Data Licensing](https://finmind.github.io/en/Disclaimer/).
106
+
87
107
  ## Project of Contents
88
108
 
89
109
  - Dataset
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finmind
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: financial mining
5
5
  Author-email: linsam <finmind.tw@gmail.com>
6
6
  License: Apache License
@@ -326,6 +326,26 @@ without having to collect the data by yourself.
326
326
 
327
327
  - 本專案提供的所有內容均用於教育、非商業用途。資料僅供參考,使用者依本資料交易發生交易損失需自行負責,本專案不對資料內容錯誤、更新延誤或傳輸中斷負任何責任。
328
328
 
329
+ ## 資訊來源與使用規定 / Data Source & Usage Rules
330
+
331
+ 資訊來源:臺灣證券交易所「TWSE」|本資訊由芬麥數據股份有限公司處理提供
332
+
333
+ 1. 使用者須遵守臺灣證券交易所『交易資訊使用管理辦法』等交易資訊管理相關規定。
334
+ 2. 所有資訊以臺灣證券交易所公告資料為準。
335
+
336
+ - **台股即時資料**:依臺灣證券交易所規定,使用台股即時資料(`taiwan_stock_tick_snapshot`)須於 **2027-01-31** 前在[會員中心](https://finmindtrade.com/analysis/#/account/user)填寫姓名、電話、地址。2027-01-31 前未填寫仍可使用,API 回應會附 `profile_notice` 提醒;2027-01-31 起未填寫者將無法取得台股即時資料(HTTP 403)。資料用途請見[隱私權政策](https://finmind.github.io/PrivacyPolicy/#realtime-profile)。
337
+ - **券商分點類資料**(台股分點、權證分點、當日卷商分點統計、鉅額交易買賣日報表):任何方案(包含 Sponsor Pro)皆僅限用戶自行使用,不得以任何形式再傳輸或提供予第三人。
338
+ - 詳見[免責聲明與資料授權](https://finmind.github.io/Disclaimer/)。
339
+
340
+ Source: Taiwan Stock Exchange (TWSE) | This information is processed and provided by 芬麥數據股份有限公司 (FinMind)
341
+
342
+ 1. Users must comply with the TWSE Regulations Governing the Use of Trading Information and other applicable rules on trading information.
343
+ 2. All information is subject to the data announced by the Taiwan Stock Exchange.
344
+
345
+ - **Taiwan stock real-time data**: under Taiwan Stock Exchange regulations, users of Taiwan stock real-time data (`taiwan_stock_tick_snapshot`) must fill in their name, phone number, and address in the [Member Center](https://finmindtrade.com/analysis/#/account/user) by **2027-01-31**. Before then, users who have not filled it in can still use the data, with a `profile_notice` reminder in API responses; from 2027-01-31 they will no longer be able to get Taiwan stock real-time data (HTTP 403). See the [Privacy Policy](https://finmind.github.io/en/PrivacyPolicy/#realtime-profile).
346
+ - **Broker branch data** (stock and warrant broker branch trading reports, daily branch aggregate statistics, block trading daily report): for your own use only under every plan, including Sponsor Pro; must not be retransmitted or provided to third parties in any form.
347
+ - See [Disclaimer & Data Licensing](https://finmind.github.io/en/Disclaimer/).
348
+
329
349
  ## Project of Contents
330
350
 
331
351
  - Dataset
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes