{
"cells": [
{
"cell_type": "markdown",
"id": "0593c9fa",
"metadata": {},
"source": [
"# Data Collection"
]
},
{
"cell_type": "markdown",
"id": "3f657cd5",
"metadata": {},
"source": [
"本課程實作如何將資料(如價量、基本面、籌碼面...等)ingest 到 zipline 回測引擎中。\n",
"\n",
"透過這個動作,後續使用 Pipeline API 時,就可以很有效率地獲取資料並計算因子。"
]
},
{
"cell_type": "markdown",
"id": "1d826f7b",
"metadata": {},
"source": [
"### 載入所需套件"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6aaa0ad8",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "479ba028",
"metadata": {},
"source": [
"## Bundle設置\n",
"\n",
"介紹環境變數(environ)設定、運用設定的環境變數做價量、非價量資料的 bundle。\n",
"\n",
"* 在 import zipline 前,必須先設定 `TEJAPI_BASE` 與 `TEJAPI_KEY`。\n",
"\n",
"#### os.environ 變數設定:\n",
"\n",
"設置價量資料 bundle(tquant bundle)需要的資訊:\n",
"* os.environ['TEJAPI_BASE'] = \"https://api.tej.com.tw\"
\n",
" 用於連結TEJ資料庫\n",
"\n",
"* os.environ['TEJAPI_KEY'] = \"Your_Key\"
\n",
" 用於識別使用者\n",
"* os.environ['ticker']
\n",
" tickers = 'xxxx xxxx xxxx'\n",
" os.environ['ticker'] = tickers \n",
" 設置我們所需要的股票代碼 \n",
"* os.environ['mdate'] = 'yyyymmdd yyyymmdd'
\n",
" 設置取得資料的起始時間與結束時間\n",
"* !zipline ingest -b tquant\n",
" 將上方資料 ingest 進 bundle。\n",
"\n",
"設置非價量資料 bundle(fundamentals bundle)需要的資訊:\n",
"* os.environ['fields'] = 'field1, field2, field3'
\n",
" 設置撈取非價量資料的欄位,其中 field1、field2、field3 代表資料欄位名稱 \n",
"* os.environ['include_self_acc'] = 'N'(預設)
\n",
" 設置是否涵蓋公司自結財務,其中設定'Y'代表財務資料包含自結財務,'N'則表示不包含\n",
" \n",
"* !zipline ingest -b fundamentals\n",
" 將非價量資料 ingest 進 bundle。"
]
},
{
"cell_type": "markdown",
"id": "a3936d1f",
"metadata": {},
"source": [
"### 價量資料\n",
"* 價量資料係指單純 OHLCV 與除權息相關資訊。\n",
"\n",
"載入指定股票的價量資料,其中 IR0001 為台灣發行量加權股價報酬指數。"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "32827fc3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"總共有 : 107 筆資料\n"
]
}
],
"source": [
"tickers = 'IR0001 0050 0056 00737 1108 1101 1102 1103 6243 6451 1216 1301 1303 1326 1402 1476 1590 1605 1722 1802 2002 2105 2201 2207 2227 2301 2939 4108 4148 6431 6541 6657 2883 2891 2543 2929 2303 6505 9926 2308 2311 2317 2324 2325 2327 2330 2347 2353 2354 2357 2379 2382 2395 2408 2409 2412 2448 2454 2474 2492 2498 2603 2609 2615 2618 2633 2801 2823 2880 2881 2882 2883 2884 2885 2886 2887 2888 2890 2891 2892 2912 3008 3009 3034 3037 3045 3231 3474 3481 3673 3697 3711 4904 4938 5854 5871 5876 5880 6239 6415 6505 6669 6770 8046 8454 9904 9910'\n",
"print(\"總共有 :\",len(tickers.split()),\"筆資料\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5566b1c9",
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Merging daily equity files:\n",
"Currently used TEJ API key call quota 306/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 7697102/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:06:53.092393] INFO: zipline.data.bundles.core: Ingesting tquant.\n",
"[2024-03-13 03:07:03.377371] INFO: zipline.data.bundles.core: Ingest tquant successfully.\n"
]
}
],
"source": [
"os.environ[\"TEJAPI_BASE\"] = 'https://api.tej.com.tw'\n",
"os.environ['TEJAPI_KEY'] = \"Your_Key\"\n",
"os.environ['ticker'] = tickers\n",
"os.environ['mdate'] = '20200103 20230530'\n",
"\n",
"!zipline ingest -b tquant"
]
},