Skip to content

Commit 9f8f8c9

Browse files
authored
Merge pull request #132 from FinMind/feature/institutional-investors-buysell-wide
docs: add TaiwanStockInstitutionalInvestorsBuySellWide (個股三大法人買賣表寬表)
2 parents ecb5f4f + 2f957bd commit 9f8f8c9

8 files changed

Lines changed: 234 additions & 5 deletions

File tree

docs/WhatIsNew.en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#### 2026-06-13
2+
* Added [Institutional Investors Buy/Sell (Wide) TaiwanStockInstitutionalInvestorsBuySellWide](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockinstitutionalinvestorsbuysellwide): same data as `TaiwanStockInstitutionalInvestorsBuySell` but in wide format — one row per trading day with each institutional investor's buy/sell as its own column, no manual pivot needed. Columns cover all historical investor categories; a category is 0 in eras where it did not exist (dealer split into proprietary/hedging from 2014-12-01; foreign dealer self from 2018-01-15). Data range 2005-01-01 ~ now
23
* The FinMind Python package now supports **Python 3.12** (Python 3.8–3.11 remain supported). Starting from this release, dependencies are upgraded to `pandas>=2.0` and `ta>=0.11` (`numpy` and `pydantic` unchanged).
34
* **No code changes are required** to call FinMind: the public `DataLoader`, strategy, and plotting interfaces are unchanged.
45
* :warning: **Upgrade note**: installing/upgrading also bumps `pandas` to 2.x and `ta` to 0.11 in your environment. If your **own surrounding code** still uses pandas 1.x APIs removed in 2.0, you will need to adjust it — common examples: `df.append()``pd.concat([...])`, `df.to_dict("r")``df.to_dict("records")`, `df.iteritems()``df.items()`. If you cannot adjust yet, pin an older FinMind version for now.

docs/WhatIsNew.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#### 2026-06-13
2+
* 新增 [個股三大法人買賣表(寬表)TaiwanStockInstitutionalInvestorsBuySellWide](https://finmind.github.io/tutor/TaiwanMarket/Chip/#taiwanstockinstitutionalinvestorsbuysellwide):與 `TaiwanStockInstitutionalInvestorsBuySell` 相同資料,改為寬表(橫式),每個交易日一列、各法人別買賣攤平成獨立欄位(外資、外資自營商、投信、自營商及其自行買賣/避險),免自行轉置。欄位涵蓋所有歷史法人別分類,尚未存在的年代該欄為 0(自營商於 2014-12-01 由合併拆為自行買賣/避險、外資自營商於 2018-01-15 起提供);資料區間 2005-01-01 ~ now
23
* FinMind Python 套件新增支援 **Python 3.12**(持續支援 Python 3.8–3.11)。本版起套件相依升級為 `pandas>=2.0``ta>=0.11``numpy``pydantic` 維持不變)。
34
* 呼叫 FinMind 的程式碼**無需修改**`DataLoader`、策略 (Strategy)、繪圖等對外介面皆不變。
45
* :warning: **升級須知**:安裝/升級會一併將環境中的 `pandas` 升至 2.x、`ta` 升至 0.11。若你**其餘自有程式碼**仍使用 pandas 1.x 在 2.0 已移除的寫法,需自行調整,常見如:`df.append()``pd.concat([...])``df.to_dict("r")``df.to_dict("records")``df.iteritems()``df.items()`。若暫時無法調整,可先固定安裝舊版 FinMind。

docs/llms-full.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ Async batch query is supported by datasets that require `data_id` parameter. Not
303303
- Params (all stocks, Backer/Sponsor): dataset=TaiwanStockInstitutionalInvestorsBuySell, start_date=2020-04-01 (不帶 data_id,取得該日所有股票資料)
304304
- Columns: date, stock_id, buy, name, sell
305305

