frames = []
for stock_index in etf50_id:
print(stock_index)
tmp_df = etf50[stock_index]
holding_cash = (
1000
* tmp_df.groupby(pd.DatetimeIndex(tmp_df.index).to_period("M"))
.nth(0)["Close"]
.sum()
)
test = Backtest(
etf50[stock_index],
ContinueHolding,
cash=holding_cash,
commission=0.004,
# exclusive_orders=True,
trade_on_close=True,
)
result = test.run()
result["stock_id"] = stock_index
result["Cash"] = holding_cash
result["Strategy"] = result["_strategy"].__class__.__name__
result["Params"] = result["_strategy"].params
df = result.to_frame().transpose()
frames.append(df)
本金 = Sum( 每月交易日首日收盘价 * 1000 )
tmp_df = etf50[stock_index]
holding_cash = (
1000
* tmp_df.groupby(pd.DatetimeIndex(tmp_df.index).to_period("M"))
.nth(0)["Close"]
.sum()
)
test = Backtest(
etf50[stock_index],
ContinueHolding,
cash=holding_cash,
commission=0.004,
# exclusive_orders=False,
trade_on_close=True,
)
result = test.run()
final_df = pd.concat(frames).reset_index(drop=True)
final_df = final_df.loc[
final_df["Duration"] == final_df["Duration"].max()
].reset_index(drop=True)
etf50_df = final_df.loc[final_df["stock_id"] == "0050", "Return (Ann.) [%]"]
profit_df = final_df[final_df["Return (Ann.) [%]"] >= etf50_df[0]]
由报表可以看出,以平均来说「只买不卖」策略低的可怜,
年化报酬率只有可怜的0.73%(甚至比定存还低),
而所有成分股中超过ETF50投资报酬率的只有13个,
我们可以将其当成日後其他策略的参考线,
只要年化报酬率低於**「只买不卖」策略或ETF50**的年化报酬率,
即可视为「糟糕」的策略。
股票ID | 股票名称 | 年化报酬率 [%] | 夏普率 | 系统质量(SQN) |
---|---|---|---|---|
TW | 台股平均 | 0.73529 | ||
0050 | 元大台湾50 | 1.75358 | 0.206715 | 7.19137 |
2330 | 台积电 | 5.78504 | 0.431027 | 12.2543 |
1301 | 台塑 | 2.30122 | 0.199212 | 11.2324 |
1216 | 统一 | 2.7866 | 0.210213 | 13.1493 |
3008 | 大立光 | 2.62141 | 0.0995397 | 3.0121 |
5871 | 中租-KY | 4.62837 | 0.291684 | 13.0569 |
1326 | 台化 | 2.85479 | 0.218428 | 11.1298 |
2379 | 瑞昱 | 6.71893 | 0.319554 | 20.2988 |
2327 | 国巨 | 14.9039 | 0.389574 | 8.04219 |
2912 | 统一超 | 4.59893 | 0.30617 | 15.5105 |
6505 | 台塑化 | 2.69953 | 0.173866 | 9.66391 |
1590 | 亚德客-KY | 2.39312 | 0.0805668 | 3.92964 |
9910 | 丰泰 | 7.19998 | 0.319489 | 11.4869 |
2408 | 南亚科 | 5.61503 | 0.151951 | 5.1359 |
<<: DAY21 搞样式--CSS Gird小进阶(Template Area)
原理 昨天有提到 Bagging 最有名的例子就是随机森林,它是集合多棵决策树来进行预测,很多树就成...
CSS是啥? 全名为(Cascading Stylesheets),谷哥中文是阶层样式表,是一种风...
Optimizer 优化器 神经网路是由多个神经元节点组成,每个神经元(Neuron)都拥有自己的权...
在 Objective-C 中,为了保存基本的资料类型,像是 int, float, bool,内建...
前言 第三天要延续介绍如何处理一笔数据。 对於数据分析的用途跟前几个步骤 请看上一篇文章 数据分析...