侠之大者 一起赚钱
最后更新于:2022-04-01 21:55:01
# 侠之大者 一起赚钱
> 来源:https://uqer.io/community/share/554048dff9f06c1c3d687fa5
在阔别七年的又一轮牛市里,炒股已经成为人们每天讨论的话题.
小老弟一直以为:"侠之大者,一起赚钱,一起嗨". 故借宝地献出珍藏多年的交易秘籍.
首先讲述一下策略思路:
+ 标的: 流通性较好,深受大妈喜爱的沪深300成分股, 乃策略标的最佳选择.
+ 买卖点: 追涨杀跌是本策略的核心思路. 在股价,成交量向上突破最近20日最高价格(量)时买入. 在股价向下突破最近10日最低价格卖出.
+ 头寸规模:每只股票最多占1/10仓位.
话不多说, 上代码:
```py
start = datetime(2013, 1, 1)
end = datetime(2015, 5, 25)
benchmark = 'HS300'
universe = set_universe('HS300')
capital_base = 100000
pos_pieces = 10
enter_window = 20
exit_window = 10
def initialize(account):
pass
def handle_data(account):
highest_price = account.get_attribute_history('highPrice', enter_window)
lowest_price = account.get_attribute_history('lowPrice', exit_window)
close_price = account.get_attribute_history('closePrice', exit_window)
turnover_vol = account.get_attribute_history('turnoverVol', enter_window)
for stock in account.universe:
cnt_price = close_price[stock][-1] #account.referencePrice[stock]
cnt_turnover = turnover_vol[stock][-1]
if cnt_price > highest_price[stock][:-1].max() and cnt_turnover > turnover_vol[stock][:-1].max() and account.position.secpos.get(stock, 0)==0:
order(stock, capital_base/pos_pieces/cnt_price)
elif cnt_price < lowest_price[stock][:-1].min():
order_to(stock, 0)
```
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-07-30_579cbdac9b8db.jpg)
也许已经有人发现, 其实这就是海龟交易系统.
海龟交易系统是一个完整的交易系统,它有一个完整的交易系统所应该有的所有成分,涵盖了成功交易中的每一个必要决策:
+ 市场:买卖什么?
+ 头寸规模:买卖多少?
+ 入市:什么时候买卖?
+ 止损:什么时候放弃一个亏损的头寸?
+ 退出:什么时候退出一个盈利的头寸?
+ 战术:怎么买卖?
在上面的策略中, 每只股票的头寸规模为1/10的初始资金.
《海龟交易法则》介绍了一种头寸规模控制方法, 将头寸分为一个个单位, 下面的策略将展示将头寸分为N个单位, 每次产生买入信号时, 仅买入一个单位.
```py
start = datetime(2013, 1, 1)
end = datetime(2015, 5, 25)
benchmark = 'HS300'
universe = set_universe('HS300')
capital_base = 100000
pos_pieces = 10
enter_window = 20
exit_window = 10
N = 4
def initialize(account):
account.postion_size_hold = {}
for stk in universe:
account.postion_size_hold[stk] = 0
def handle_data(account):
highest_price = account.get_attribute_history('highPrice', enter_window)
lowest_price = account.get_attribute_history('lowPrice', exit_window)
close_price = account.get_attribute_history('closePrice', exit_window)
turnover_vol = account.get_attribute_history('turnoverVol', enter_window)
for stock in account.universe:
cnt_price = close_price[stock][-1] #account.referencePrice[stock]
cnt_turnover = turnover_vol[stock][-1]
if cnt_price > highest_price[stock][:-1].max() and cnt_turnover > turnover_vol[stock][:-1].max() and account.postion_size_hold[stock]= high_channel and account.postion_size_hold[stock]
';