Get backtest factors for Hong Kong and US stocks
Method name: get_factor
Enter parameters
| Field | Type | Description | Is it required |
|---|---|---|---|
| start_date | str | Start date,eg: “20250702” | Required |
| end_date | str | End date,eg: “20250702” | Required |
| symbol | Optional[Union[str, List[str]]] | Stock code | Optional |
| factors | Union[str, List[str]] | Factor list | Required |
| type | Optional[str] | Product type, supports “hk”, “nb”, default is “hk” | Optional |
Response parameters
Basic factor class:| Field | Type | Description |
|---|---|---|
| date | str | date |
| symbol | str | stock code |
| open | double | opening price |
| close | double | closing price |
| high | double | highest price |
| low | double | lowest price |
| volume | double | trading volume |
| amount | double | transaction amount |
| pre_close | double | previous day’s closing price |
Usage examples
Obtain some backtest factors of a single Hong Kong stock
import tqx_data
result = tqx_data.get_factor(
symbol="0700.HK",
start_date="20260101",
end_date="20260131",
type="hk",
factors=["symbol", "date", "close"],
)
print(result)
symbol date close
0 0700.HK 20260130 678.9326
1 0700.HK 20260129 696.8582
2 0700.HK 20260128 695.7379
3 0700.HK 20260127 680.0530
4 0700.HK 20260126 671.6503
5 0700.HK 20260123 666.6088
6 0700.HK 20260122 669.4096
7 0700.HK 20260121 675.0114
8 0700.HK 20260120 673.3309
9 0700.HK 20260119 683.4140
10 0700.HK 20260116 691.8166
11 0700.HK 20260115 696.8582
12 0700.HK 20260114 709.1821
13 0700.HK 20260113 703.0202
14 0700.HK 20260112 697.9786
15 0700.HK 20260109 684.5344
16 0700.HK 20260108 690.1361
17 0700.HK 20260107 699.6591
18 0700.HK 20260106 708.6219
19 0700.HK 20260105 699.6591
20 0700.HK 20260102 697.9786
Obtain some backtest factors of a single US stock
import tqx_data
result = tqx_data.get_factor(
symbol="AAPL.NB",
start_date="20260101",
end_date="20260131",
type="nb",
factors=["symbol", "date", "volume"],
)
print(result)
symbol date volume
0 AAPL.NB 20260130 92443408.0
1 AAPL.NB 20260129 67253009.0
2 AAPL.NB 20260128 41287971.0
3 AAPL.NB 20260127 49648271.0
4 AAPL.NB 20260126 55969234.0
5 AAPL.NB 20260123 41688982.0
6 AAPL.NB 20260122 39708340.0
7 AAPL.NB 20260121 54641725.0
8 AAPL.NB 20260120 80267517.0
9 AAPL.NB 20260116 72142773.0
10 AAPL.NB 20260115 39388564.0
11 AAPL.NB 20260114 40019421.0
12 AAPL.NB 20260113 45730847.0
13 AAPL.NB 20260112 45263767.0
14 AAPL.NB 20260109 39996967.0
15 AAPL.NB 20260108 50419337.0
16 AAPL.NB 20260107 48309804.0
17 AAPL.NB 20260106 52352090.0
18 AAPL.NB 20260105 45647190.0
19 AAPL.NB 20260102 37838054.0

