Hikyuu
ProfitGoalBase.h
浏览该文件的文档.
1 /*
2  * ProfitGoal.h
3  *
4  * Created on: 2013-3-7
5  * Author: fasiondog
6  */
7 
8 #ifndef PROFITGOAL_H_
9 #define PROFITGOAL_H_
10 
11 #include "../../KData.h"
12 #include "../../utilities/Parameter.h"
13 #include "../../trade_manage/TradeManager.h"
14 
15 #if HKU_SUPPORT_SERIALIZATION
16 #include <boost/serialization/shared_ptr.hpp>
17 #include <boost/serialization/assume_abstract.hpp>
18 #include <boost/serialization/base_object.hpp>
19 #endif
20 
21 namespace hku {
22 
28 class HKU_API ProfitGoalBase: public enable_shared_from_this<ProfitGoalBase> {
30 
31 public:
33  ProfitGoalBase(const string& name);
34  virtual ~ProfitGoalBase();
35 
37  void setTM(const TradeManagerPtr& tm);
38 
40  TradeManagerPtr getTM() const;
41 
43  void setTO(const KData& kdata);
44 
46  KData getTO() const;
47 
49  string name() const;
50 
52  void name(const string& name);
53 
55  virtual void buyNotify(const TradeRecord&) {}
56 
58  virtual void sellNotify(const TradeRecord&) {}
59 
61  void reset();
62 
63  typedef shared_ptr<ProfitGoalBase> ProfitGoalPtr;
65  ProfitGoalPtr clone();
66 
73  virtual price_t getGoal(const Datetime& datetime, price_t price) = 0;
74 
76  virtual price_t getShortGoal(const Datetime&, price_t) {
77  return 0.0;
78  }
79 
81  virtual void _reset() {}
82 
84  virtual ProfitGoalPtr _clone() = 0;
85 
87  virtual void _calculate() = 0;
88 
89 protected:
90  string m_name;
93 
94 //============================================
95 // 序列化支持
96 //============================================
97 #if HKU_SUPPORT_SERIALIZATION
98 private:
99  friend class boost::serialization::access;
100  template<class Archive>
101  void save(Archive & ar, const unsigned int version) const {
102  string name(GBToUTF8(m_name));
103  ar & boost::serialization::make_nvp("m_name", name);
104  ar & BOOST_SERIALIZATION_NVP(m_params);
105  }
106 
107  template<class Archive>
108  void load(Archive & ar, const unsigned int version) {
109  string name;
110  ar & boost::serialization::make_nvp("m_name", name);
111  m_name = UTF8ToGB(name);
112  ar & BOOST_SERIALIZATION_NVP(m_params);
113  }
114 
115  BOOST_SERIALIZATION_SPLIT_MEMBER()
116 #endif /* HKU_SUPPORT_SERIALIZATION */
117 };
118 
119 
120 #if HKU_SUPPORT_SERIALIZATION
121 BOOST_SERIALIZATION_ASSUME_ABSTRACT(ProfitGoalBase)
122 #endif
123 
124 #if HKU_SUPPORT_SERIALIZATION
125 
138 #define PROFIT_GOAL_NO_PRIVATE_MEMBER_SERIALIZATION private:\
139  friend class boost::serialization::access; \
140  template<class Archive> \
141  void serialize(Archive & ar, const unsigned int version) { \
142  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ProfitGoalBase); \
143  }
144 #else
145 #define PROFIT_GOAL_NO_PRIVATE_MEMBER_SERIALIZATION
146 #endif
147 
148 
149 #define PROFITGOAL_IMP(classname) public:\
150  virtual ProfitGoalPtr _clone() {\
151  return ProfitGoalPtr(new classname());\
152  }\
153  virtual price_t getGoal(const Datetime&, price_t); \
154  virtual void _calculate();
155 
156 
157 
162 typedef shared_ptr<ProfitGoalBase> ProfitGoalPtr;
163 typedef shared_ptr<ProfitGoalBase> PGPtr;
164 
165 HKU_API std::ostream & operator<<(std::ostream& os, const ProfitGoalBase& pg);
166 HKU_API std::ostream & operator<<(std::ostream& os, const ProfitGoalPtr& pg);
167 
168 
169 inline void ProfitGoalBase::setTM(const TradeManagerPtr& tm) {
170  m_tm = tm;
171 }
172 
174  return m_tm;
175 }
176 
177 inline KData ProfitGoalBase::getTO() const {
178  return m_kdata;
179 }
180 
181 inline string ProfitGoalBase::name() const {
182  return m_name;
183 }
184 
185 inline void ProfitGoalBase::name(const string& name) {
186  m_name = name;
187 }
188 
189 inline void ProfitGoalBase::reset() {
190  _reset();
191 }
192 
193 } /* namespace hku */
194 #endif /* PROFITGOAL_H_ */
KData getTO() const
获取交易对象
Definition: ProfitGoalBase.h:177
shared_ptr< ProfitGoalBase > PGPtr
Definition: ProfitGoalBase.h:163
TradeManagerPtr m_tm
Definition: ProfitGoalBase.h:92
shared_ptr< ProfitGoalBase > ProfitGoalPtr
客户程序都应使用该指针类型
Definition: ProfitGoalBase.h:162
盈利目标策略基类
Definition: ProfitGoalBase.h:28
void setTM(const TradeManagerPtr &tm)
设置账户
Definition: ProfitGoalBase.h:169
K线数据
Definition: KData.h:19
string name() const
获取名称
Definition: ProfitGoalBase.h:181
交易记录
Definition: TradeRecord.h:60
日期类型
Definition: Datetime.h:33
#define GBToUTF8(s)
Definition: util.h:55
KData m_kdata
Definition: ProfitGoalBase.h:91
void load(Archive &ar, hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:34
virtual void _reset()
子类复位接口
Definition: ProfitGoalBase.h:81
shared_ptr< TradeManager > TradeManagerPtr
客户程序应使用此类型进行实际操作
Definition: TradeManager.h:635
#define HKU_API
Definition: DataType.h:12
void save(Archive &ar, const hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:20
void reset()
复位操作
Definition: ProfitGoalBase.h:189
HKU_API std::ostream & operator<<(std::ostream &os, const Block &blk)
Definition: Block.cpp:13
double price_t
Definition: DataType.h:53
shared_ptr< ProfitGoalBase > ProfitGoalPtr
Definition: ProfitGoalBase.h:63
#define PARAMETER_SUPPORT
Definition: Parameter.h:233
virtual price_t getShortGoal(const Datetime &, price_t)
返回0,表示未设目标
Definition: ProfitGoalBase.h:76
TradeManagerPtr getTM() const
获取账户
Definition: ProfitGoalBase.h:173
#define UTF8ToGB(s)
Definition: util.h:56
Hikyuu核心命名空间,包含股票数据的管理、指标实现、交易系统框架等
Definition: Block.cpp:11
virtual void sellNotify(const TradeRecord &)
接收实际交易变化情况
Definition: ProfitGoalBase.h:58
virtual void buyNotify(const TradeRecord &)
接收实际交易变化情况
Definition: ProfitGoalBase.h:55
string m_name
Definition: ProfitGoalBase.h:90