Hikyuu
AllocateFundsBase.h
浏览该文件的文档.
1 /*
2  * AllocateMoney.h
3  *
4  * Created on: 2018年1月30日
5  * Author: fasiondog
6  */
7 
8 #ifndef TRADE_SYS_ALLOCATEFUNDS_ALLOCATEFUNDSBASE_H_
9 #define TRADE_SYS_ALLOCATEFUNDS_ALLOCATEFUNDSBASE_H_
10 
11 #include "../../utilities/Parameter.h"
12 #include "../allocatefunds/SystemWeight.h"
13 
14 #if HKU_SUPPORT_SERIALIZATION
15 #include <boost/serialization/shared_ptr.hpp>
16 #include <boost/serialization/assume_abstract.hpp>
17 #include <boost/serialization/base_object.hpp>
18 #endif
19 
20 namespace hku {
21 
22 class HKU_API AllocateFundsBase: public enable_shared_from_this<AllocateFundsBase> {
24 
25 public:
27  AllocateFundsBase(const string& name);
28  virtual ~AllocateFundsBase();
29 
30  string name() const;
31  void name(const string& name);
32 
40  SystemList getAllocatedSystemList(const Datetime& date,
41  const SystemList& se_list,
42  const SystemList& hold_list);
43 
45  TMPtr getTM();
46 
48  void setTM(const TMPtr&);
49 
50  KQuery getQuery();
51  void setQuery(KQuery query);
52 
54  double getReservePercent();
55 
60  void setReserverPercent(double p);
61 
62  bool changed(Datetime date);
63 
65  void reset();
66 
67  typedef shared_ptr<AllocateFundsBase> AFPtr;
69  AFPtr clone();
70 
72  virtual void _reset() {}
73 
75  virtual AFPtr _clone() = 0;
76 
87  virtual SystemWeightList _allocateWeight(const Datetime& date,
88  const SystemList& se_list) = 0;
89 
90  void _getAllocatedSystemList_adjust_hold(
91  const Datetime& date,
92  const SystemList& se_list,
93  const SystemList& hold_list,
94  SystemList& out_sys_list);
95  void _getAllocatedSystemList_not_adjust_hold(
96  const Datetime& date,
97  const SystemList& se_list,
98  const SystemList& hold_list,
99  SystemList& out_sys_list);
100 
101 private:
102  string m_name;
103  KQuery m_query;
104  int m_count;
105  Datetime m_pre_date;
106  TMPtr m_tm;
107 
108  double m_reserve_percent; //保留资产比例,不参与资产分配
109 
110  list<SystemWeight> m_wait_for_allocate_list;
111 
112  //============================================
113  // 序列化支持
114  //============================================
115  #if HKU_SUPPORT_SERIALIZATION
116  private:
117  friend class boost::serialization::access;
118  template<class Archive>
119  void save(Archive & ar, const unsigned int version) const {
120  string name_str(GBToUTF8(m_name));
121  ar & boost::serialization::make_nvp("name", name_str);
122  ar & BOOST_SERIALIZATION_NVP(m_params);
123  ar & BOOST_SERIALIZATION_NVP(m_query);
124  ar & BOOST_SERIALIZATION_NVP(m_count);
125  ar & BOOST_SERIALIZATION_NVP(m_pre_date);
126  ar & BOOST_SERIALIZATION_NVP(m_reserve_percent);
127  ar & BOOST_SERIALIZATION_NVP(m_tm);
128  }
129 
130  template<class Archive>
131  void load(Archive & ar, const unsigned int version) {
132  ar & boost::serialization::make_nvp("name", m_name);
133  ar & BOOST_SERIALIZATION_NVP(m_params);
134  ar & BOOST_SERIALIZATION_NVP(m_query);
135  ar & BOOST_SERIALIZATION_NVP(m_count);
136  ar & BOOST_SERIALIZATION_NVP(m_pre_date);
137  ar & BOOST_SERIALIZATION_NVP(m_reserve_percent);
138  ar & BOOST_SERIALIZATION_NVP(m_tm);
139  }
140 
141  BOOST_SERIALIZATION_SPLIT_MEMBER()
142  #endif /* HKU_SUPPORT_SERIALIZATION */
143 };
144 
145 #if HKU_SUPPORT_SERIALIZATION
146 BOOST_SERIALIZATION_ASSUME_ABSTRACT(SelectorBase)
147 #endif
148 
149 #if HKU_SUPPORT_SERIALIZATION
150 
163 #define ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION private:\
164  friend class boost::serialization::access; \
165  template<class Archive> \
166  void serialize(Archive & ar, const unsigned int version) { \
167  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(AllocateFundsBase); \
168  }
169 #else
170 #define ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION
171 #endif
172 
173 #define ALLOCATEFUNDS_IMP(classname) public:\
174  virtual AFPtr _clone() {\
175  return AFPtr(new classname());\
176  }\
177  virtual SystemWeightList _allocateWeight(const Datetime&, const SystemList&);
178 
179 
180 typedef shared_ptr<AllocateFundsBase> AllocateFundsPtr;
181 typedef shared_ptr<AllocateFundsBase> AFPtr;
182 
183 
184 HKU_API std::ostream & operator<<(std::ostream&, const AllocateFundsBase&);
185 HKU_API std::ostream & operator<<(std::ostream&, const AFPtr&);
186 
187 
188 inline string AllocateFundsBase::name() const {
189  return m_name;
190 }
191 
192 inline void AllocateFundsBase::name(const string& name) {
193  m_name = name;
194 }
195 
196 
198  return m_tm;
199 }
200 
201 inline void AllocateFundsBase::setTM(const TMPtr& tm) {
202  m_tm = tm;
203 }
204 
206  return m_query;
207 }
208 
210  m_query = query;
211 }
212 
214  return m_reserve_percent;
215 }
216 
217 
218 } /* namespace hku */
219 
220 #endif /* TRADE_SYS_ALLOCATEFUNDS_ALLOCATEFUNDSBASE_H_ */
vector< SystemWeight > SystemWeightList
Definition: SystemWeight.h:55
按索引方式查询K线数据条件
Definition: KQuery.h:19
KQuery getQuery()
Definition: AllocateFundsBase.h:205
shared_ptr< AllocateFundsBase > AFPtr
Definition: AllocateFundsBase.h:67
日期类型
Definition: Datetime.h:33
#define GBToUTF8(s)
Definition: util.h:55
void load(Archive &ar, hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:34
#define HKU_API
Definition: DataType.h:12
virtual void _reset()
子类复位接口
Definition: AllocateFundsBase.h:72
vector< SystemPtr > SystemList
Definition: System.h:306
void save(Archive &ar, const hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:20
HKU_API std::ostream & operator<<(std::ostream &os, const Block &blk)
Definition: Block.cpp:13
string name() const
Definition: AllocateFundsBase.h:188
交易对象选择模块
Definition: SelectorBase.h:27
void setTM(const TMPtr &)
设定交易账户
Definition: AllocateFundsBase.h:201
void setQuery(KQuery query)
Definition: AllocateFundsBase.h:209
TMPtr getTM()
获取交易账户
Definition: AllocateFundsBase.h:197
double getReservePercent()
获取不参与资产分配的保留比例
Definition: AllocateFundsBase.h:213
#define PARAMETER_SUPPORT
Definition: Parameter.h:233
shared_ptr< AllocateFundsBase > AllocateFundsPtr
Definition: AllocateFundsBase.h:180
shared_ptr< TradeManager > TMPtr
Definition: TradeManager.h:636
Definition: AllocateFundsBase.h:22
Hikyuu核心命名空间,包含股票数据的管理、指标实现、交易系统框架等
Definition: Block.cpp:11
shared_ptr< AllocateFundsBase > AFPtr
Definition: AllocateFundsBase.h:181