
{
"cell_type": "markdown",
"id": "274043a0",
"metadata": {},
"source": [
"### 更新價量資料\n",
"\n",
"透過輸入 `zipline update -b tquant` 指令,可以更新當前使用的 tquant bundle,以獲得最新的交易價格和交易量資訊。"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c1e59673",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tickers :\n",
"0050 0056 00737 1101 1102 1103 1108 1216 1301 1303\n",
"1326 1402 1476 1590 1605 1722 1802 2002 2105 2201\n",
"2207 2227 2301 2303 2308 2317 2324 2327 2330 2347\n",
"2353 2354 2357 2379 2382 2395 2408 2409 2412 2448\n",
"2454 2474 2492 2498 2543 2603 2609 2615 2618 2633\n",
"2801 2823 2880 2881 2882 2883 2884 2885 2886 2887\n",
"2888 2890 2891 2892 2912 2929 2939 3008 3034 3037\n",
"3045 3231 3481 3673 3711 4108 4148 4904 4938 5871\n",
"5876 5880 6239 6243 6415 6431 6451 6505 6541 6669\n",
"6770 8046 8454 9904 9910 9926 IR0001 \n",
"start_date : 20200103.\n",
"end_date : 20230530.\n"
]
}
],
"source": [
"# 執行前\n",
"!zipline bundle-info"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f52e4e84",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Merging daily equity files:\n",
"Currently used TEJ API key call quota 313/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 7845975/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:07:12.095439] INFO: zipline.data.bundles.core: Ingesting tquant.\n",
"[2024-03-13 03:07:23.400641] INFO: zipline.data.bundles.core: Ingest tquant successfully.\n"
]
}
],
"source": [
"!zipline update -b tquant"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5a719a70",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tickers :\n",
"0050 0056 00737 1101 1102 1103 1108 1216 1301 1303\n",
"1326 1402 1476 1590 1605 1722 1802 2002 2105 2201\n",
"2207 2227 2301 2303 2308 2317 2324 2327 2330 2347\n",
"2353 2354 2357 2379 2382 2395 2408 2409 2412 2448\n",
"2454 2474 2492 2498 2543 2603 2609 2615 2618 2633\n",
"2801 2823 2880 2881 2882 2883 2884 2885 2886 2887\n",
"2888 2890 2891 2892 2912 2929 2939 3008 3034 3037\n",
"3045 3231 3481 3673 3711 4108 4148 4904 4938 5871\n",
"5876 5880 6239 6243 6415 6431 6451 6505 6541 6669\n",
"6770 8046 8454 9904 9910 9926 IR0001 \n",
"start_date : 20200103.\n",
"end_date : 20240312.\n"
]
}
],
"source": [
"# 執行後\n",
"!zipline bundle-info"
]
},