Skip to content

Commit

Permalink
Merge pull request #34 from FinMind/33-新增10年線資料文件
Browse files Browse the repository at this point in the history
add 10 year avg price dataset doc
  • Loading branch information
linsamtw authored Sep 19, 2023
2 parents 5eec4f8 + e42ba77 commit 8dec0e2
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/tutor/TaiwanMarket/DataList.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
在台灣金融市場,我們擁有 44 種資料集,如下:
在台灣金融市場,我們擁有 45 種資料集,如下:

#### 技術面 Technical

Expand All @@ -13,6 +13,7 @@
- [台股加權指數 TaiwanVariousIndicators5Seconds](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanvariousindicators5seconds)
- [當日沖銷交易標的及成交量值 TaiwanStockDayTrading](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstockdaytrading)
- [加權、櫃買報酬指數 TaiwanStockTotalReturnIndex](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstocktotalreturnindex)
- [台灣各股十年線資料表 TaiwanStock10Year](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstock10year)

#### 籌碼面 Chip

Expand Down
124 changes: 123 additions & 1 deletion docs/tutor/TaiwanMarket/Technical.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
在台股技術面,我們擁有 10 種資料集,如下:
在台股技術面,我們擁有 11 種資料集,如下:

- [台股總覽 TaiwanStockInfo](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstockinfo)
- [台股總覽(含權證) TaiwanStockInfoWithWarrant](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstockinfowithwarrant)
Expand All @@ -10,6 +10,7 @@
- [台股加權指數 TaiwanVariousIndicators5Seconds](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanvariousindicators5seconds)
- [當日沖銷交易標的及成交量值 TaiwanStockDayTrading](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstockdaytrading)
- [加權、櫃買報酬指數 TaiwanStockTotalReturnIndex](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstocktotalreturnindex)
- [台灣各股十年線資料表 TaiwanStock10Year](https://finmind.github.io/tutor/TaiwanMarket/Technical/#taiwanstock10year)


根據上述資料表逐一說明怎麼使用,另外具體資料表 schemas 請參考 [finmindapi](http://api.finmindtrade.com/docs#/default/method_api_v4_data_get)
Expand Down Expand Up @@ -839,3 +840,124 @@
| 2 | 18952.7 | TAIEX | 2020-04-08 |
| 3 | 18922.6 | TAIEX | 2020-04-09 |
| 4 | 18994 | TAIEX | 2020-04-10 |


#### 台灣各股十年線資料表 TaiwanStock10Year (只限 [backer、sponsor](https://finmindtrade.com/analysis/#/Sponsor/sponsor) 會員使用)

- 透過2500個交易日所計算出的平均價格
- 資料更新時間 **星期一至五 20:00**,實際更新時間以 API 資料為主

!!! example
=== "Package"
```python
from FinMind.data import DataLoader

api = DataLoader()
# api.login_by_token(api_token='token')
# api.login(user_id='user_id',password='password')
df = api.taiwan_stock_10year(
stock_id='2330',
start_date='2020-04-02',
end_date='2020-04-12'
)
```
=== "Python-request"
```python
import requests
import pandas as pd
url = "https://api.finmindtrade.com/api/v4/data"
parameter = {
"dataset": "TaiwanStock10Year",
"data_id": "2330",
"start_date": "2020-04-02",
"end_date": "2020-04-12",
"token": "", # 參考登入,獲取金鑰
}
resp = requests.get(url, params=parameter)
data = resp.json()
data = pd.DataFrame(data["data"])
print(data.head())
```
=== "R"
```R
library(httr)
library(data.table)
library(dplyr)
url = 'https://api.finmindtrade.com/api/v4/data'
response = httr::GET(
url = url,
query = list(
dataset="TaiwanStock10Year",
data_id= "2330",
start_date= "2020-04-02",
end_date= "2020-04-12",
token = "" # 參考登入,獲取金鑰
)
)
data = content(response)
df = data$data %>%
do.call('rbind',.) %>%
data.table
head(df)

```

!!! output
| | date | stock_id | close |
|---:|:-----------|-----------:|-----------------:|
| 0 | 2020-04-06 | 2330 | 150.16 |
| 1 | 2020-04-07 | 2330 | 150.25 |
| 2 | 2020-04-08 | 2330 | 150.34 |
| 3 | 2020-04-09 | 2330 | 150.43 |
| 4 | 2020-04-10 | 2330 | 150.52 |


#### 一次拿特定日期,所有資料(只限 [backer、sponsor](https://finmindtrade.com/analysis/#/Sponsor/sponsor) 使用)

!!! example
=== "Python-request"
```python
import requests
import pandas as pd
url = "https://api.finmindtrade.com/api/v4/data"
parameter = {
"dataset": "TaiwanStock10Year",
"start_date": "2020-04-06",
"token": "", # 參考登入,獲取金鑰
}
resp = requests.get(url, params=parameter)
data = resp.json()
data = pd.DataFrame(data["data"])
print(data.head())

```
=== "R"
```R
library(httr)
library(data.table)
library(dplyr)
url = 'https://api.finmindtrade.com/api/v4/data'
response = httr::GET(
url = url,
query = list(
dataset="TaiwanStock10Year",
start_date= "2020-04-06",
token = "" # 參考登入,獲取金鑰
)
)
data = content(response)
df = data$data %>%
do.call('rbind',.) %>%
data.table
head(df)

```

!!! output
| | date | stock_id | close |
|---:|:-----------|-----------:|--------:|
| 0 | 2020-04-06 | 0050 | 66.5 |
| 1 | 2020-04-06 | 0053 | 28.68 |
| 2 | 2020-04-06 | 0055 | 14.31 |
| 3 | 2020-04-06 | 0056 | 24.59 |
| 4 | 2020-04-06 | 0061 | 16.28 |

0 comments on commit 8dec0e2

Please sign in to comment.