abupy.UmpBu package¶
Submodules¶
abupy.UmpBu.ABuUmp module¶
abupy.UmpBu.ABuUmpBase module¶
ump基础模块
-
class
abupy.UmpBu.ABuUmpBase.
AbuUmpBase
[源代码]¶ Bases:
abc.NewBase
ump拦截缓存,在AbuUmpBase类中
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf_manager
= <abupy.UmpBu.ABuUmpBase.CachedUmpManager object>¶
-
classmethod
-
class
abupy.UmpBu.ABuUmpBase.
BuyUmpMixin
[源代码]¶ Bases:
object
买入ump混入, 与BuyFeatureMixin不同,每一个具体的ump只能属于一个ump类别 即不是BuyUmpMixin就应该是SellUmpMixin
-
class
abupy.UmpBu.ABuUmpBase.
CachedUmpManager
[源代码]¶ Bases:
object
ump拦截缓存实体,分别在主裁和边裁类中
-
get_ump
(ump)[源代码]¶ 主要在具体裁判类的predict方法中获取裁判本体使用,如果 不在_cache中load_pickle,否则使用catch中的ump返回 :param ump: 具体裁判对象,AbuUmpBase对象 :return: 每个裁判需要的决策数据,每类裁判主体的数据形式不同,且使用方法不同
- eg:主裁中的使用
- def predict(self, x, need_hit_cnt=1):
dump_clf_with_ind = AbuUmpMainBase.dump_clf_manager.get_ump(self) count_hit = 0 for clf, ind in dump_clf_with_ind.values():
ss = clf.predict(x) if ss == ind:
count_hit += 1 if need_hit_cnt == count_hit:
return 1return 0
-
s_use_weak
= False¶
-
-
class
abupy.UmpBu.ABuUmpBase.
SellUmpMixin
[源代码]¶ Bases:
object
卖出ump混入, 与SellFeatureMixin不同,每一个具体的ump只能属于一个ump类别 即不是BuyUmpMixin就应该是SellUmpMixin
-
class
abupy.UmpBu.ABuUmpBase.
UmpDict
[源代码]¶ Bases:
dict
Several built-in types such as list and dict do not directly support weak references but can add support through subclassing:
-
abupy.UmpBu.ABuUmpBase.
ump_edge_make_xy
(func)[源代码]¶ 边裁中对应fiter class中make_xy的装饰器, 使用eg:详阅AbuUmpEdgeDeg或其它边裁子类实现
- class AbuUmpEdgeDeg(AbuUmpEdgeBase, BuyUmpMixin):
- class UmpDegFiter(AbuMLPd):
@ump_edge_make_xy def make_xy(self, **kwarg):
filter_list = [‘profit’, ‘profit_cg’] cols = AbuFeatureDeg().get_feature_ump_keys(ump_cls=AbuUmpEdgeDeg) filter_list.extend(cols) # noinspection PyUnresolvedReferences deg_df = self.order_has_ret.filter(filter_list) return deg_df
-
abupy.UmpBu.ABuUmpBase.
ump_main_make_xy
(func)[源代码]¶ 主裁中对应fiter class中make_xy的装饰器, 使用eg:详阅ABuUmpMainDeg或其它主裁子类实现
- class AbuUmpMainDeg(AbuUmpMainBase, BuyUmpMixin):
- class UmpDegFiter(AbuMLPd):
@ump_main_make_xy def make_xy(self, **kwarg):
- regex = ‘result|{}’.format(
- ‘|’.join(AbuFeatureDeg().get_feature_ump_keys(ump_cls=AbuUmpMainDeg)))
# noinspection PyUnresolvedReferences deg_df = self.order_has_ret.filter(regex=regex) return deg_df
abupy.UmpBu.ABuUmpEdgeBase module¶
边裁基础实现模块
-
class
abupy.UmpBu.ABuUmpEdgeBase.
AbuUmpEdgeBase
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpBase.AbuUmpBase
边裁基类
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf
()[源代码]¶ 边裁的本地序列化相对主裁的dump_clf也简单很多, 将self.fiter.df和self.fiter.x打包成一个字典对象df_x_dict 通过ABuFileUtil.dump_pickle进行保存
-
dump_file_fn
()[源代码]¶ 边裁本地缓存的存储路径规则: ABuEnv.g_project_data_dir + ‘ump/ump_edge_‘ + market_name + self.class_unique_id()
-
fit
()[源代码]¶ 边裁训练集拟合存储函数,相对主裁的训练fit函数,边裁的fit很简单 self.fiter.df经过fit后添加了新列p_rk_cg和rk形式如下所示
- eg:self.fiter.df
- profit profit_cg buy_deg_ang42 buy_deg_ang252 2014-09-24 -22618.04 -0.0566 3.378 3.458
2014-10-24 -29690.28 -0.0742 0.191 2.889 2014-10-29 18959.19 0.0542 -2.026 16.689 2014-10-29 148209.36 0.5022 -3.427 -11.956 2014-10-29 24867.60 0.0952 -2.915 39.469 2014-10-29 18959.19 0.0542 -2.026 16.689 2014-11-03 1250.80 0.0045 0.103 39.202 2014-11-11 59888.21 0.1857 8.341 -9.450 2014-11-12 -3578.78 -0.0140 3.963 6.595 2014-11-26 -29085.19 -0.0946 14.052 6.061 ... ... ... ... ... 2016-03-14 16220.57 0.0559 4.002 -10.559 2016-03-14 -25328.12 -0.1218 0.129 -6.649 2016-03-30 -29858.44 -0.0863 13.121 -8.461 2016-04-04 5373.76 0.0244 4.409 -33.097 2016-04-13 -28044.40 -0.1159 6.603 -31.459 2016-04-14 -18645.93 -0.0467 4.611 18.428 2016-04-15 -32484.79 -0.1149 4.238 -13.247 2016-04-15 -32484.79 -0.1149 4.238 -13.247 2016-04-29 290.96 0.0007 1.445 16.266 2016-04-29 290.96 0.0007 1.445 16.266
buy_deg_ang60 buy_deg_ang21 p_rk_cg rk2014-09-24 3.458 1.818 19.0 0 2014-10-24 2.809 -1.089 13.0 -1 2014-10-29 -0.761 1.980 35.5 0 2014-10-29 -8.296 6.507 56.0 1 2014-10-29 -6.043 7.046 43.0 1 2014-10-29 -0.761 1.980 35.5 0 2014-11-03 -4.614 10.125 28.0 0 2014-11-11 0.730 12.397 48.0 1 2014-11-12 -7.524 6.671 23.0 0 2014-11-26 7.566 12.494 9.0 -1 ... ... ... ... .. 2016-03-14 -7.992 9.324 37.0 0 2016-03-14 -10.880 5.201 2.0 -1 2016-03-30 4.498 4.070 12.0 -1 2016-04-04 -6.281 5.618 33.0 0 2016-04-13 0.191 4.457 4.0 -1 2016-04-14 3.134 0.733 20.0 0 2016-04-15 4.693 1.162 5.5 -1 2016-04-15 4.693 1.162 5.5 -1 2016-04-29 4.615 -1.115 24.5 0 2016-04-29 4.615 -1.115 24.5 0
边裁裁决方式多次使用非均衡技术对最后的结果概率进行干预,目的是使最终的裁决正确率达成非均衡的目标, 非均衡技术思想是量化中很很重要的一种设计思路,因为我们量化的目标结果就是非均衡(我们想要赢的钱比输的多)
-
fiter
= None¶ 通过self.fiter_cls构造形成self.fiter后self.fiter.df中以存在特征
- eg:self.fiter.df
- profit profit_cg buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang21
2014-09-24 -22618.04 -0.0566 3.378 3.458 3.458 1.818 2014-10-24 -29690.28 -0.0742 0.191 2.889 2.809 -1.089 2014-10-29 18959.19 0.0542 -2.026 16.689 -0.761 1.980 2014-10-29 148209.36 0.5022 -3.427 -11.956 -8.296 6.507 2014-10-29 24867.60 0.0952 -2.915 39.469 -6.043 7.046
-
predict
(**kwargs)[源代码]¶ 边裁交易决策函数,从CachedUmpManager中获取缓存df_x_dict,对kwargs关键字参数所描述的交易特征进行拦截决策 边裁的predict()实现相对主裁来说比较复杂,大致思路如下:
- 从输入的新交易中挑选需要的特征组成x
- 将x和之前保存的训练集数据组合concatenate(),一起做数据标准化scaler
- 使用sklearn.metrics.pairwise.pairwise_distances()度量输入特征和训练集矩阵中的距离序列
- 取pairwise_distances() TOP个作为种子,继续匹配相似度
- 相似度由大到小排序,保留大于保留阀值的相似度交易数据做为最终有投票权利的
- 保留的交易认为是与新交易最相似的交易,保留的交易使用之前非均衡的rk对新交易进行投票
- 最后的判断需要大于一定比例才被结果认可,即再次启动非均衡
参数: kwargs – 需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818返回: 是否对kwargs关键字参数所描述的交易特征进行拦截, EEdgeType: 不拦截: EEdgeType.E_EEdge_NORMAL or EEdgeType.E_STORE_TOP_WIN 拦截: EEdgeType.E_EEdge_TOP_LOSS
-
classmethod
ump_edge_clf_dump
(orders_pd_train, show_info=False, market_name=None)[源代码]¶ 类方法,通过交易训练集orders_pd_train构造AbuUmpEdgeBase子类对象, 使用fit方法对训练集进行特征采集,后进行dump_clf即 本地序列化存贮等工作 :param orders_pd_train: 交易训练集,pd.DataFrame对象 :param show_info: 是否显示edge.fiter.df.head(),默认False :param market_name: 主裁训练或者获取裁判对应的存贮唯一名称,默认None, 根据env中的当前市场设置存储名称 :return: AbuUmpEdgeBase子类对象实例
-
classmethod
-
class
abupy.UmpBu.ABuUmpEdgeBase.
EEdgeType
[源代码]¶ Bases:
enum.Enum
对交易的利润亏损进行rank后的分类结果
-
E_EEdge_NORMAL
= 0¶ 盈利最多的一类交易,可理解为最顶端
-
E_EEdge_TOP_LOSS
= -1¶ 其它的普通收益亏损的交易,在整个训练集交易中占最多数
-
E_STORE_TOP_WIN
= 1¶
-
-
abupy.UmpBu.ABuUmpEdgeBase.
K_CG_TOP_RATE
= 0.236¶ 在predict中最后的投票结果需要大于一定比例才被认可, 即对有争议的投票需要一方拥有相对优势才认可
-
abupy.UmpBu.ABuUmpEdgeBase.
K_DISTANCE_THRESHOLD
= 0.668¶ 从第一轮pairwise_distances的结果使用argsort后取K_N_TOP_SEED个做为第二轮相似匹配的种子
-
abupy.UmpBu.ABuUmpEdgeBase.
K_N_TOP_SEED
= 100¶ 完成第二轮相似度匹配后使用K_SIMILAR_THRESHOLD做为阀值过滤后得到有投票权的向量
-
abupy.UmpBu.ABuUmpEdgeBase.
K_SIMILAR_THRESHOLD
= 0.91¶ K_CG_TOP_RATE做为计算win_top和loss_top win_top = len(self.fiter.df[‘profit_cg’]) - len(self.fiter.df[‘profit_cg’]) * K_CG_TOP_RATE eg:
- len(self.fiter.df[‘profit_cg’]) == 100
- -> win_top = 100 - 100 * 0.236 -> win_top = 100 - 23.6 -> win_top = 76.4
loss_top = len(self.fiter.df[‘profit_cg’]) * K_CG_TOP_RATE eg:
len(self.fiter.df[‘profit_cg’]) == 100 -> loss_top = 100 * 0.236 -> loss_top = 23.6
abupy.UmpBu.ABuUmpEdgeDeg module¶
示例ump边裁特征走势拟合角度模块
-
class
abupy.UmpBu.ABuUmpEdgeDeg.
AbuUmpEdgeDeg
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁走势拟合角度特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpDegFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成deg_df ump_edge_make_xy装饰器在make_xy返回deg_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘deg_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.ABuUmpEdgeDeg.
AbuUmpEegeDegExtend
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁使用新的视角来决策交易,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpExtendEdgeFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
-
class
abupy.UmpBu.ABuUmpEdgeFull module¶
示例ump边裁特征多混模块
-
class
abupy.UmpBu.ABuUmpEdgeFull.
AbuUmpEdgeFull
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁多混特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpFullFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成full_df ump_edge_make_xy装饰器在make_xy返回full_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘full_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
get_fiter_class
()[源代码]¶ 边裁多混特征返回的AbuMLPd子类:AbuUmpEdgeFull.UmpFullFiter :return: AbuUmpEdgeFull.UmpFullFiter
-
get_predict_col
()[源代码]¶ - 边裁多混特征keys:
- [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
返回: [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
-
class
abupy.UmpBu.ABuUmpEdgeMul module¶
示例ump边裁特征单混模块
-
class
abupy.UmpBu.ABuUmpEdgeMul.
AbuUmpEdgeMul
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁单混特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpMulFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成mul_df ump_edge_make_xy装饰器在make_xy返回mul_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘mul_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpEdgePrice module¶
示例ump边裁特征价格模块
-
class
abupy.UmpBu.ABuUmpEdgePrice.
AbuUmpEdgePrice
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁价格特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpPriceFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成price_df ump_edge_make_xy装饰器在make_xy返回price_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘price_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpEdgeWave module¶
示例ump边裁价格波动特征模块
-
class
abupy.UmpBu.ABuUmpEdgeWave.
AbuUmpEdgeWave
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁价格波动特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpWaveFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成wave_df ump_edge_make_xy装饰器在make_xy返回wave_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘wave_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpMainBase module¶
主裁基础实现模块
-
class
abupy.UmpBu.ABuUmpMainBase.
AbuUmpMainBase
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpBase.AbuUmpBase
主裁基类
-
best_hit_cnt_info
(llps=None)[源代码]¶ 辅助工具函数,通过统计在各个分类簇中重复出现的交易单子,计算出 平均值
参数: llps – llps对象,默认参数llps=None将使用llps = self.llps
- eg: llps形式如
- lcs lms lps lrs
15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
brust_min
()[源代码]¶ 在fit操作之后对self.cprs进行分析可以发现,这些分类中存在很多分类簇中的交易胜率不高, 但是交易获利比例总和却为正值,也就是说这个分类簇由于非均衡赔率使得非均衡胜率得以保持平衡, 并且最终获利,那么我们将所有分类簇保存在本地,对之后的交易进行裁决显然是不妥当的,所以需要使用 全局最优技术对分类簇集合进行筛选
- 将lps的范围选定(分类簇中交易获利比例总和最小值-0), 即醋中交易获胜比例组合大于0的过滤
- 将lms的范围选定(分类簇中交易获利比例平均值最小值-0), 即醋中交易获利比例平均值大于0的过滤
- 将lrs交易醋失败率从最小值-最大值
- 计算最小值-0(最大值)之间合适的step值
- bnds = (slice(lps_min, 0, lps_step), slice(lms_min, 0, lms_step), slice(lrs_min, lrs_max, lrs_step))
6. sco.brute中设定最优函数self.min_func_improved使用bnds进行计算 更多详见brust_min实现函数
-
choose_cprs_component
(llps=None)[源代码]¶ 辅助工具函数,输出显示在llps下训练集交易中的生效数量,和训练集可提升数据比例 以及可视化所有训练集中被拦截的交易profit_cg的cumsum
参数: llps – llps对象,默认参数llps=None将使用llps = self.llps
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf
(llps=None)[源代码]¶ - 通过llps.index,从self.rts中获取GaussianMixture对象,即self.rts[clf][0]
eg: llps.index Index([‘14_7’, ‘14_8’, ‘14_9’, ‘14_10’, ‘15_7’, ‘15_8’, ‘15_9’, ‘15_10’,
- ‘16_7’, ‘16_8’, ‘16_9’, ‘16_10’, ‘17_7’, ‘17_8’, ‘17_9’, ‘17_10’,
‘27_14’, ‘27_15’, ‘27_17’, ‘27_18’, ‘27_24’], dtype=’object’)
2. 将cluster和GaussianMixture对象做为value,llps.index中的元素做为key形成最终序列化的dict对象形式如下所示 eg:
{ ‘14_7’: (GaussianMixture(covariance_type=’full’, init_params=’kmeans’, max_iter=100,
means_init=None, n_components=14, n_init=1, precisions_init=None, random_state=3, reg_covar=1e-06, tol=0.001, verbose=0, verbose_interval=10, warm_start=False, weights_init=None), 7),- ‘14_8’: (GaussianMixture(covariance_type=’full’, init_params=’kmeans’, max_iter=100,
- means_init=None, n_components=14, n_init=1, precisions_init=None, random_state=3, reg_covar=1e-06, tol=0.001, verbose=0, verbose_interval=10, warm_start=False, weights_init=None), 8)
}
3. 通过ABuFileUtil.dump_pickle最终将元素序列化保存在本地 :param llps: 需要最终保存的llps对象,默认参数llps=None将使用llps = self.llps
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
dump_file_fn
()[源代码]¶ 主裁本地缓存的存储路径规则: ABuEnv.g_project_data_dir + ‘ump/ump_main_‘ + market_name + self.class_unique_id()
-
fit
(p_ncs=None, threshold=0.65, brust_min=True, show=True)[源代码]¶ 交易训练集训练拟合函数,根据规则计算gmm分类的范围,使用gmm对训练集交易进行阀值筛选, 根据brust_min参数决定是否进行全局最优参数计算,最终生成self.rts,self.nts,self.cprs
- eg:self.rts字典形式如下:
key=component, value=(GaussianMixtured对象,cluster_ind: GMM(component)分component个类中, 满足子分类的失败率大于阀值threshold的子分类序号)
- {14: (GaussianMixture(max_iter=100, n_components=14, n_init=1),
- Int64Index([7, 8, 9, 10], dtype=’int64’, name=’cluster’)),
- 15: (GaussianMixture(max_iter=100, n_components=15, n_init=1),
- Int64Index([7, 8, 9, 10], dtype=’int64’, name=’cluster’))}
- eg: self.nts字典对象形式如下所示:
{ ‘14-7’:
result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang21 ind cluster2014-11-11 1 8.341 -9.450 0.730 12.397 7 7 2015-10-28 0 7.144 -9.818 -3.886 6.955 39 7 2015-11-04 0 12.442 -10.353 3.313 7.840 41 7 2016-03-30 0 13.121 -8.461 4.498 4.070 49 7 2016-04-15 0 4.238 -13.247 4.693 1.162 53 7 2016-04-15 0 4.238 -13.247 4.693 1.162 54 7 ...............................................................................................
- ‘14-8’:
- result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang21 ind cluster
2014-11-26 0 14.052 6.061 7.566 12.494 9 8 2015-04-22 1 20.640 2.751 20.436 18.781 23 8 2015-12-16 0 12.906 6.312 16.638 12.379 43 8
}
- eg: self.cprs pd.DataFrame对象形式如下
- lcs lms lps lrs
14_7 6 -0.0552 -0.3310 0.8333 14_8 3 -0.0622 -0.1866 0.6667 14_9 1 -0.1128 -0.1128 1.0000 14_10 2 -0.0327 -0.0654 1.0000 15_7 4 -0.1116 -0.4465 1.0000 15_8 3 -0.0622 -0.1866 0.6667 ... ... ... ... ... 27_8 1 -0.1128 -0.1128 1.0000 27_9 3 -0.0103 -0.0309 0.6667 27_14 1 -0.0946 -0.0946 1.0000 27_15 2 -0.1149 -0.2299 1.0000 27_17 1 -0.1041 -0.1041 1.0000 27_18 2 -0.0327 -0.0654 1.0000 27_24 1 -0.0140 -0.0140 1.0000
参数: - p_ncs – gmm分类的范围, 可以为具体序列对象如[10, 11, 12....80], 也可以为生成器对象, 如xrange(10, 80, 10),还支持slice对象,eg:slice(10, 80, 10)
- threshold – 分类簇中失败率选择的阀值(默认0.65),即大于threshold值的gmm分类簇做为主裁学习目标分类簇
- brust_min – bool类型,代表是否进行全局最优参数计算brust_min,如果否则直接使用默认g_brust_min_default(0, 0, 0.65) 如果不使用brust_min,即brust_min=False可大大提高训练运行效率
- show – 是否可视化lcs,lrs,lps,lms数据(2d, 3d)
-
fiter
= None¶ self.fiter是AbuMLPd子类对象,在init中即通过make_xy筛选出orders_pd中需要的训练集特征,在子类 实现的make_xy函数都被主裁装饰器函数ump_main_make_xy装饰对筛选出的训练集特征进行转换矩阵,提取x, y序列等统一操作,详阅AbuUmpMainDeg等示例主裁具体子类
这里构造好的self.fiter中df对象已经存在特定的特征 eg: self.fiter.df
result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang212014-09-24 0 3.378 3.458 3.458 1.818 2014-10-24 0 0.191 2.889 2.809 -1.089 2014-10-29 1 -2.026 16.689 -0.761 1.980 2014-10-29 1 -3.427 -11.956 -8.296 6.507 2014-10-29 1 -2.915 39.469 -6.043 7.046
-
hit_cnt
(x)[源代码]¶ 辅助统计工具函数,从CachedUmpManager中获取缓存clf_cluster_dict,迭代ump字典对象, 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict 结果和 (clf, cluster)中存储的cluster一致的情况下代表hit
参数: x – 交易特征形成的x eg: array([[ 8.341, -9.45 , 0.73 , 12.397]]) 返回: kwargs关键字参数所描述的交易特征进行分类簇命中统计,返回int值
-
min_func
(l_pmr)[源代码]¶ - 使用lps,lms,lrs的特点组合值获取crps的子pd.DataFrame对象:
- llps = self.cprs[(self.cprs[‘lps’] <= l_pmr[0]) & (self.cprs[‘lms’] <= l_pmr[1]) &
- (self.cprs[‘lrs’] >= l_pmr[2])]
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
- 通过llps从self.nts字典中获取原始训练集特征数据:
- result deg_ang21 deg_ang42 deg_ang60 deg_ang252 ind cluster
2011-09-21 0 8.645 -3.294 -8.426 -8.758 40 48 -0.083791 2011-09-30 0 11.123 -1.887 -2.775 1.585 158 49 -0.066309
- 计算llps组合的情况下拦截的单子的数量,以及胜率,失败率,通过:
improved = (effect_num / self.fiter.order_has_ret.shape[0]) * (loss_rate - win_rate)
eg:(effect_num / self.fiter.order_has_ret.shape[0]) * (loss_rate - win_rate) effect_num = 10, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.8, win_rate =0.2 -> (10 / 100) * (0.8 - 0.2) = 0.06
effect_num = 50, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.8, win_rate =0.2 -> (50 / 100) * (0.8 - 0.2) = 0.3
effect_num = 50, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.9, win_rate =0.1 -> (50 / 100) * (0.9 - 0.1) = 0.4
即最终提升的比例和llps下被拦截的交易数量成正比,和llps下被拦截的交易失败率成正比
即计算llps组合的情况下,即参数l_pmr给定的lps,lms,lrs的特点组合下的交易提升值 :param l_pmr: 可迭代序列,eg:(-0.45, -0.11, 0.77), 由三个float值组成的序列
l_pmr[0]: 切取self.cprs使用的分类簇交易获利和值,即lps阀值:self.cprs[‘lps’] <= l_pmr[0] l_pmr[1]: 切取self.cprs使用的分类簇交易获利平均值,即lms阀值:self.cprs[‘lms’] <= l_pmr[1] l_pmr[2]: 切取self.cprs使用的分类簇交易失败比例,即lrs阀值:self.cprs[‘lrs’] >= l_pmr[2]返回: [improved, effect_num]
-
min_func_improved
(l_pmr)[源代码]¶ 包装min_func具体现实函数,在brust_min函数中使用: sco.brute(self.min_func_improved, bnds, full_output=False, finish=None) 计算最优参数组合,因为在self.min_func中计算的是提高improved值,要想得到最大 提高参数组合,即self.min_func返回值最大的组合,使用最优sco.brute的目标是 最小值,所以使用 -self.min_func(l_pmr)[0],找到最小值,结果的参数组合即为 最大提高improved值的参数组合 :param l_pmr: 可迭代序列,eg:(-0.45, -0.11, 0.77), 由三个float值组成的序列
l_pmr[0]: 切取self.cprs使用的分类簇交易获利和值,即lps阀值:self.cprs[‘lps’] <= l_pmr[0] l_pmr[1]: 切取self.cprs使用的分类簇交易获利平均值,即lms阀值:self.cprs[‘lms’] <= l_pmr[1] l_pmr[2]: 切取self.cprs使用的分类簇交易失败比例,即lrs阀值:self.cprs[‘lrs’] >= l_pmr[2]返回: -self.min_func(l_pmr)[0],即[improved, effect_num][0], 即improved值,float
-
predict
(x, need_hit_cnt=1)[源代码]¶ 主交易决策函数,从CachedUmpManager中获取缓存clf_cluster_dict,迭代ump字典对象, 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict 结果和 (clf, cluster)中存储的cluster一致的情况下代表hit,最终对交易 做出决策
参数: - x – 交易特征形成的x eg: array([[ 8.341, -9.45 , 0.73 , 12.397]])
- need_hit_cnt – 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict结果和 (clf, cluster)中存储的cluster一致的情况下代表hit一次:count_hit += 1 只有当need_hit_cnt == count_hit才最终做出决策对交易进行拦截
返回: 最终做出决策对交易是否进行拦截,拦截即返回1,放行即返回0
-
predict_hit_kwargs
(w_col=None, **kwargs)[源代码]¶ 辅助统计工具函数,对kwargs关键字参数所描述的交易特征进行ump分类簇命中统计,从子类对象必须实现的虚方法get_predict_col中获取特征列, 将kwargs中的特征值转换为x,套接self.hit_cnt进行分类簇命中统计
参数: - w_col – 自定义特征列,一般不会使用,正常情况从子类对象必须实现的虚方法get_predict_col中获取特征列
- kwargs –
需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818
返回: kwargs关键字参数所描述的交易特征进行分类簇命中统计,返回int值
-
predict_kwargs
(w_col=None, need_hit_cnt=1, **kwargs)[源代码]¶ 主裁交易决策函数,对kwargs关键字参数所描述的交易特征进行拦截决策,从子类对象必须实现的虚方法get_predict_col中获取特征列, 将kwargs中的特征值转换为x,套接self.predict进行核心裁决判定
参数: - w_col – 自定义特征列,一般不会使用,正常情况从子类对象必须实现的虚方法get_predict_col中获取特征列
- need_hit_cnt – 透传给self.predict中need_hit_cnt参数,做为分类簇匹配拦截阀值
- kwargs –
需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818
返回: 是否对kwargs关键字参数所描述的交易特征进行拦截,int,不拦截: 0,拦截: 1
-
show_parse_rt
(rt)[源代码]¶ 辅助工具函数,使用柱状图可视化分类簇中cluster,result的数据关系 :param rt: 在fit函数中保存在字典中的元素:
clf_component_dict[component] = (clf, cluster_ind)
- eg:rt,(GaussianMixtured对象,cluster_ind: GMM(component)分component个类中,
- 满足子分类的失败率大于阀值threshold的子分类序号)
-
classmethod
ump_main_clf_dump
(orders_pd_train, p_ncs=None, brust_min=True, market_name=None, show_component=False, show_info=False, save_order=False, show_order=False)[源代码]¶ 类方法,通过交易训练集orders_pd_train构造AbuUmpMainBase子类对象,透传brust_min,p_ncs等参数 使用fit方法对训练集进行分类簇筛选,使用dump_clf本地序列化训练结果 :param orders_pd_train: 交易训练集,pd.DataFrame对象 :param p_ncs: gmm分类的范围, 可以为具体序列对象如[10, 11, 12....80], 也可以为生成器对象,
如xrange(10, 80, 10),还支持slice对象,eg:slice(10, 80, 10)参数: - brust_min – bool类型,代表是否进行全局最优参数计算brust_min,如果否则直接使用默认g_brust_min_default(0, 0, 0.65) 如果不使用brust_min,即brust_min=False可大大提高训练运行效率
- market_name – 主裁训练或者获取裁判对应的存贮唯一名称,默认None, 根据env中的当前市场设置存储名称
- show_component – 是否可视化lcs,lrs,lps,lms数据(2d, 3d),即透传给fit函数的show参数
- show_info – 是否显示brust_min计算的最优lrs,lps,lms组合结果以及best_hit_cnt_info,choose_cprs_component 等辅助函数的辅助输出信息
- save_order – 是否保存失败概率最大的分类簇的交易快照图片到本地
- show_order – 是否绘制失败概率最大的分类簇的交易快照图片
返回: AbuUmpMainBase子类对象实例
-
-
abupy.UmpBu.ABuUmpMainBase.
K_DEFAULT_NCS_MAX
= 50000¶ 在brust_min中计算lps_step, lms_step, lrs_step中使用的默认step参数,默认50,详见brust_min函数实现
-
abupy.UmpBu.ABuUmpMainBase.
K_DEFAULT_NCS_RANG
= slice(40, 85, 1)¶ 主裁使用的gmm默认分类K_DEFAULT_NCS_RANG最大对应的分类数量,详阅读使用
-
abupy.UmpBu.ABuUmpMainBase.
g_brust_min_default
= (0, 0, 0.65)¶ 代表在ump_main_clf_dump中show_order或者save_order为True的情况下最多绘制和保存的交易快照数量
-
abupy.UmpBu.ABuUmpMainBase.
g_brust_min_step_cnt
= 50¶ 在不计算全局最优参数brust_min组合情况下的直接使用的默认参数摘取cprs形成llps
abupy.UmpBu.ABuUmpMainDeg module¶
示例ump主裁特征走势拟合角度模块
-
class
abupy.UmpBu.ABuUmpMainDeg.
AbuUmpMainDeg
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁走势拟合角度特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpDegFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: - self.order_has_ret中使用filter选取特征列形成deg_df
- ump_main_make_xy装饰器在make_xy返回deg_df后做转换matrix,形成x,y等工作
eg: deg_df
result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 2014-09-24 0 3.378 3.458 3.4582014-10-24 0 0.191 2.889 2.809 2014-10-29 1 -2.026 16.689 -0.761 2014-10-29 1 -3.427 -11.956 -8.296 2014-10-29 1 -2.915 39.469 -6.043 2014-10-29 1 -2.026 16.689 -0.761 2014-11-03 1 0.103 39.202 -4.614 2014-11-11 1 8.341 -9.450 0.730 2014-11-12 0 3.963 6.595 -7.524 2014-11-26 0 14.052 6.061 7.566 ... ... ... ... ... 2016-03-14 1 4.002 -10.559 -7.992 2016-03-14 0 0.129 -6.649 -10.880 2016-03-30 0 13.121 -8.461 4.498 2016-04-04 1 4.409 -33.097 -6.281 2016-04-13 0 6.603 -31.459 0.191 2016-04-14 0 4.611 18.428 3.134 2016-04-15 0 4.238 -13.247 4.693 2016-04-15 0 4.238 -13.247 4.693 2016-04-29 1 1.445 16.266 4.615 2016-04-29 1 1.445 16.266 4.615
buy_deg_ang212014-09-24 1.818 2014-10-24 -1.089 2014-10-29 1.980 2014-10-29 6.507 2014-10-29 7.046 2014-10-29 1.980 2014-11-03 10.125 2014-11-11 12.397 2014-11-12 6.671 2014-11-26 12.494 ... ... 2016-03-14 9.324 2016-03-14 5.201 2016-03-30 4.070 2016-04-04 5.618 2016-04-13 4.457 2016-04-14 0.733 2016-04-15 1.162 2016-04-15 1.162 2016-04-29 -1.115 2016-04-29 -1.115
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘deg_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.ABuUmpMainDeg.
AbuUmpMainDegExtend
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁使用新的视角来决策交易,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpExtendFeatureFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
-
class
abupy.UmpBu.ABuUmpMainFull module¶
示例ump多混特征模块
-
class
abupy.UmpBu.ABuUmpMainFull.
AbuUmpMainFull
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁多混特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpFullFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成full_df ump_main_make_xy装饰器在make_xy返回full_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘full_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
get_fiter_class
()[源代码]¶ 主裁多混特征返回的AbuMLPd子类:AbuUmpMainFull.UmpFullFiter :return: AbuUmpMainFull.UmpFullFiter
-
get_predict_col
()[源代码]¶ - 主裁多混特征keys:
- [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
返回: [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
-
class
abupy.UmpBu.ABuUmpMainJump module¶
示例ump主裁特征跳空模块
-
class
abupy.UmpBu.ABuUmpMainJump.
AbuUmpMainJump
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁跳空特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpJumpFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成jump_df ump_main_make_xy装饰器在make_xy返回jump_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘jump_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpMainMul module¶
示例ump单混特征模块
-
class
abupy.UmpBu.ABuUmpMainMul.
AbuUmpMainMul
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁单混特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpMulFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成mul_df ump_main_make_xy装饰器在make_xy返回mul_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘mul_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpMainPrice module¶
示例ump价格特征模块
-
class
abupy.UmpBu.ABuUmpMainPrice.
AbuUmpMainPrice
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁价格特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpPriceFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成price_df ump_main_make_xy装饰器在make_xy返回price_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘price_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpMainWave module¶
示例ump价格波动特征模块
-
class
abupy.UmpBu.ABuUmpMainWave.
AbuUmpMainWave
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁价格波动特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpWaveFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成wave_df ump_main_make_xy装饰器在make_xy返回wave_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘wave_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
abupy.UmpBu.ABuUmpManager module¶
买入卖出因子与ump进行组织管理通信模块
-
class
abupy.UmpBu.ABuUmpManager.
AbuUmpManager
(factor)[源代码]¶ Bases:
object
ump组织管理类
-
builtin_ump_block
(ml_feature_dict)[源代码]¶ 内置ump进行拦截决策,通过ABuEnv中的拦截设置以及因子的买入卖出类型是否和ump类型匹配, 来决定是否使用特定的ump进行拦截决策,如需要决策:
对交易进行拦截决策
param ml_feature_dict: 交易所形成的特征字典 - eg: ml_feature_dict
- {‘buy_deg_ang42’: -0.45400000000000001, ‘buy_deg_ang252’: 5.532, ‘buy_deg_ang60’: 2.1419999999999999, ‘buy_deg_ang21’: 0.93100000000000005, ‘buy_price_rank120’: 1.0, ‘buy_price_rank90’: 1.0, ‘buy_price_rank60’: 1.0, ‘buy_price_rank252’: 1.0, ‘buy_wave_score1’: 1.2470000000000001, ‘buy_wave_score2’: 1.286, ‘buy_wave_score3’: 1.2849999999999999, ‘buy_atr_std’: 0.19400000000000001, ‘buy_jump_down_power’: -13.57, ‘buy_diff_down_days’: 136, ‘buy_jump_up_power’: 1.038, ‘buy_diff_up_days’: 2}
返回: bool, 对ml_feature_dict所描述的交易特征是否进行拦截
-
extend_ump_block
(ml_feature_dict)[源代码]¶ 外部用户设置的ump进行拦截决策,迭代self.extend_ump_list中外部设置的ump, 由于对外添加ump的接口append_user_ump中参数ump可以是ump class类型, 也可以是实例化后的ump object,所以需要把class类型的ump进行实例构造,且将 实例的ump对象缓存在类变量中(通过class_unique_id为类变量构造唯一名称), ump对象构造好后根据主裁还是边裁选择决策方法:
对交易进行拦截决策
参数: ml_feature_dict – 交易所形成的特征字典 - eg: ml_feature_dict
- {‘buy_deg_ang42’: -0.45400000000000001, ‘buy_deg_ang252’: 5.532, ‘buy_deg_ang60’: 2.1419999999999999, ‘buy_deg_ang21’: 0.93100000000000005, ‘buy_price_rank120’: 1.0, ‘buy_price_rank90’: 1.0, ‘buy_price_rank60’: 1.0, ‘buy_price_rank252’: 1.0, ‘buy_wave_score1’: 1.2470000000000001, ‘buy_wave_score2’: 1.286, ‘buy_wave_score3’: 1.2849999999999999, ‘buy_atr_std’: 0.19400000000000001, ‘buy_jump_down_power’: -13.57, ‘buy_diff_down_days’: 136, ‘buy_jump_up_power’: 1.038, ‘buy_diff_up_days’: 2}
返回: bool, 对ml_feature_dict所描述的交易特征是否进行拦截
-
ump_block
(ml_feature_dict)[源代码]¶ 在买入或者卖出因子中make_ump_block_decision方法中使用,决策特定交易是否被拦截, ump_block中首先使用内置ump进行拦截决策,如果不被拦截,使用外部定义的ump进行拦截决策
参数: ml_feature_dict – 交易所形成的特征字典 eg: ml_feature_dict
{‘buy_deg_ang42’: -0.45400000000000001, ‘buy_deg_ang252’: 5.532, ‘buy_deg_ang60’: 2.1419999999999999, ‘buy_deg_ang21’: 0.93100000000000005, ‘buy_price_rank120’: 1.0, ‘buy_price_rank90’: 1.0, ‘buy_price_rank60’: 1.0, ‘buy_price_rank252’: 1.0, ‘buy_wave_score1’: 1.2470000000000001, ‘buy_wave_score2’: 1.286, ‘buy_wave_score3’: 1.2849999999999999, ‘buy_atr_std’: 0.19400000000000001, ‘buy_jump_down_power’: -13.57, ‘buy_diff_down_days’: 136, ‘buy_jump_up_power’: 1.038, ‘buy_diff_up_days’: 2}返回: bool, 对ml_feature_dict所描述的交易特征是否进行拦截
-
ump_edge_deg
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_edge_full
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_edge_price
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_edge_wave
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_main_deg
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_main_deg_hit_cnt
()[源代码]¶ - 角度主裁使用predict_kwargs的参数need_hit_cnt值,即:
- predict_kwargs(need_hit_cnt=self.ump_main_deg_hit_cnt(), **ml_feature_dict)
被装饰器first_delegate_has_method(delegate=’factor’)装饰,当被委托的因子,即self.factor中 有对应实现的ump_main_deg_hit_cnt方法时,返回self.factor.ump_main_deg_hit_cnt()的返回值 :return: int
-
ump_main_jump
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_main_jump_hit_cnt
()[源代码]¶ - 跳空主裁使用predict_kwargs的参数need_hit_cnt值,即:
- predict_kwargs(need_hit_cnt=self.ump_main_jump_hit_cnt, **ml_feature_dict)
被装饰器first_delegate_has_method(delegate=’factor’)装饰,当被委托的因子,即self.factor中 有对应实现的ump_main_jump_hit_cnt方法时,返回self.factor.ump_main_jump_hit_cnt()的返回值 :return: int
-
ump_main_price
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_main_price_hit_cnt
()[源代码]¶ - 价格主裁使用predict_kwargs的参数need_hit_cnt值,即:
- predict_kwargs(need_hit_cnt=self.ump_main_price_hit_cnt, **ml_feature_dict)
被装饰器first_delegate_has_method(delegate=’factor’)装饰,当被委托的因子,即self.factor中 有对应实现的ump_main_price_hit_cnt方法时,返回self.factor.ump_main_price_hit_cnt()的返回值 :return: int
-
ump_main_user_hit_cnt
()[源代码]¶ 用户自定义的主裁ump类的使用predict_kwargs的参数need_hit_cnt值, 用户在因子中可通过实现特点的方法名称来替换ump_main_user_hit_cnt值,
使用时使用replace_word_delegate_has_method检测self.factor中有没有对应的方法, eg:
- replace_hit_cnt = replace_word_delegate_has_method(delegate=’factor’, key_word=’user’,
- replace_word=class_unique_id)
hit_cnt = replace_hit_cnt(self.ump_main_user_hit_cnt)()
- 即如果用户编写的主裁ump中class_unique_id方法返回’extend_main_test’
@classmethod def class_unique_id(cls):
return ‘extend_main_test’- 则在因子中对应自定义hit_cnt的方法名称应为:
- def ump_main_extend_main_test_hit_cnt(self)
- return 1
更多具体实现阅extend_ump_block以及replace_word_delegate_has_method方法的实现
返回: int
-
ump_main_wave
¶ 描述器类:作用在类中需要lazy的对象方法上
-
ump_main_wave_hit_cnt
()[源代码]¶ - 价格波动主裁使用predict_kwargs的参数need_hit_cnt值,即:
- predict_kwargs(need_hit_cnt=self.ump_main_wave_hit_cnt, **ml_feature_dict)
被装饰器first_delegate_has_method(delegate=’factor’)装饰,当被委托的因子,即self.factor中 有对应实现的ump_main_wave_hit_cnt方法时,返回self.factor.ump_main_wave_hit_cnt()的返回值 :return: int
-
Module contents¶
-
class
abupy.UmpBu.
CachedUmpManager
[源代码]¶ Bases:
object
ump拦截缓存实体,分别在主裁和边裁类中
-
get_ump
(ump)[源代码]¶ 主要在具体裁判类的predict方法中获取裁判本体使用,如果 不在_cache中load_pickle,否则使用catch中的ump返回 :param ump: 具体裁判对象,AbuUmpBase对象 :return: 每个裁判需要的决策数据,每类裁判主体的数据形式不同,且使用方法不同
- eg:主裁中的使用
- def predict(self, x, need_hit_cnt=1):
dump_clf_with_ind = AbuUmpMainBase.dump_clf_manager.get_ump(self) count_hit = 0 for clf, ind in dump_clf_with_ind.values():
ss = clf.predict(x) if ss == ind:
count_hit += 1 if need_hit_cnt == count_hit:
return 1return 0
-
s_use_weak
= False¶
-
-
class
abupy.UmpBu.
AbuUmpBase
[源代码]¶ Bases:
abc.NewBase
ump拦截缓存,在AbuUmpBase类中
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf_manager
= <abupy.UmpBu.ABuUmpBase.CachedUmpManager object>¶
-
classmethod
-
class
abupy.UmpBu.
BuyUmpMixin
[源代码]¶ Bases:
object
买入ump混入, 与BuyFeatureMixin不同,每一个具体的ump只能属于一个ump类别 即不是BuyUmpMixin就应该是SellUmpMixin
-
class
abupy.UmpBu.
SellUmpMixin
[源代码]¶ Bases:
object
卖出ump混入, 与SellFeatureMixin不同,每一个具体的ump只能属于一个ump类别 即不是BuyUmpMixin就应该是SellUmpMixin
-
class
abupy.UmpBu.
AbuUmpEdgeBase
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpBase.AbuUmpBase
边裁基类
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf
()[源代码]¶ 边裁的本地序列化相对主裁的dump_clf也简单很多, 将self.fiter.df和self.fiter.x打包成一个字典对象df_x_dict 通过ABuFileUtil.dump_pickle进行保存
-
dump_file_fn
()[源代码]¶ 边裁本地缓存的存储路径规则: ABuEnv.g_project_data_dir + ‘ump/ump_edge_‘ + market_name + self.class_unique_id()
-
fit
()[源代码]¶ 边裁训练集拟合存储函数,相对主裁的训练fit函数,边裁的fit很简单 self.fiter.df经过fit后添加了新列p_rk_cg和rk形式如下所示
- eg:self.fiter.df
- profit profit_cg buy_deg_ang42 buy_deg_ang252 2014-09-24 -22618.04 -0.0566 3.378 3.458
2014-10-24 -29690.28 -0.0742 0.191 2.889 2014-10-29 18959.19 0.0542 -2.026 16.689 2014-10-29 148209.36 0.5022 -3.427 -11.956 2014-10-29 24867.60 0.0952 -2.915 39.469 2014-10-29 18959.19 0.0542 -2.026 16.689 2014-11-03 1250.80 0.0045 0.103 39.202 2014-11-11 59888.21 0.1857 8.341 -9.450 2014-11-12 -3578.78 -0.0140 3.963 6.595 2014-11-26 -29085.19 -0.0946 14.052 6.061 ... ... ... ... ... 2016-03-14 16220.57 0.0559 4.002 -10.559 2016-03-14 -25328.12 -0.1218 0.129 -6.649 2016-03-30 -29858.44 -0.0863 13.121 -8.461 2016-04-04 5373.76 0.0244 4.409 -33.097 2016-04-13 -28044.40 -0.1159 6.603 -31.459 2016-04-14 -18645.93 -0.0467 4.611 18.428 2016-04-15 -32484.79 -0.1149 4.238 -13.247 2016-04-15 -32484.79 -0.1149 4.238 -13.247 2016-04-29 290.96 0.0007 1.445 16.266 2016-04-29 290.96 0.0007 1.445 16.266
buy_deg_ang60 buy_deg_ang21 p_rk_cg rk2014-09-24 3.458 1.818 19.0 0 2014-10-24 2.809 -1.089 13.0 -1 2014-10-29 -0.761 1.980 35.5 0 2014-10-29 -8.296 6.507 56.0 1 2014-10-29 -6.043 7.046 43.0 1 2014-10-29 -0.761 1.980 35.5 0 2014-11-03 -4.614 10.125 28.0 0 2014-11-11 0.730 12.397 48.0 1 2014-11-12 -7.524 6.671 23.0 0 2014-11-26 7.566 12.494 9.0 -1 ... ... ... ... .. 2016-03-14 -7.992 9.324 37.0 0 2016-03-14 -10.880 5.201 2.0 -1 2016-03-30 4.498 4.070 12.0 -1 2016-04-04 -6.281 5.618 33.0 0 2016-04-13 0.191 4.457 4.0 -1 2016-04-14 3.134 0.733 20.0 0 2016-04-15 4.693 1.162 5.5 -1 2016-04-15 4.693 1.162 5.5 -1 2016-04-29 4.615 -1.115 24.5 0 2016-04-29 4.615 -1.115 24.5 0
边裁裁决方式多次使用非均衡技术对最后的结果概率进行干预,目的是使最终的裁决正确率达成非均衡的目标, 非均衡技术思想是量化中很很重要的一种设计思路,因为我们量化的目标结果就是非均衡(我们想要赢的钱比输的多)
-
predict
(**kwargs)[源代码]¶ 边裁交易决策函数,从CachedUmpManager中获取缓存df_x_dict,对kwargs关键字参数所描述的交易特征进行拦截决策 边裁的predict()实现相对主裁来说比较复杂,大致思路如下:
- 从输入的新交易中挑选需要的特征组成x
- 将x和之前保存的训练集数据组合concatenate(),一起做数据标准化scaler
- 使用sklearn.metrics.pairwise.pairwise_distances()度量输入特征和训练集矩阵中的距离序列
- 取pairwise_distances() TOP个作为种子,继续匹配相似度
- 相似度由大到小排序,保留大于保留阀值的相似度交易数据做为最终有投票权利的
- 保留的交易认为是与新交易最相似的交易,保留的交易使用之前非均衡的rk对新交易进行投票
- 最后的判断需要大于一定比例才被结果认可,即再次启动非均衡
参数: kwargs – 需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818返回: 是否对kwargs关键字参数所描述的交易特征进行拦截, EEdgeType: 不拦截: EEdgeType.E_EEdge_NORMAL or EEdgeType.E_STORE_TOP_WIN 拦截: EEdgeType.E_EEdge_TOP_LOSS
-
classmethod
ump_edge_clf_dump
(orders_pd_train, show_info=False, market_name=None)[源代码]¶ 类方法,通过交易训练集orders_pd_train构造AbuUmpEdgeBase子类对象, 使用fit方法对训练集进行特征采集,后进行dump_clf即 本地序列化存贮等工作 :param orders_pd_train: 交易训练集,pd.DataFrame对象 :param show_info: 是否显示edge.fiter.df.head(),默认False :param market_name: 主裁训练或者获取裁判对应的存贮唯一名称,默认None, 根据env中的当前市场设置存储名称 :return: AbuUmpEdgeBase子类对象实例
-
classmethod
-
class
abupy.UmpBu.
AbuUmpEdgeDeg
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁走势拟合角度特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpDegFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成deg_df ump_edge_make_xy装饰器在make_xy返回deg_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘deg_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpEegeDegExtend
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁使用新的视角来决策交易,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpExtendEdgeFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
-
class
-
class
abupy.UmpBu.
AbuUmpEdgeFull
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁多混特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpFullFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成full_df ump_edge_make_xy装饰器在make_xy返回full_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘full_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
get_fiter_class
()[源代码]¶ 边裁多混特征返回的AbuMLPd子类:AbuUmpEdgeFull.UmpFullFiter :return: AbuUmpEdgeFull.UmpFullFiter
-
get_predict_col
()[源代码]¶ - 边裁多混特征keys:
- [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
返回: [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
-
class
-
class
abupy.UmpBu.
AbuUmpEdgeMul
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁单混特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpMulFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成mul_df ump_edge_make_xy装饰器在make_xy返回mul_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘mul_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpEdgePrice
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁价格特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpPriceFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成price_df ump_edge_make_xy装饰器在make_xy返回price_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘price_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpEdgeWave
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpEdgeBase.AbuUmpEdgeBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
边裁价格波动特征类,AbuUmpEdgeBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpWaveFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_edge_make_xy装饰
- 在边裁__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ - make_xy通过装饰器ump_edge_make_xy进行包装,调用make_xy前将有交易结果的单子进行筛选: order_has_ret = orders_pd[orders_pd[‘result’] != 0],且赋予self.order_has_ret make_xy只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df
参数: kwarg – ump_edge_make_xy装饰器中使用kwarg kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 返回: self.order_has_ret中使用filter选取特征列形成wave_df ump_edge_make_xy装饰器在make_xy返回wave_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘wave_edge’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpMainBase
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpBase.AbuUmpBase
主裁基类
-
best_hit_cnt_info
(llps=None)[源代码]¶ 辅助工具函数,通过统计在各个分类簇中重复出现的交易单子,计算出 平均值
参数: llps – llps对象,默认参数llps=None将使用llps = self.llps
- eg: llps形式如
- lcs lms lps lrs
15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
brust_min
()[源代码]¶ 在fit操作之后对self.cprs进行分析可以发现,这些分类中存在很多分类簇中的交易胜率不高, 但是交易获利比例总和却为正值,也就是说这个分类簇由于非均衡赔率使得非均衡胜率得以保持平衡, 并且最终获利,那么我们将所有分类簇保存在本地,对之后的交易进行裁决显然是不妥当的,所以需要使用 全局最优技术对分类簇集合进行筛选
- 将lps的范围选定(分类簇中交易获利比例总和最小值-0), 即醋中交易获胜比例组合大于0的过滤
- 将lms的范围选定(分类簇中交易获利比例平均值最小值-0), 即醋中交易获利比例平均值大于0的过滤
- 将lrs交易醋失败率从最小值-最大值
- 计算最小值-0(最大值)之间合适的step值
- bnds = (slice(lps_min, 0, lps_step), slice(lms_min, 0, lms_step), slice(lrs_min, lrs_max, lrs_step))
6. sco.brute中设定最优函数self.min_func_improved使用bnds进行计算 更多详见brust_min实现函数
-
choose_cprs_component
(llps=None)[源代码]¶ 辅助工具函数,输出显示在llps下训练集交易中的生效数量,和训练集可提升数据比例 以及可视化所有训练集中被拦截的交易profit_cg的cumsum
参数: llps – llps对象,默认参数llps=None将使用llps = self.llps
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法,abstractmethod子类必须实现 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
dump_clf
(llps=None)[源代码]¶ - 通过llps.index,从self.rts中获取GaussianMixture对象,即self.rts[clf][0]
eg: llps.index Index([‘14_7’, ‘14_8’, ‘14_9’, ‘14_10’, ‘15_7’, ‘15_8’, ‘15_9’, ‘15_10’,
- ‘16_7’, ‘16_8’, ‘16_9’, ‘16_10’, ‘17_7’, ‘17_8’, ‘17_9’, ‘17_10’,
‘27_14’, ‘27_15’, ‘27_17’, ‘27_18’, ‘27_24’], dtype=’object’)
2. 将cluster和GaussianMixture对象做为value,llps.index中的元素做为key形成最终序列化的dict对象形式如下所示 eg:
{ ‘14_7’: (GaussianMixture(covariance_type=’full’, init_params=’kmeans’, max_iter=100,
means_init=None, n_components=14, n_init=1, precisions_init=None, random_state=3, reg_covar=1e-06, tol=0.001, verbose=0, verbose_interval=10, warm_start=False, weights_init=None), 7),- ‘14_8’: (GaussianMixture(covariance_type=’full’, init_params=’kmeans’, max_iter=100,
- means_init=None, n_components=14, n_init=1, precisions_init=None, random_state=3, reg_covar=1e-06, tol=0.001, verbose=0, verbose_interval=10, warm_start=False, weights_init=None), 8)
}
3. 通过ABuFileUtil.dump_pickle最终将元素序列化保存在本地 :param llps: 需要最终保存的llps对象,默认参数llps=None将使用llps = self.llps
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
-
dump_file_fn
()[源代码]¶ 主裁本地缓存的存储路径规则: ABuEnv.g_project_data_dir + ‘ump/ump_main_‘ + market_name + self.class_unique_id()
-
fit
(p_ncs=None, threshold=0.65, brust_min=True, show=True)[源代码]¶ 交易训练集训练拟合函数,根据规则计算gmm分类的范围,使用gmm对训练集交易进行阀值筛选, 根据brust_min参数决定是否进行全局最优参数计算,最终生成self.rts,self.nts,self.cprs
- eg:self.rts字典形式如下:
key=component, value=(GaussianMixtured对象,cluster_ind: GMM(component)分component个类中, 满足子分类的失败率大于阀值threshold的子分类序号)
- {14: (GaussianMixture(max_iter=100, n_components=14, n_init=1),
- Int64Index([7, 8, 9, 10], dtype=’int64’, name=’cluster’)),
- 15: (GaussianMixture(max_iter=100, n_components=15, n_init=1),
- Int64Index([7, 8, 9, 10], dtype=’int64’, name=’cluster’))}
- eg: self.nts字典对象形式如下所示:
{ ‘14-7’:
result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang21 ind cluster2014-11-11 1 8.341 -9.450 0.730 12.397 7 7 2015-10-28 0 7.144 -9.818 -3.886 6.955 39 7 2015-11-04 0 12.442 -10.353 3.313 7.840 41 7 2016-03-30 0 13.121 -8.461 4.498 4.070 49 7 2016-04-15 0 4.238 -13.247 4.693 1.162 53 7 2016-04-15 0 4.238 -13.247 4.693 1.162 54 7 ...............................................................................................
- ‘14-8’:
- result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 buy_deg_ang21 ind cluster
2014-11-26 0 14.052 6.061 7.566 12.494 9 8 2015-04-22 1 20.640 2.751 20.436 18.781 23 8 2015-12-16 0 12.906 6.312 16.638 12.379 43 8
}
- eg: self.cprs pd.DataFrame对象形式如下
- lcs lms lps lrs
14_7 6 -0.0552 -0.3310 0.8333 14_8 3 -0.0622 -0.1866 0.6667 14_9 1 -0.1128 -0.1128 1.0000 14_10 2 -0.0327 -0.0654 1.0000 15_7 4 -0.1116 -0.4465 1.0000 15_8 3 -0.0622 -0.1866 0.6667 ... ... ... ... ... 27_8 1 -0.1128 -0.1128 1.0000 27_9 3 -0.0103 -0.0309 0.6667 27_14 1 -0.0946 -0.0946 1.0000 27_15 2 -0.1149 -0.2299 1.0000 27_17 1 -0.1041 -0.1041 1.0000 27_18 2 -0.0327 -0.0654 1.0000 27_24 1 -0.0140 -0.0140 1.0000
参数: - p_ncs – gmm分类的范围, 可以为具体序列对象如[10, 11, 12....80], 也可以为生成器对象, 如xrange(10, 80, 10),还支持slice对象,eg:slice(10, 80, 10)
- threshold – 分类簇中失败率选择的阀值(默认0.65),即大于threshold值的gmm分类簇做为主裁学习目标分类簇
- brust_min – bool类型,代表是否进行全局最优参数计算brust_min,如果否则直接使用默认g_brust_min_default(0, 0, 0.65) 如果不使用brust_min,即brust_min=False可大大提高训练运行效率
- show – 是否可视化lcs,lrs,lps,lms数据(2d, 3d)
-
hit_cnt
(x)[源代码]¶ 辅助统计工具函数,从CachedUmpManager中获取缓存clf_cluster_dict,迭代ump字典对象, 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict 结果和 (clf, cluster)中存储的cluster一致的情况下代表hit
参数: x – 交易特征形成的x eg: array([[ 8.341, -9.45 , 0.73 , 12.397]]) 返回: kwargs关键字参数所描述的交易特征进行分类簇命中统计,返回int值
-
min_func
(l_pmr)[源代码]¶ - 使用lps,lms,lrs的特点组合值获取crps的子pd.DataFrame对象:
- llps = self.cprs[(self.cprs[‘lps’] <= l_pmr[0]) & (self.cprs[‘lms’] <= l_pmr[1]) &
- (self.cprs[‘lrs’] >= l_pmr[2])]
eg: llps形式如
lcs lms lps lrs15_9 4 -0.1116 -0.4465 0.65 16_7 12 -0.1786 -0.8122 0.72 ................................
- 通过llps从self.nts字典中获取原始训练集特征数据:
- result deg_ang21 deg_ang42 deg_ang60 deg_ang252 ind cluster
2011-09-21 0 8.645 -3.294 -8.426 -8.758 40 48 -0.083791 2011-09-30 0 11.123 -1.887 -2.775 1.585 158 49 -0.066309
- 计算llps组合的情况下拦截的单子的数量,以及胜率,失败率,通过:
improved = (effect_num / self.fiter.order_has_ret.shape[0]) * (loss_rate - win_rate)
eg:(effect_num / self.fiter.order_has_ret.shape[0]) * (loss_rate - win_rate) effect_num = 10, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.8, win_rate =0.2 -> (10 / 100) * (0.8 - 0.2) = 0.06
effect_num = 50, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.8, win_rate =0.2 -> (50 / 100) * (0.8 - 0.2) = 0.3
effect_num = 50, self.fiter.order_has_ret.shape[0] = 100 loss_rate = 0.9, win_rate =0.1 -> (50 / 100) * (0.9 - 0.1) = 0.4
即最终提升的比例和llps下被拦截的交易数量成正比,和llps下被拦截的交易失败率成正比
即计算llps组合的情况下,即参数l_pmr给定的lps,lms,lrs的特点组合下的交易提升值 :param l_pmr: 可迭代序列,eg:(-0.45, -0.11, 0.77), 由三个float值组成的序列
l_pmr[0]: 切取self.cprs使用的分类簇交易获利和值,即lps阀值:self.cprs[‘lps’] <= l_pmr[0] l_pmr[1]: 切取self.cprs使用的分类簇交易获利平均值,即lms阀值:self.cprs[‘lms’] <= l_pmr[1] l_pmr[2]: 切取self.cprs使用的分类簇交易失败比例,即lrs阀值:self.cprs[‘lrs’] >= l_pmr[2]返回: [improved, effect_num]
-
min_func_improved
(l_pmr)[源代码]¶ 包装min_func具体现实函数,在brust_min函数中使用: sco.brute(self.min_func_improved, bnds, full_output=False, finish=None) 计算最优参数组合,因为在self.min_func中计算的是提高improved值,要想得到最大 提高参数组合,即self.min_func返回值最大的组合,使用最优sco.brute的目标是 最小值,所以使用 -self.min_func(l_pmr)[0],找到最小值,结果的参数组合即为 最大提高improved值的参数组合 :param l_pmr: 可迭代序列,eg:(-0.45, -0.11, 0.77), 由三个float值组成的序列
l_pmr[0]: 切取self.cprs使用的分类簇交易获利和值,即lps阀值:self.cprs[‘lps’] <= l_pmr[0] l_pmr[1]: 切取self.cprs使用的分类簇交易获利平均值,即lms阀值:self.cprs[‘lms’] <= l_pmr[1] l_pmr[2]: 切取self.cprs使用的分类簇交易失败比例,即lrs阀值:self.cprs[‘lrs’] >= l_pmr[2]返回: -self.min_func(l_pmr)[0],即[improved, effect_num][0], 即improved值,float
-
predict
(x, need_hit_cnt=1)[源代码]¶ 主交易决策函数,从CachedUmpManager中获取缓存clf_cluster_dict,迭代ump字典对象, 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict 结果和 (clf, cluster)中存储的cluster一致的情况下代表hit,最终对交易 做出决策
参数: - x – 交易特征形成的x eg: array([[ 8.341, -9.45 , 0.73 , 12.397]])
- need_hit_cnt – 对交易特征形成的x使用字典中元素(clf, cluster)中的clf进行predict结果和 (clf, cluster)中存储的cluster一致的情况下代表hit一次:count_hit += 1 只有当need_hit_cnt == count_hit才最终做出决策对交易进行拦截
返回: 最终做出决策对交易是否进行拦截,拦截即返回1,放行即返回0
-
predict_hit_kwargs
(w_col=None, **kwargs)[源代码]¶ 辅助统计工具函数,对kwargs关键字参数所描述的交易特征进行ump分类簇命中统计,从子类对象必须实现的虚方法get_predict_col中获取特征列, 将kwargs中的特征值转换为x,套接self.hit_cnt进行分类簇命中统计
参数: - w_col – 自定义特征列,一般不会使用,正常情况从子类对象必须实现的虚方法get_predict_col中获取特征列
- kwargs –
需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818
返回: kwargs关键字参数所描述的交易特征进行分类簇命中统计,返回int值
-
predict_kwargs
(w_col=None, need_hit_cnt=1, **kwargs)[源代码]¶ 主裁交易决策函数,对kwargs关键字参数所描述的交易特征进行拦截决策,从子类对象必须实现的虚方法get_predict_col中获取特征列, 将kwargs中的特征值转换为x,套接self.predict进行核心裁决判定
参数: - w_col – 自定义特征列,一般不会使用,正常情况从子类对象必须实现的虚方法get_predict_col中获取特征列
- need_hit_cnt – 透传给self.predict中need_hit_cnt参数,做为分类簇匹配拦截阀值
- kwargs –
需要和子类对象实现的虚方法get_predict_col中获取特征列对应的 关键字参数,eg: buy_deg_ang42=3.378, buy_deg_ang60=3.458
buy_deg_ang21=3.191, buy_deg_ang252=1.818
返回: 是否对kwargs关键字参数所描述的交易特征进行拦截,int,不拦截: 0,拦截: 1
-
show_parse_rt
(rt)[源代码]¶ 辅助工具函数,使用柱状图可视化分类簇中cluster,result的数据关系 :param rt: 在fit函数中保存在字典中的元素:
clf_component_dict[component] = (clf, cluster_ind)
- eg:rt,(GaussianMixtured对象,cluster_ind: GMM(component)分component个类中,
- 满足子分类的失败率大于阀值threshold的子分类序号)
-
classmethod
ump_main_clf_dump
(orders_pd_train, p_ncs=None, brust_min=True, market_name=None, show_component=False, show_info=False, save_order=False, show_order=False)[源代码]¶ 类方法,通过交易训练集orders_pd_train构造AbuUmpMainBase子类对象,透传brust_min,p_ncs等参数 使用fit方法对训练集进行分类簇筛选,使用dump_clf本地序列化训练结果 :param orders_pd_train: 交易训练集,pd.DataFrame对象 :param p_ncs: gmm分类的范围, 可以为具体序列对象如[10, 11, 12....80], 也可以为生成器对象,
如xrange(10, 80, 10),还支持slice对象,eg:slice(10, 80, 10)参数: - brust_min – bool类型,代表是否进行全局最优参数计算brust_min,如果否则直接使用默认g_brust_min_default(0, 0, 0.65) 如果不使用brust_min,即brust_min=False可大大提高训练运行效率
- market_name – 主裁训练或者获取裁判对应的存贮唯一名称,默认None, 根据env中的当前市场设置存储名称
- show_component – 是否可视化lcs,lrs,lps,lms数据(2d, 3d),即透传给fit函数的show参数
- show_info – 是否显示brust_min计算的最优lrs,lps,lms组合结果以及best_hit_cnt_info,choose_cprs_component 等辅助函数的辅助输出信息
- save_order – 是否保存失败概率最大的分类簇的交易快照图片到本地
- show_order – 是否绘制失败概率最大的分类簇的交易快照图片
返回: AbuUmpMainBase子类对象实例
-
-
class
abupy.UmpBu.
AbuUmpMainDeg
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁走势拟合角度特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpDegFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: - self.order_has_ret中使用filter选取特征列形成deg_df
- ump_main_make_xy装饰器在make_xy返回deg_df后做转换matrix,形成x,y等工作
eg: deg_df
result buy_deg_ang42 buy_deg_ang252 buy_deg_ang60 2014-09-24 0 3.378 3.458 3.4582014-10-24 0 0.191 2.889 2.809 2014-10-29 1 -2.026 16.689 -0.761 2014-10-29 1 -3.427 -11.956 -8.296 2014-10-29 1 -2.915 39.469 -6.043 2014-10-29 1 -2.026 16.689 -0.761 2014-11-03 1 0.103 39.202 -4.614 2014-11-11 1 8.341 -9.450 0.730 2014-11-12 0 3.963 6.595 -7.524 2014-11-26 0 14.052 6.061 7.566 ... ... ... ... ... 2016-03-14 1 4.002 -10.559 -7.992 2016-03-14 0 0.129 -6.649 -10.880 2016-03-30 0 13.121 -8.461 4.498 2016-04-04 1 4.409 -33.097 -6.281 2016-04-13 0 6.603 -31.459 0.191 2016-04-14 0 4.611 18.428 3.134 2016-04-15 0 4.238 -13.247 4.693 2016-04-15 0 4.238 -13.247 4.693 2016-04-29 1 1.445 16.266 4.615 2016-04-29 1 1.445 16.266 4.615
buy_deg_ang212014-09-24 1.818 2014-10-24 -1.089 2014-10-29 1.980 2014-10-29 6.507 2014-10-29 7.046 2014-10-29 1.980 2014-11-03 10.125 2014-11-11 12.397 2014-11-12 6.671 2014-11-26 12.494 ... ... 2016-03-14 9.324 2016-03-14 5.201 2016-03-30 4.070 2016-04-04 5.618 2016-04-13 4.457 2016-04-14 0.733 2016-04-15 1.162 2016-04-15 1.162 2016-04-29 -1.115 2016-04-29 -1.115
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘deg_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpMainDegExtend
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁使用新的视角来决策交易,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpExtendFeatureFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
-
class
-
class
abupy.UmpBu.
AbuUmpMainFull
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁多混特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpFullFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成full_df ump_main_make_xy装饰器在make_xy返回full_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘full_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
get_fiter_class
()[源代码]¶ 主裁多混特征返回的AbuMLPd子类:AbuUmpMainFull.UmpFullFiter :return: AbuUmpMainFull.UmpFullFiter
-
get_predict_col
()[源代码]¶ - 主裁多混特征keys:
- [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
返回: [‘buy_deg_ang42’, ‘buy_deg_ang252’, ‘buy_deg_ang60’, ‘buy_deg_ang21’, ‘buy_price_rank120’, ‘buy_price_rank90’, ‘buy_price_rank60’, ‘buy_price_rank252’, ‘buy_wave_score1’, ‘buy_wave_score2’, ‘buy_wave_score3’, ‘buy_atr_std’, ‘buy_diff_down_days’, ‘buy_jump_up_power’, ‘buy_diff_up_days’, ‘buy_jump_down_power’]
-
class
-
class
abupy.UmpBu.
AbuUmpMainJump
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁跳空特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpJumpFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成jump_df ump_main_make_xy装饰器在make_xy返回jump_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘jump_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpMainMul
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁单混特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpMulFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成mul_df ump_main_make_xy装饰器在make_xy返回mul_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘mul_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpMainPrice
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁价格特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpPriceFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成price_df ump_main_make_xy装饰器在make_xy返回price_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘price_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class
-
class
abupy.UmpBu.
AbuUmpMainWave
(orders_pd=None, predict=False, market_name=None, **kwarg)[源代码]¶ Bases:
abupy.UmpBu.ABuUmpMainBase.AbuUmpMainBase
,abupy.UmpBu.ABuUmpBase.BuyUmpMixin
主裁价格波动特征类,AbuUmpMainBase子类,混入BuyUmpMixin,做为买入ump类
-
class
UmpWaveFiter
(**kwarg)[源代码]¶ Bases:
abupy.MLBu.ABuMLPd.AbuMLPd
内部类,只需要实现make_xy,且使用ump_main_make_xy装饰
- 在__init__中通过:
- self.fiter_cls = self.get_fiter_class() self.fiter = self.fiter_cls(orders_pd=self.orders_pd, **kwarg)
构造裁判的filter以及重要的self.fiter.df,即pd.DataFrame对象特征
-
make_xy
(**kwarg)[源代码]¶ make_xy通过装饰器ump_main_make_xy进行二次包装 这里只需要使用filter选取需要的特征,即从self.order_has_ret中使用filter选取特征列形成df :param kwarg: ump_main_make_xy装饰器中使用kwarg
kwargs[‘orders_pd’] 做为必须要有的关键字参数:交易训练集数据,pd.DataFrame对象 kwargs[‘scaler’] 做为可选关键字参数:控制在make_xy中返回的特征矩阵数据是否进行标准化处理返回: self.order_has_ret中使用filter选取特征列形成wave_df ump_main_make_xy装饰器在make_xy返回wave_df后做转换matrix,形成x,y等工作
-
classmethod
class_unique_id
()[源代码]¶ 具体ump类关键字唯一名称,类方法:return ‘wave_main’ 主要针对外部user设置自定义ump使用, 需要user自己保证class_unique_id的唯一性,内部不做检测 具体使用见ABuUmpManager中extend_ump_block方法
-
class