
{
"cell_type": "markdown",
"id": "a49aeea6",
"metadata": {},
"source": [
"### 新增價量資料\n",
"\n",
"使用 `zipline add -t ` 指令,可以向現有的 tquant bundle 中新增所選的股票。"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fb43945c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tickers :\n",
"0050 0056 00737 1101 1102 1103 1108 1216 1301 1303\n",
"1326 1402 1476 1590 1605 1722 1802 2002 2105 2201\n",
"2207 2227 2301 2303 2308 2317 2324 2327 2330 2347\n",
"2353 2354 2357 2379 2382 2395 2408 2409 2412 2448\n",
"2454 2474 2492 2498 2543 2603 2609 2615 2618 2633\n",
"2801 2823 2880 2881 2882 2883 2884 2885 2886 2887\n",
"2888 2890 2891 2892 2912 2929 2939 3008 3034 3037\n",
"3045 3231 3481 3673 3711 4108 4148 4904 4938 5871\n",
"5876 5880 6239 6243 6415 6431 6451 6505 6541 6669\n",
"6770 8046 8454 9904 9910 9926 IR0001 \n",
"start_date : 20200103.\n",
"end_date : 20240312.\n"
]
}
],
"source": [
"# 執行前\n",
"!zipline bundle-info"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c086cede",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Merging daily equity files:\n",
"Currently used TEJ API key call quota 317/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 7848331/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:07:36.502363] INFO: zipline.data.bundles.core: Ingesting tquant.\n",
"[2024-03-13 03:07:42.873940] INFO: zipline.data.bundles.core: Ingest tquant successfully.\n"
]
}
],
"source": [
"!zipline add -t \"6523 6208\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "f357630c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tickers :\n",
"0050 0056 00737 1101 1102 1103 1108 1216 1301 1303\n",
"1326 1402 1476 1590 1605 1722 1802 2002 2105 2201\n",
"2207 2227 2301 2303 2308 2317 2324 2327 2330 2347\n",
"2353 2354 2357 2379 2382 2395 2408 2409 2412 2448\n",
"2454 2474 2492 2498 2543 2603 2609 2615 2618 2633\n",
"2801 2823 2880 2881 2882 2883 2884 2885 2886 2887\n",
"2888 2890 2891 2892 2912 2929 2939 3008 3034 3037\n",
"3045 3231 3481 3673 3711 4108 4148 4904 4938 5871\n",
"5876 5880 6208 6239 6243 6415 6431 6451 6505 6523\n",
"6541 6669 6770 8046 8454 9904 9910 9926 IR0001 \n",
"start_date : 20200103.\n",
"end_date : 20240312.\n"
]
}
],
"source": [
"# 執行後\n",
"!zipline bundle-info"
]
},
{
"cell_type": "markdown",
"id": "3922be7d",
"metadata": {},
"source": [
"### 非價量資料\n",
"* 欄位對照清單可參考[TQuant官方網站](https://tquant.tejwin.com/%e8%b3%87%e6%96%99%e9%9b%86/)最下方的 TEJ TOOL API `欄位對照清單`。\n",
"\n",
"設定完 `os.environ['fields']` 後,便可使用 `!zipline ingest -b fundamentals` 載入所需要的非價量資料。"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4b018033",
"metadata": {},
"outputs": [],
"source": [
"columns = ['Sales_Growth_Rate','Operating_Income_Growth_Rate', \n",
" 'Pre_Tax_Income_Growth_Rate','Net_Income_Growth_Rate',\n",
" 'Industry_Eng','Industry', 'roi', 'YoY_Monthly_Sales','mktcap']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8393f09c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Currently used TEJ API key call quota 345/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 8196374/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:07:50.805275] INFO: zipline.data.bundles.core: Ingesting fundamentals.\n",
"[2024-03-13 03:08:32.858797] INFO: zipline.data.bundles.core: Ingest fundamentals successfully.\n"
]
}
],
"source": [
"os.environ['fields'] = \" \".join(columns)\n",
"!zipline ingest -b fundamentals"
]
},