|
1 | | -In Taiwan stock chip data, we have 20 datasets as follows: |
| 1 | +In Taiwan stock chip data, we have 21 datasets as follows: |
2 | 2 |
|
3 | 3 |
|
4 | 4 | - [Individual Stock Margin Purchase / Short Sale TaiwanStockMarginPurchaseShortSale](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockmarginpurchaseshortsale) |
5 | 5 | - [Total Market Margin Purchase / Short Sale TaiwanStockTotalMarginPurchaseShortSale](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstocktotalmarginpurchaseshortsale) |
6 | 6 | - [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) |
7 | 8 | - [Total Market Institutional Investors Buy/Sell TaiwanStockTotalInstitutionalInvestors](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstocktotalinstitutionalinvestors) |
8 | 9 | - [Foreign Investor Shareholding TaiwanStockShareholding](https://finmind.github.io/en/tutor/TaiwanMarket/Chip/#taiwanstockshareholding) |
9 | 10 | - [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: |
479 | 480 | } |
480 | 481 | ``` |
481 | 482 |
|
| 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 | + |
482 | 589 | ---------------------------------- |
483 | 590 | #### Taiwan Total Market Institutional Investors Buy/Sell TaiwanStockTotalInstitutionalInvestors |
484 | 591 |
|
|
0 commit comments