股價創新高動能
安裝套件¶
In [1]:
Copied!
!pip install finlab > log.txt
!pip install finlab > log.txt
股價創新高動能¶
In [2]:
Copied!
from finlab.backtest import sim
from finlab import data
# 標的範圍為上市櫃普通股
with data.universe(market='TSE_OTC'):
# 取得收盤價
close = data.get("price:收盤價")
# 股價創近200日新高
position = (close == close.rolling(200).max())
# 每兩週再平衡,單檔最大持股比例限制20%,停損20%
report = sim(position, resample="2W", position_limit=0.2, stop_loss=0.2, name="股價創新高策略", upload=False)
report.display()
from finlab.backtest import sim
from finlab import data
# 標的範圍為上市櫃普通股
with data.universe(market='TSE_OTC'):
# 取得收盤價
close = data.get("price:收盤價")
# 股價創近200日新高
position = (close == close.rolling(200).max())
# 每兩週再平衡,單檔最大持股比例限制20%,停損20%
report = sim(position, resample="2W", position_limit=0.2, stop_loss=0.2, name="股價創新高策略", upload=False)
report.display()
輸入成功!
WARNING:finlab.data:security_categories -- Daily data usage: 339.0 / 5000 MB WARNING:finlab.data:price:收盤價 -- Daily data usage: 360.5 / 5000 MB WARNING:finlab.data:etl:adj_close -- Daily data usage: 388.9 / 5000 MB