美股 營收突破策略
安裝套件¶
In [ ]:
Copied!
!pip install finlab > log.txt
!pip install ta-lib-bin
!pip install finlab > log.txt
!pip install ta-lib-bin
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting ta-lib-bin Downloading ta_lib_bin-0.4.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.9/2.9 MB 26.3 MB/s eta 0:00:00 Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from ta-lib-bin) (1.22.4) Installing collected packages: ta-lib-bin Successfully installed ta-lib-bin-0.4.26
動能因子與獲利因子¶
尋找營收與股價同步創高的股票
In [ ]:
Copied!
from finlab import data
from finlab.backtest import sim
close = data.get('us_price:close')
adj_close = data.get('us_price:adj_close')
vol = data.get('us_price:volume')
rev = data.get('us_fundamental:revenue')
def 成長率(s):
return ((s-s.shift(4)) / s.shift(4).abs()) * 100
rev_yoy_growth = 成長率(rev)
# 近1季營收創近1年來新高
condition1 = rev == rev.rolling(4, min_periods=2).max()
# 近5日內至少有2日股價創100日新高
condition2 = (close == close.rolling(100).max()).sustain(5,2)
# 5日成交均量大於500000股
condition3 = vol.average(5) > 500000
position = condition1 & condition2 & condition3
# 符合選股條件的名單中,再選出季營收年增率前10強
position *= rev_yoy_growth
position = position[position>0].is_largest(10)
# # 設定position_limit避免重壓
report = sim(position=position,resample='2W',stop_loss=0.2,take_profit=0, position_limit=0.1, fee_ratio=0, tax_ratio=0, name="美股_營收突破策略")
# report.display()
from finlab import data
from finlab.backtest import sim
close = data.get('us_price:close')
adj_close = data.get('us_price:adj_close')
vol = data.get('us_price:volume')
rev = data.get('us_fundamental:revenue')
def 成長率(s):
return ((s-s.shift(4)) / s.shift(4).abs()) * 100
rev_yoy_growth = 成長率(rev)
# 近1季營收創近1年來新高
condition1 = rev == rev.rolling(4, min_periods=2).max()
# 近5日內至少有2日股價創100日新高
condition2 = (close == close.rolling(100).max()).sustain(5,2)
# 5日成交均量大於500000股
condition3 = vol.average(5) > 500000
position = condition1 & condition2 & condition3
# 符合選股條件的名單中,再選出季營收年增率前10強
position *= rev_yoy_growth
position = position[position>0].is_largest(10)
# # 設定position_limit避免重壓
report = sim(position=position,resample='2W',stop_loss=0.2,take_profit=0, position_limit=0.1, fee_ratio=0, tax_ratio=0, 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 | |
---|---|---|---|---|
26.63% | 0.77 | -39.57% | 51.69% |
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 | ||||||||||||||||||
APLD APPLIED DIGITAL CORP | 2023-05-22 | NaT | 2023-05-19 | NaT | 0.1 | 14.0 | 1606.0 | -1.0 | -4.934602e-02 | 8.41 | 7.995 | -0.057075 | 1.521998e-01 | 0.080856 | -0.174923 | 9.0 | 0.1 | 0.1 |
CTIC CTI BIOPHARMA CORP | 2023-06-05 | NaT | 2023-06-02 | NaT | 0.1 | 5.0 | 1615.0 | -1.0 | 2.220446e-16 | 9.05 | 9.050 | -0.001105 | 2.220446e-16 | 0.000000 | -0.001105 | 2.0 | 0.1 | 0.1 |
ELF ELF BEAUTY INC | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | -5.708306e-03 | 105.11 | 104.510 | -0.015508 | 1.788602e-02 | 0.017886 | -0.032807 | 2.0 | 0.1 | 0.0 |
HRZN HORIZON TECHNOLOGY FINANCE CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 5.838198e-03 | 11.99 | 12.060 | 0.000000 | 2.001668e-02 | 0.000000 | -0.013900 | 4.0 | 0.1 | 0.0 |
INTR INTER & CO INC | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 1.395349e-01 | 3.01 | 3.430 | 0.000000 | 1.395349e-01 | 0.000000 | -0.036697 | 4.0 | 0.1 | 0.0 |
MVIS MICROVISION INC | 2023-06-05 | NaT | 2023-06-02 | NaT | 0.1 | 5.0 | 1615.0 | -1.0 | 2.570356e-01 | 5.33 | 6.700 | 0.000000 | 4.352720e-01 | 0.000000 | -0.124183 | 4.0 | 0.1 | 0.1 |
OMER OMEROS CORP | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | 3.305785e-02 | 7.26 | 7.500 | -0.028926 | 4.269972e-02 | 0.000000 | -0.028926 | 2.0 | 0.1 | 0.0 |
OUST OUSTER INC | 2023-05-22 | NaT | 2023-05-19 | 2023-06-18 | 0.1 | 14.0 | 1606.0 | -1.0 | -1.107595e-01 | 6.32 | 5.620 | -0.110759 | 1.487342e-01 | 0.148734 | -0.225895 | 9.0 | 0.1 | 0.0 |
PIII P3 HEALTH PARTNERS INC | 2023-06-05 | NaT | 2023-06-02 | 2023-06-18 | 0.1 | 5.0 | 1615.0 | -1.0 | -1.488550e-01 | 5.24 | 4.460 | -0.148855 | 0.000000e+00 | 0.000000 | -0.148855 | 0.0 | 0.1 | 0.0 |
SYM SYMBOTIC INC | 2023-06-05 | NaT | 2023-06-02 | NaT | 0.1 | 5.0 | 1615.0 | -1.0 | 2.537096e-01 | 34.37 | 43.090 | 0.000000 | 2.537096e-01 | 0.000000 | 0.000000 | 4.0 | 0.1 | 0.1 |
ADVM ADVERUM BIOTECHNOLOGIES INC | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
CCL CARNIVAL CORP | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
IMPP IMPERIAL PETROLEUM INC/MARSHALL ISLANDS | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
LI LI AUTO INC | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
NU NU HOLDINGS LTD | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
SAGE SAGE THERAPEUTICS INC | NaT | NaT | 2023-06-18 | NaT | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 0.0 | 0.1 |
In [ ]:
Copied!