
{
"cell_type": "markdown",
"id": "711faf21",
"metadata": {},
"source": [
"### 更新非價量資料\n",
"\n",
"透過輸入 `zipline update -b tquant` 指令,可以更新當前使用的 fundamentals bundle,以獲得最新的資訊。"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "80886edf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"股票池為: ['0050' '0056' '00737' '1101' '1102' '1103' '1108' '1216' '1301' '1303'\n",
" '1326' '1402' '1476' '1590' '1605' '1722' '1802' '2002' '2105' '2201'\n",
" '2207' '2227' '2301' '2303' '2308' '2317' '2324' '2327' '2330' '2347'\n",
" '2353' '2354' '2357' '2543' '2883' '2891' '2929' '2939' '4108' '4148'\n",
" '6243' '6431' '6451' '6505' '6541' '9926' 'IR0001' '2379' '2382' '2395'\n",
" '2408' '2409' '2412' '2448' '2454' '2474' '2492' '2498' '2603' '2609'\n",
" '2615' '2618' '2633' '2801' '2823' '2880' '2881' '2882' '2884' '2885'\n",
" '2886' '2887' '2888' '2890' '2892' '2912' '3008' '3034' '3037' '3045'\n",
" '3231' '3481' '3673' '3711' '4904' '4938' '5871' '5876' '5880' '6239'\n",
" '6415' '6669' '6770' '8046' '8454' '9904' '9910']\n",
"起始日: 2020-01-03 00:00:00\n",
"結束日: 2023-05-30 00:00:00\n",
"欄位: Index(['symbol', 'date', 'Industry', 'Industry_Eng', 'Market_Cap_Dollars',\n",
" 'ROI', 'YoY_Monthly_Sales', 'mon_sales_date',\n",
" 'Net_Income_Growth_Rate_A', 'Net_Income_Growth_Rate_Q',\n",
" 'Net_Income_Growth_Rate_TTM', 'Sales_Growth_Rate_A',\n",
" 'Sales_Growth_Rate_Q', 'Sales_Growth_Rate_TTM',\n",
" 'Pre_Tax_Income_Growth_Rate_A', 'Pre_Tax_Income_Growth_Rate_Q',\n",
" 'Pre_Tax_Income_Growth_Rate_TTM', 'fin_date',\n",
" 'Operating_Income_Growth_Rate_A', 'Operating_Income_Growth_Rate_Q',\n",
" 'Operating_Income_Growth_Rate_TTM'],\n",
" dtype='object')\n"
]
}
],
"source": [
"## update 前\n",
"from zipline.data.data_portal import get_fundamentals\n",
"df = get_fundamentals()\n",
"print('股票池為:',df['symbol'].unique())\n",
"print('起始日:',df['date'].min())\n",
"print('結束日:',df['date'].max())\n",
"print('欄位:',df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "52fb8bf9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Currently used TEJ API key call quota 366/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 8398711/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:08:41.302161] INFO: zipline.data.bundles.core: Ingesting fundamentals.\n",
"[2024-03-13 03:09:12.704311] INFO: zipline.data.bundles.core: Ingest fundamentals successfully.\n"
]
}
],
"source": [
"!zipline update -b fundamentals"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f8c9a12b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"股票池為: ['0050' '0056' '00737' '1101' '1102' '1103' '1108' '1216' '1301' '1303'\n",
" '1326' '1402' '1476' '1590' '1605' '1722' '1802' '2002' '2105' '2201'\n",
" '2207' '2227' '2301' '2303' '2308' '2317' '2324' '2327' '2330' '2347'\n",
" '2353' '2354' '2357' '2379' '2382' '2395' '2408' '2409' '2412' '2448'\n",
" '2454' '2474' '2492' '2498' '2543' '2603' '2609' '2615' '2618' '2633'\n",
" '2801' '2823' '2880' '2881' '2882' '2883' '2884' '2885' '2886' '2887'\n",
" '2888' '2890' '2891' '2892' '2912' '2929' '2939' '3008' '3034' '3037'\n",
" '3045' '3231' '3481' '3673' '3711' '4108' '4148' '4904' '4938' '5871'\n",
" '5876' '5880' '6239' '6243' '6415' '6431' '6451' '6505' '6541' '6669'\n",
" '6770' '8046' '8454' '9904' '9910' '9926' 'IR0001']\n",
"起始日: 2020-01-03 00:00:00\n",
"結束日: 2024-03-12 00:00:00\n",
"欄位: Index(['symbol', 'date', 'Industry', 'Industry_Eng', 'Market_Cap_Dollars',\n",
" 'ROI', 'YoY_Monthly_Sales', 'mon_sales_date',\n",
" 'Net_Income_Growth_Rate_A', 'Net_Income_Growth_Rate_Q',\n",
" 'Net_Income_Growth_Rate_TTM', 'Sales_Growth_Rate_A',\n",
" 'Sales_Growth_Rate_Q', 'Sales_Growth_Rate_TTM',\n",
" 'Pre_Tax_Income_Growth_Rate_A', 'Pre_Tax_Income_Growth_Rate_Q',\n",
" 'Pre_Tax_Income_Growth_Rate_TTM', 'fin_date',\n",
" 'Operating_Income_Growth_Rate_A', 'Operating_Income_Growth_Rate_Q',\n",
" 'Operating_Income_Growth_Rate_TTM'],\n",
" dtype='object')\n"
]
}
],
"source": [
"# update 後\n",
"df = get_fundamentals()\n",
"print('股票池為:',df['symbol'].unique())\n",
"print('起始日:',df['date'].min())\n",
"print('結束日:',df['date'].max())\n",
"print('欄位:',df.columns)"
]
},