金融量化分析【day113】:羊驼策略

金融量化分析【day113】:羊驼策略零 动量策略 VS 反转策略 1 实现代码 导入函数库 import jqdata import pandas as pd import numpy as np import datetime import math def initialize context set option use real price

大家好,我是讯享网,很高兴认识大家。

 零、动量策略VS反转策略

1、实现代码


讯享网

# 导入函数库 import jqdata import pandas as pd import numpy as np import datetime import math def initialize(context): set_option('use_real_price', True) set_order_cost(OrderCost(close_tax=0.001, open_commission=0.0003, close_commission=0.0003, min_commission=5), type='stock') g.benchmark = '000300.XSHG' g.N = 10 set_benchmark(g.benchmark) run_monthly(handle, 1) def handle(context): stock = get_index_stocks('000300.XSHG') df_close = history(30,field='close',security_list=list(stock)).T df_close['ret']=(df_close.iloc[:,-1]-df_close.iloc[:,0])/df_close.iloc[:,0] sorted_stocks = df_close.sort('ret',ascending=True).index tohold = sorted_stocks[:g.N] for stock in context.portfolio.positions: if stock not in tohold: order_target_value(stock, 0) tobuy = [stock for stock in tohold if stock not in context.portfolio.positions] if len(tobuy) > 0: print('Buying') cash = context.portfolio.available_cash / len(tobuy) cash_every_stock = cash / len(tobuy) for stock in tobuy: order_value(stock, cash_every_stock) 

讯享网
小讯
上一篇 2025-02-10 11:14
下一篇 2025-04-08 18:53

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/135655.html