美股 低價股低波動策略
In [ ]:
Copied!
%%capture
!pip install finlab
%%capture
!pip install finlab
低波動因子¶
以股價高低區間計算波動率,找出低波動、創新高的股票。
In [ ]:
Copied!
from finlab import data
from finlab.backtest import sim
close = data.get('us_price:close')
high = data.get('us_price:high')
low = data.get('us_price:low')
vol = data.get('us_price:volume')
marketcap = data.get('us_daily_metrics:marketcap')
# 收盤價近5日至少有1日創收盤價近100日創新
condition1 = (close == close.rolling(100).max()).sustain(5,1)
# 近60日股價高低區間在25%內
condition2 = (1 - low.rolling(60).min()/high.rolling(60).max()) < 0.25
# 收盤價低於整體市場分級的50%
condition3 = close <= close.quantile_row(0.5)
# 成交均量不能太低
condition4 = vol.average(10) > 10000
position = condition1 & condition2 & condition3 & condition4
position *= vol
position = position[position > 0].is_smallest(10)
report = sim(position, resample="2w", fee_ratio=0, tax_ratio=0, position_limit=0.1, stop_loss=0.05, name="美股低價股低波動策略")
# report.display()
from finlab import data
from finlab.backtest import sim
close = data.get('us_price:close')
high = data.get('us_price:high')
low = data.get('us_price:low')
vol = data.get('us_price:volume')
marketcap = data.get('us_daily_metrics:marketcap')
# 收盤價近5日至少有1日創收盤價近100日創新
condition1 = (close == close.rolling(100).max()).sustain(5,1)
# 近60日股價高低區間在25%內
condition2 = (1 - low.rolling(60).min()/high.rolling(60).max()) < 0.25
# 收盤價低於整體市場分級的50%
condition3 = close <= close.quantile_row(0.5)
# 成交均量不能太低
condition4 = vol.average(10) > 10000
position = condition1 & condition2 & condition3 & condition4
position *= vol
position = position[position > 0].is_smallest(10)
report = sim(position, resample="2w", fee_ratio=0, tax_ratio=0, position_limit=0.1, stop_loss=0.05, name="美股低價股低波動策略")
# report.display()
/usr/local/lib/python3.10/dist-packages/finlab/analysis/alphaBetaAnalysis.py:22: RuntimeWarning: invalid value encountered in double_scalars
annualized_rate_of_return | sharpe | max_drawdown | win_ratio | |
---|---|---|---|---|
10.96% | 0.81 | -14.34% | 55.0% |
entry_date | exit_date | entry_sig_date | exit_sig_date | position | period | entry_index | exit_index | return | trade_price@entry_date | trade_price@exit_date | mae | gmfe | bmfe | mdd | pdays | weight | next_weights | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stock_id | ||||||||||||||||||
CSLM CONSILIUM ACQUISITION CORP I LTD | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.000000 | 10.47 | NaN | -0.000955 | 0.000000 | 0.000000 | -0.000955 | 0.0 | 0.1 | 0.0 |
ENTF ENTERPRISE 40 TECHNOLOGY ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.000943 | 10.61 | NaN | 0.000000 | 0.000943 | 0.000000 | 0.000000 | 4.0 | 0.1 | 0.0 |
FNVT FINNOVATE ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.003791 | 10.55 | 10.590 | 0.000000 | 0.003791 | 0.000000 | 0.000000 | 3.0 | 0.1 | 0.0 |
GFGD GROWTH FOR GOOD ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.001448 | 10.36 | 10.375 | 0.000000 | 0.002896 | 0.000000 | -0.001444 | 4.0 | 0.1 | 0.0 |
IOAC INNOVATIVE INTERNATIONAL ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | -0.012739 | 10.99 | 10.850 | -0.012739 | 0.054595 | 0.054595 | -0.063848 | 2.0 | 0.1 | 0.0 |
IVCP SWIFTMERGE ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.006744 | 10.38 | 10.450 | -0.015414 | 0.008671 | 0.008671 | -0.023878 | 2.0 | 0.1 | 0.0 |
MCAC MONTEREY CAPITAL ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.000000 | 10.41 | NaN | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.0 | 0.1 | 0.0 |
PUCK GOAL ACQUISITIONS CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 0.002913 | 10.30 | 10.330 | 0.000000 | 0.002913 | 0.000000 | 0.000000 | 1.0 | 0.1 | 0.0 |
SCAQ STRATIM CLOUD ACQUISITION CORP | 2023-06-05 | NaT | 2023-06-02 | NaT | 0.1 | 5.0 | 1615.0 | -1.0 | 0.001946 | 10.28 | 10.300 | 0.000000 | 0.001946 | 0.000000 | 0.000000 | 3.0 | 0.1 | 0.1 |
TLGA TLG ACQUISITION ONE CORP | 2023-05-22 | NaT | 2023-05-19 | 2023-06-18 | 0.1 | 14.0 | 1606.0 | -1.0 | 0.000000 | 10.52 | 10.520 | -0.019011 | 0.000000 | 0.000000 | -0.019011 | 0.0 | 0.1 | 0.0 |
ALPA ALPHA HEALTHCARE ACQUISITION CORP III | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
ANZU ANZU SPECIAL ACQUISITION CORP I | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
AOGO AROGO CAPITAL ACQUISITION CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
BMAC BLACK MOUNTAIN ACQUISITION CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
CORS CORSAIR PARTNERING CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
FRBN FORBION EUROPEAN ACQUISITION CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
ICNC ICONIC SPORTS ACQUISITION CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
SLVR SILVERSPAC INC | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
TRTL TORTOISEECOFIN ACQUISITION CORP III | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
In [ ]:
Copied!
position['GMFIU'].tail(10)
position['GMFIU'].tail(10)
Out[ ]:
date 2023-05-26 False 2023-05-30 False 2023-05-31 False 2023-06-01 False 2023-06-02 True 2023-06-05 False 2023-06-06 False 2023-06-07 False 2023-06-08 False 2023-06-09 False Name: GMFIU, dtype: bool
In [ ]:
Copied!
vol['GMFIU'].tail(10)
vol['GMFIU'].tail(10)
Out[ ]:
date 2023-05-26 0.0 2023-05-30 0.0 2023-05-31 1.0 2023-06-01 0.0 2023-06-02 125.0 2023-06-05 NaN 2023-06-06 NaN 2023-06-07 NaN 2023-06-08 NaN 2023-06-09 NaN Name: GMFIU, dtype: float64
In [ ]:
Copied!