forked from bbfamily/abu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,753 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- encoding:utf-8 -*- | ||
""" | ||
卖出择时示例因子:n日卖出策略,不管什么结果,买入后只持有N天 | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
from __future__ import division | ||
|
||
from .ABuFactorSellBase import AbuFactorSellBase, filter_sell_order, skip_last_day, ESupportDirection | ||
|
||
__author__ = '阿布' | ||
__weixin__ = 'abu_quant' | ||
|
||
|
||
class AbuFactorSellNDay(AbuFactorSellBase): | ||
"""n日卖出策略,不管交易现在什么结果,买入后只持有N天""" | ||
|
||
def _init_self(self, **kwargs): | ||
"""kwargs中可以包含: 参数sell_n:代表买入后持有的天数,默认1天""" | ||
self.sell_n = kwargs.pop('sell_n', 1) | ||
self.sell_type_extra = '{}:sell_n={}'.format(self.__class__.__name__, self.sell_n) | ||
|
||
def support_direction(self): | ||
"""因子支持两个方向""" | ||
return [ESupportDirection.DIRECTION_CAll.value, ESupportDirection.DIRECTION_PUT.value] | ||
|
||
@skip_last_day | ||
@filter_sell_order | ||
def fit_day(self, today, orders): | ||
""" | ||
:param today: 当前驱动的交易日金融时间序列数据 | ||
:param orders: 买入择时策略中生成的订单序列 | ||
:return: | ||
""" | ||
for order in orders: | ||
# 将单子的持有天数进行增加 | ||
order.keep_days += 1 | ||
if order.keep_days >= self.sell_n: | ||
# 只要超过self.sell_n即卖出 | ||
order.fit_sell_order(int(today.key), self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
,symbol,product,min_deposit,min_unit,exchange | ||
0,NID,伦敦镍,0.07,6,LME | ||
1,PBD,伦敦铅,0.1,25,LME | ||
2,SND,伦敦锡,0.05,5,LME | ||
3,ZSD,伦敦锌,0.1,25,LME | ||
4,AHD,伦敦铝,0.08,25,LME | ||
5,CAD,伦敦铜,0.08,25,LME | ||
6,XAU,伦敦金,0.1,1,LME | ||
7,XAG,伦敦银,0.1,100,LME | ||
8,XPT,伦敦铂金,0.1,1,LME | ||
9,S,美黄豆,0.1,5000,CBOT | ||
10,W,美小麦,0.1,5000,CBOT | ||
11,C,美玉米,0.1,5000,CBOT | ||
12,BO,美豆油,0.1,60000,CBOT | ||
13,SM,美豆粕,0.1,100,CBOT | ||
14,HG,纽约铜,0.1,25000,NYMEX | ||
15,SI,纽约白银,0.08,5000,NYMEX | ||
16,GC,纽约黄金,0.08,100,NYMEX | ||
17,CL,纽约原油,0.07,1000,NYMEX | ||
18,NG,纽约天然气,0.07,10000,NYMEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.