306+
### TaiwanStockInstitutionalInvestorsBuySellWide (個股三大法人買賣表(寬表))
307+
- Tier: Free (with data_id) / Backer/Sponsor (all stocks by start_date only)
308+
- Same data as TaiwanStockInstitutionalInvestorsBuySell but wide format: one row per (date, stock_id), each institutional investor's buy/sell as its own column
309+
- Data range: 2005-01-01 ~ now
310+
- Coverage: 上市 (TWSE), 上櫃 (TPEx), 興櫃 (Emerging) 三市場,以 stock_id 區分
311+
- Update: Mon-Fri 20:00
312+
- Params: dataset=TaiwanStockInstitutionalInvestorsBuySellWide, data_id=2330, start_date=2020-04-01, end_date=2020-04-12
313+
- Params (all stocks, Backer/Sponsor): dataset=TaiwanStockInstitutionalInvestorsBuySellWide, start_date=2020-04-01 (不帶 data_id,取得該日所有股票資料)
314+
- Columns: date, stock_id, Foreign_Investor_buy, Foreign_Investor_sell, Foreign_Dealer_Self_buy, Foreign_Dealer_Self_sell, Investment_Trust_buy, Investment_Trust_sell, Dealer_buy, Dealer_sell, Dealer_self_buy, Dealer_self_sell, Dealer_Hedging_buy, Dealer_Hedging_sell
315+
- Note: covers all historical investor categories; a category is 0 in eras where it did not exist. Dealer (combined) is pre-2014-12-01 (and Emerging); Dealer_self/Dealer_Hedging from 2014-12-01; Foreign_Dealer_Self from 2018-01-15. For a continuous dealer total, sum Dealer + Dealer_self + Dealer_Hedging.
316+
306317
### TaiwanStockTotalInstitutionalInvestors (整體三大市場法人買賣表)
307318
- Tier: Free
308319
- Data range: 2004-04-01 ~ now

docs/llms.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Async batch query is supported by datasets that require `data_id` parameter. Not
5555

