三个月100倍的“策略”:
```
import datetime
# 初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
set_option('use_real_price', True)
run_weekly(market_open, weekday=1, time='open', reference_security='000300.XSHG')
# 开盘时运行函数
def market_open(context):
end_date = context.previous_date + datetime.timedelta(days=7)
all_stocks = list(get_all_securities(date=context.previous_date).index)
h = get_price(all_stocks, end_date=end_date, fields='close', count=5, panel=False)
target_list = list(h.groupby('code')['close'].apply(lambda x: x.iloc[-1]/x.iloc[0]).sort_values(ascending=False).index[:5])
#
for stock in context.portfolio.positions:
if stock not in target_list:
order_target(stock,0)
#
for stock in target_list:
if stock not in context.portfolio.positions:
_order = order_target_value(stock, context.portfolio.available_cash)
if _order is not None and _order.filled > 0:
break
```