from finlab import data
from finlab.backtest import sim
close_not_adj =data.get('price:收盤價')
close_adj = data.get('etl:adj_close')
mon_rev =data.get("monthly_revenue:當月營收")
mon_rev_lag =data.get("monthly_revenue:去年當月營收")
three_mon_rev_yoy = mon_rev.rolling(3).sum()/mon_rev_lag.rolling(3).sum()
twelve_mon_rev_yoy = mon_rev.rolling(12).sum()/mon_rev_lag.rolling(12).sum()
statement_dog_rev_index = three_mon_rev_yoy/twelve_mon_rev_yoy >1.05
close = data.get('price:收盤價')
condition = statement_dog_rev_index &(close>0)
result = condition
entries = result
sellout = (three_mon_rev_yoy<twelve_mon_rev_yoy)&(close>0)
position = entries.hold_until(sellout ).reindex(mon_rev.index_str_to_date().index, method='ffill')
report = sim(position,mae_mfe_window=22,mae_mfe_window_step=2, name="財報狗獨家數據")
report.display()
report.display_mae_mfe_analysis()
此為使用finlab回測使用的程式碼