5656
- [Taiwan DataList](https://finmind.github.io/tutor/TaiwanMarket/DataList/): Full list of 78 Taiwan datasets
5757
- [Technical](https://finmind.github.io/tutor/TaiwanMarket/Technical/): TaiwanStockInfo, TaiwanStockPrice, TaiwanStockPriceAdj, TaiwanStockPriceTick, TaiwanStockPER, TaiwanStockKBar, TaiwanStockWeekPrice, TaiwanStockMonthPrice, TaiwanStockDayTrading, TaiwanStockTotalReturnIndex, TaiwanVariousIndicators5Seconds, TaiwanStockTradingDate, etc.
58-
- [Chip (Institutional)](https://finmind.github.io/tutor/TaiwanMarket/Chip/): TaiwanStockMarginPurchaseShortSale, TaiwanStockInstitutionalInvestorsBuySell, TaiwanStockShareholding, TaiwanStockHoldingSharesPer, TaiwanStockSecuritiesLending, TaiwanStockTradingDailyReport, TaiwanStockBlockTradingDailyReport, TaiwanStockBlockTrade, TaiwanStockLoanCollateralBalance, TaiwanstockGovernmentBankBuySell, etc.
58+
- [Chip (Institutional)](https://finmind.github.io/tutor/TaiwanMarket/Chip/): TaiwanStockMarginPurchaseShortSale, TaiwanStockInstitutionalInvestorsBuySell, TaiwanStockInstitutionalInvestorsBuySellWide, TaiwanStockShareholding, TaiwanStockHoldingSharesPer, TaiwanStockSecuritiesLending, TaiwanStockTradingDailyReport, TaiwanStockBlockTradingDailyReport, TaiwanStockBlockTrade, TaiwanStockLoanCollateralBalance, TaiwanstockGovernmentBankBuySell, etc.
5959
- [Fundamental](https://finmind.github.io/tutor/TaiwanMarket/Fundamental/): TaiwanStockCashFlowsStatement, TaiwanStockFinancialStatements, TaiwanStockBalanceSheet, TaiwanStockDividend, TaiwanStockDividendResult, TaiwanStockMonthRevenue, TaiwanStockMarketValue, etc.
6060
- [Derivative](https://finmind.github.io/tutor/TaiwanMarket/Derivative/): TaiwanFuturesDaily, TaiwanOptionDaily, TaiwanFuturesTick, TaiwanFuturesSpreadTick, TaiwanOptionTick, TaiwanFuturesInstitutionalInvestors, TaiwanOptionInstitutionalInvestors, TaiwanFuturesDealerTradingVolumeDaily, TaiwanOptionDealerTradingVolumeDaily, TaiwanFuturesSpreadTrading, etc.
6161
- [Real-Time](https://finmind.github.io/tutor/TaiwanMarket/RealTime/): taiwan_stock_tick_snapshot, TaiwanFutOptTickInfo, taiwan_futures_snapshot, taiwan_options_snapshot

docs/tutor/TaiwanMarket/Chip.en.md

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
In Taiwan stock chip data, we have 20 datasets as follows:
1+
In Taiwan stock chip data, we have 21 datasets as follows:
22

33

44
- [Individual Stock Margin Purchase / Short Sale TaiwanStockMarginPurchaseShortSale](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockmarginpurchaseshortsale)
55
- [Total Market Margin Purchase / Short Sale TaiwanStockTotalMarginPurchaseShortSale](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstocktotalmarginpurchaseshortsale)
66
- [Individual Stock Institutional Investors Buy/Sell TaiwanStockInstitutionalInvestorsBuySell](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockinstitutionalinvestorsbuysell)
7+
- [Individual Stock Institutional Investors Buy/Sell (Wide) TaiwanStockInstitutionalInvestorsBuySellWide](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockinstitutionalinvestorsbuysellwide)
78
- [Total Market Institutional Investors Buy/Sell TaiwanStockTotalInstitutionalInvestors](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstocktotalinstitutionalinvestors)
89
- [Foreign Investor Shareholding TaiwanStockShareholding](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockshareholding)
910
- [Shareholders Holding Shares Distribution TaiwanStockHoldingSharesPer](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockholdingsharesper-backersponsor)
@@ -479,6 +480,112 @@ In Taiwan stock chip data, we have 20 datasets as follows:
479480
}
480481
```
481482

483+
----------------------------------
484+
#### Institutional Investors Buy/Sell (Wide) TaiwanStockInstitutionalInvestorsBuySellWide
485+
486+
- Same source data as `TaiwanStockInstitutionalInvestorsBuySell`, but in **wide format**: one row per trading day, with each institutional investor's buy/sell flattened into its own column — no manual pivot needed.
487+
- Data range: 2005-01-01 ~ now
488+
- Coverage: listed (TWSE), OTC (TPEx) and emerging market companies, distinguished by `stock_id` (use `TaiwanStockInfo` to look up market type)
489+
- Data update time **Monday to Friday 20:00**, the actual update time is based on the API data.
490+
491+
!!! note "New vs old era columns (important)"
492+
The classification of the three institutional investors has changed over the years. This wide table includes **all historical classifications**; a classification is always `0` in eras where it did not yet exist:
493+
494+
| Column | Available era | Other eras |
495+
|--------|---------------|------------|
496+
| `Foreign_Investor` (foreign, excl. foreign dealer self) | all | — |
497+
| `Investment_Trust` | all | — |
498+
| `Dealer` (dealer, combined) | **old era** (before ~2014-12-01) and Emerging | `0` afterwards |
499+
| `Dealer_self` (dealer, proprietary) | **new era** (from 2014-12-01) | `0` before |
500+
| `Dealer_Hedging` (dealer, hedging) | **new era** (from 2014-12-01) | `0` before |
501+
| `Foreign_Dealer_Self` (foreign dealer self) | **new era** (from 2018-01-15) | `0` before |
502+
503+
- From **2014-12-01**, the combined `Dealer` was split into `Dealer_self` (proprietary) and `Dealer_Hedging` (hedging).
504+
- From **2018-01-15**, `Foreign_Dealer_Self` was split out from foreign investors.
505+
- For a continuous "dealer total" across eras, sum `Dealer + Dealer_self + Dealer_Hedging` (only one group is non-zero in any era, so there is no double counting).
506+
507+
!!! example
508+
=== "Package"
509+
```python
510+
from FinMind.data import DataLoader
511+
512+
api = DataLoader()
513+
# api.login_by_token(api_token='token')
514+
df = api.taiwan_stock_institutional_investors_wide(
515+
stock_id="2330",
516+
start_date='2020-04-01',
517+
end_date='2020-04-12',
518+
)
519+
```
520+
=== "Python-request"
521+
```python
522+
import requests
523+
import pandas as pd
524+
url = "https://api.finmindtrade.com/api/v4/data"
525+
token = "" # login to get the token
526+
headers = {"Authorization": f"Bearer {token}"}
527+
parameter = {
528+
"dataset": "TaiwanStockInstitutionalInvestorsBuySellWide",
529+
"data_id": "2330",
530+
"start_date": "2020-04-01",
531+
"end_date": "2020-04-12",
532+
}
533+
data = requests.get(url, headers=headers, params=parameter)
534+
data = data.json()
535+
data = pd.DataFrame(data['data'])
536+
print(data.head())
537+
538+
```
539+
=== "R"
540+
```R
541+
library(httr)
542+
library(data.table)
543+
library(dplyr)
544+
url = 'https://api.finmindtrade.com/api/v4/data'
545+
token = "" # login to get the token
546+
response = httr::GET(
547+
url = url,
548+
query = list(
549+
dataset="TaiwanStockInstitutionalInvestorsBuySellWide",
550+
data_id= "2330",
551+
start_date= "2020-04-01",
552+
end_date= "2020-04-12"
553+
),
554+
add_headers(Authorization = paste("Bearer", token))
555+
)
556+
data = content(response)
557+
df = data$data %>%
558+
do.call('rbind',.) %>%
559+
data.table
560+
head(df)
561+
562+
```
563+
564+
!!! output
565+
=== "DataFrame"
566+
| | date | stock_id | Foreign_Investor_buy | Foreign_Investor_sell | Foreign_Dealer_Self_buy | Foreign_Dealer_Self_sell | Investment_Trust_buy | Investment_Trust_sell | Dealer_buy | Dealer_sell | Dealer_self_buy | Dealer_self_sell | Dealer_Hedging_buy | Dealer_Hedging_sell |
567+
|---:|:-----------|-----------:|-----------------------:|------------------------:|--------------------------:|---------------------------:|-----------------------:|------------------------:|-------------:|--------------:|------------------:|-------------------:|---------------------:|----------------------:|
568+
| 0 | 2020-04-01 | 2330 | 31304729 | 29057663 | 0 | 0 | 900000 | 239000 | 0 | 0 | 79000 | 807000 | 189000 | 493500 |
569+
=== "Schema"
570+
```
571+
{
572+
date: str, # date
573+
stock_id: str, # stock id
574+
Foreign_Investor_buy: int64, # foreign investor buy
575+
Foreign_Investor_sell: int64, # foreign investor sell
576+
Foreign_Dealer_Self_buy: int64, # foreign dealer self buy
577+
Foreign_Dealer_Self_sell: int64, # foreign dealer self sell
578+
Investment_Trust_buy: int64, # investment trust buy
579+
Investment_Trust_sell: int64, # investment trust sell
580+
Dealer_buy: int64, # dealer buy (combined, old era)
581+
Dealer_sell: int64, # dealer sell (combined, old era)
582+
Dealer_self_buy: int64, # dealer proprietary buy
583+
Dealer_self_sell: int64, # dealer proprietary sell
584+
Dealer_Hedging_buy: int64, # dealer hedging buy
585+
Dealer_Hedging_sell: int64 # dealer hedging sell
586+
}
587+
```
588+
482589
----------------------------------
483590
#### Taiwan Total Market Institutional Investors Buy/Sell TaiwanStockTotalInstitutionalInvestors
484591

0 commit comments

Comments
 (0)