Skip to content

Releases: tejtw/zipline-tej

v2.1.0

30 Oct 01:09
13a236b
Compare
Choose a tag to compare

功能新增

1. 新增設定回測成交價格設定,於initialize中加入set_execution_price_type,參數為 open , high , close , low。

def initialize(context):
    ...
    context.set_execution_price_type('open') # open , high , close , low 
    ...

2. 於 zipline.data.run_ingest 中新增 simple_ingest 功能,使得ingest更加容易。

import os 
os.environ['TEJAPI_KEY'] = '<your_key>'
...
from zipline.data.run_ingest import simple_ingest
# 價量資料
simple_ingest(name = 'tquant' , tickers = ['2330'] , start_date = '20200101' , end_date = '20220101')
# 基本面資料
simple_ingest(name = 'fundamentals' , tickers = ['2330'] , start_date = '20200101' , end_date = '20220101' , fields = ["eps"])
...

3. 新增預設網域,未來在 import zipline 之前,僅需設定 TEJAPI_KEY 即可,預設網域為 https://api.tej.com.tw

# 原先
import os
os.environ['TEJAPI_BASE'] = "https://api.tej.com.tw"
os.environ['TEJAPI_KEY'] = '<your_key>'
import zipline

# 現在
import os
os.environ['TEJAPI_KEY'] = '<your_key>'
import zipline

4. Annotation 部分新增 先買後賣交易限制

5. class TargetPercentPipeAlgo 新增 min_long_countmin_short_count 參數,以用於確定再平衡的最小做多檔數必須大於min_long_count最小做空檔數大於min_short_count才會進行再平衡。

6. 將 PctSlippage 滑價模型加入至zipline.api

from zipline.api import PctSlippage
...

7. 新增 TW_Slippage 滑價模型

TW_Slippage 說明 :

"""

Simple custom model for Taiwan Market.

Parameters

spread : float, optional

    Size of the assumed spread for all assets.

    Orders to buy will be filled at either limit_up price or ``execute_price + (spread * tick_diff)``.

    Orders to sell will be filled at either limit_down price or ``execute_price - (spread * tick_diff)``.

volume_limit : float, optional

    Maximum percent of historical volume that can fill in each bar. 0.5

    means 50% of historical volume. 1.0 means 100%. Default is 0.025 (i.e.,

    2.5%).

"""
from zipline.finance.slippage import TW_Slippage
from zipline.api import set_slippage
...
def initialize(context) :
    ...
    set_slippage(TW_Slippage(spread = 2 , volume_limit = 0.025))
    ...
...

功能調整

1. 在回測期間基於當前交易價格,而非收盤價,修改 order_valueorder_target_valueorder_percentorder_target_percent 函數來計算數量和目標金額,確保在多變的市場條件下進行更精確的交易模擬。

以下將針對有改動的部分以表格進行列示

1. order_value

成交方式 price_type 下單股數
current_bar open value/ open(t)
current_bar high value/ high(t)
current_bar low value/ low(t)

2. order_target_value

成交方式 price_type 目標股數 下單股數
current_bar open value/open(t) 目標股數 - 帳上持有股數(t期初,經除權調整)
current_bar high value/high(t) 目標股數 - 帳上持有股數(t期初,經除權調整)
current_bar low value/low(t) 目標股數 - 帳上持有股數(t期初,經除權調整)

3. order_percent

成交方式 price_type 下單價值 下單股數
current_bar open portfolio_value (t期初,經除權調整) * percent value/open(t)
current_bar high portfolio_value (t期初,經除權調整) * percent value/high(t)
current_bar low portfolio_value (t期初,經除權調整) * percent value/low(t)
current_bar close portfolio_value (t期初,經除權調整) * percent value/close(t)

4. order_target_percent

成交方式 price_type 目標價值 目標股數 下單股數
current_bar open portfolio_value (t期初,經除權調整) * percent value/open(t) 目標價值 - 帳上持有股數(t期初,經除權調整)
current_bar high portfolio_value (t期初,經除權調整) * percent value/high(t) 目標價值 - 帳上持有股數(t期初,經除權調整)
current_bar low portfolio_value (t期初,經除權調整) * percent value/low(t) 目標價值 - 帳上持有股數(t期初,經除權調整)
current_bar close portfolio_value (t期初,經除權調整) * percent value/close(t) 目標價值 - 帳上持有股數(t期初,經除權調整)

v2.1.0rc1

08 Oct 05:43
Compare
Choose a tag to compare
v2.1.0rc1 Pre-release
Pre-release
v2.1.0rc1

v2.1.0rc0

23 Sep 07:12
Compare
Choose a tag to compare
v2.1.0rc0 Pre-release
Pre-release
zipline 2.1.0rc0

v2.1.0rc2

29 Oct 01:12
b6780f3
Compare
Choose a tag to compare
v2.1.0rc2 Pre-release
Pre-release

新增台灣滑價模型

v2.0.0

13 Mar 07:15
6184a4c
Compare
Choose a tag to compare

v2.0.0rc4

06 Mar 09:42
39661fd
Compare
Choose a tag to compare
v2.0.0rc4 Pre-release
Pre-release
Merge pull request #23 from tejtw/v2.0.0rc4

MAINT: version2.0.0rc4

v2.0.0rc3

27 Feb 00:48
bfd7d36
Compare
Choose a tag to compare
v2.0.0rc3 Pre-release
Pre-release
Merge pull request #22 from tejtw/v2.0.0rc3

MAINT:loaders

v2.0.0rc2

26 Feb 09:22
ff64de1
Compare
Choose a tag to compare
v2.0.0rc2 Pre-release
Pre-release
Merge pull request #21 from tejtw/v2.0.0rc2

MAINT: change to_csv to to_parquet

v2.0.0rc1

23 Feb 08:38
1dbae27
Compare
Choose a tag to compare
v2.0.0rc1 Pre-release
Pre-release
Update python-publish.yml

v2.0.0rc0

15 Feb 02:12
8ffd530
Compare
Choose a tag to compare
v2.0.0rc0 Pre-release
Pre-release
Update cibuild version