
{
"cell_type": "markdown",
"id": "fd2fc5f9",
"metadata": {},
"source": [
"### 新增非價量資料\n",
"\n",
"- 執行指令 `zipline add -t ` 可以根據當前 fundamentls bundle 的欄位,新增所選擇的公司到 bundle 中。\n",
"\n",
"- (fundamentls bundle 限定)透過指令 `!zipline add -b fundamentals -f `(其中 `-f` 代表 `field`)來新增當前已有公司的指定資料欄位。\n",
"\n",
"- 請注意,目前系統不支援同時新增公司和資料欄位,因此需要分別進行這些操作。"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6dbfe654",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Currently used TEJ API key call quota 380/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 8442497/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:09:20.517554] INFO: zipline.data.bundles.core: Ingesting fundamentals.\n",
"[2024-03-13 03:09:40.308175] INFO: zipline.data.bundles.core: Ingest fundamentals successfully.\n"
]
}
],
"source": [
"# add 公司\n",
"!zipline add -b fundamentals -t \"6523 6208\""
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "050eb3bc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"股票池為: ['0050' '0056' '00737' '1101' '1102' '1103' '1108' '1216' '1301' '1303'\n",
" '1326' '1402' '1476' '1590' '1605' '1722' '1802' '2002' '2105' '2201'\n",
" '2207' '2227' '2301' '2303' '2308' '2317' '2324' '2327' '2330' '2347'\n",
" '2353' '2354' '2357' '2379' '2382' '2395' '2408' '2409' '2412' '2448'\n",
" '2454' '2474' '2492' '2498' '2543' '2603' '2609' '2615' '2618' '2633'\n",
" '2801' '2823' '2880' '2881' '2882' '2883' '2884' '2885' '2886' '2887'\n",
" '2888' '2890' '2891' '2892' '2912' '2929' '2939' '3008' '3034' '3037'\n",
" '3045' '3231' '3481' '3673' '3711' '4108' '4148' '4904' '4938' '5871'\n",
" '5876' '5880' '6208' '6239' '6243' '6415' '6431' '6451' '6505' '6523'\n",
" '6541' '6669' '6770' '8046' '8454' '9904' '9910' '9926' 'IR0001']\n",
"起始日: 2020-01-03 00:00:00\n",
"結束日: 2024-03-12 00:00:00\n",
"欄位: Index(['symbol', 'date', 'Industry', 'Industry_Eng', 'Market_Cap_Dollars',\n",
" 'ROI', 'YoY_Monthly_Sales', 'mon_sales_date',\n",
" 'Net_Income_Growth_Rate_A', 'Net_Income_Growth_Rate_Q',\n",
" 'Net_Income_Growth_Rate_TTM', 'Sales_Growth_Rate_A',\n",
" 'Sales_Growth_Rate_Q', 'Sales_Growth_Rate_TTM',\n",
" 'Pre_Tax_Income_Growth_Rate_A', 'Pre_Tax_Income_Growth_Rate_Q',\n",
" 'Pre_Tax_Income_Growth_Rate_TTM', 'fin_date',\n",
" 'Operating_Income_Growth_Rate_A', 'Operating_Income_Growth_Rate_Q',\n",
" 'Operating_Income_Growth_Rate_TTM'],\n",
" dtype='object')\n"
]
}
],
"source": [
"# add 公司後\n",
"df = get_fundamentals()\n",
"print('股票池為:',df['symbol'].unique())\n",
"print('起始日:',df['date'].min())\n",
"print('結束日:',df['date'].max())\n",
"print('欄位:',df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "0620756b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Currently used TEJ API key call quota 408/9223372036854775807 (0.0%)\n",
"Currently used TEJ API key data quota 8570809/9223372036854775807 (0.0%)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-03-13 03:10:24.411868] INFO: zipline.data.bundles.core: Ingesting fundamentals.\n",
"[2024-03-13 03:10:52.508213] INFO: zipline.data.bundles.core: Ingest fundamentals successfully.\n"
]
}
],
"source": [
"# add 欄位\n",
"!zipline add -b fundamentals -f Gross_Margin_Growth_Rate"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "23d8a93c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"股票池為: ['0050' '0056' '00737' '1101' '1102' '1103' '1108' '1216' '1301' '1303'\n",
" '1326' '1402' '1476' '1590' '1605' '1722' '1802' '2002' '2105' '2201'\n",
" '2207' '2227' '2301' '2303' '2308' '2317' '2324' '2327' '2330' '2347'\n",
" '2353' '2354' '2357' '2379' '2382' '2395' '2408' '2409' '2412' '2448'\n",
" '2454' '2474' '2492' '2498' '2543' '2603' '2609' '2615' '2618' '2633'\n",
" '2801' '2823' '2880' '2881' '2882' '2883' '2884' '2885' '2886' '2887'\n",
" '2888' '2890' '2891' '2892' '2912' '2929' '2939' '3008' '3034' '3037'\n",
" '3045' '3231' '3481' '3673' '3711' '4108' '4148' '4904' '4938' '5871'\n",
" '5876' '5880' '6208' '6239' '6243' '6415' '6431' '6451' '6505' '6523'\n",
" '6541' '6669' '6770' '8046' '8454' '9904' '9910' '9926' 'IR0001']\n",
"起始日: 2020-01-03 00:00:00\n",
"結束日: 2024-03-12 00:00:00\n",
"欄位: Index(['symbol', 'date', 'Industry', 'Industry_Eng', 'Market_Cap_Dollars',\n",
" 'ROI', 'YoY_Monthly_Sales', 'mon_sales_date',\n",
" 'Net_Income_Growth_Rate_A', 'Net_Income_Growth_Rate_Q',\n",
" 'Net_Income_Growth_Rate_TTM', 'Sales_Growth_Rate_A',\n",
" 'Sales_Growth_Rate_Q', 'Sales_Growth_Rate_TTM',\n",
" 'Pre_Tax_Income_Growth_Rate_A', 'Pre_Tax_Income_Growth_Rate_Q',\n",
" 'Pre_Tax_Income_Growth_Rate_TTM', 'fin_date',\n",
" 'Operating_Income_Growth_Rate_A', 'Operating_Income_Growth_Rate_Q',\n",
" 'Operating_Income_Growth_Rate_TTM', 'Gross_Margin_Growth_Rate_A',\n",
" 'Gross_Margin_Growth_Rate_Q', 'Gross_Margin_Growth_Rate_TTM'],\n",
" dtype='object')\n"
]
}
],
"source": [
"# add 欄位後\n",
"df = get_fundamentals()\n",
"print('股票池為:',df['symbol'].unique())\n",
"print('起始日:',df['date'].min())\n",
"print('結束日:',df['date'].max())\n",
"print('欄位:',df.columns)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:zipline-tej_v11]",
"language": "python",
"name": "conda-env-zipline-tej_v11-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}