Hikyuu
SlippageBase.h
浏览该文件的文档.
1 /*
2  * SlippageBase.h
3  *
4  * Created on: 2013-3-3
5  * Author: fasiondog
6  */
7 
8 #ifndef SLIPPAGEBASE_H_
9 #define SLIPPAGEBASE_H_
10 
11 #include "../../KData.h"
12 #include "../../utilities/Parameter.h"
13 #include "../../utilities/util.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 
27 class HKU_API SlippageBase: public enable_shared_from_this<SlippageBase> {
29 
30 public:
31  SlippageBase();
32  SlippageBase(const string& name);
33  virtual ~SlippageBase() {}
34 
36  void setTO(const KData& kdata);
37 
39  KData getTO() const;
40 
42  string name() const;
43 
45  void name(const string& name);
46 
48  void reset();
49 
50  typedef shared_ptr<SlippageBase> SlippagePtr;
52  SlippagePtr clone();
53 
60  virtual price_t getRealBuyPrice(const Datetime& datetime,
61  price_t planPrice) = 0;
62 
69  virtual price_t getRealSellPrice(const Datetime& datetime,
70  price_t planPrice) = 0;
71 
73  virtual SlippagePtr _clone() = 0;
74 
76  virtual void _reset() {}
77 
79  virtual void _calculate() = 0;
80 
81 protected:
82  string m_name;
84 
85 //============================================
86 // 序列化支持
87 //============================================
88 #if HKU_SUPPORT_SERIALIZATION
89 private:
90  friend class boost::serialization::access;
91  template<class Archive>
92  void save(Archive & ar, const unsigned int version) const {
93  string name(GBToUTF8(m_name));
94  ar & boost::serialization::make_nvp("m_name", name);
95  ar & BOOST_SERIALIZATION_NVP(m_params);
96  }
97 
98  template<class Archive>
99  void load(Archive & ar, const unsigned int version) {
100  string name;
101  ar & boost::serialization::make_nvp("m_name", name);
102  m_name = UTF8ToGB(name);
103  ar & BOOST_SERIALIZATION_NVP(m_params);
104  }
105 
106  BOOST_SERIALIZATION_SPLIT_MEMBER()
107 #endif /* HKU_SUPPORT_SERIALIZATION */
108 };
109 
110 
111 #if HKU_SUPPORT_SERIALIZATION
112 BOOST_SERIALIZATION_ASSUME_ABSTRACT(SlippageBase)
113 #endif
114 
115 #if HKU_SUPPORT_SERIALIZATION
116 
129 #define SLIPPAGE_NO_PRIVATE_MEMBER_SERIALIZATION private:\
130  friend class boost::serialization::access; \
131  template<class Archive> \
132  void serialize(Archive & ar, const unsigned int version) { \
133  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(SlippageBase); \
134  }
135 #else
136 #define SLIPPAGE_NO_PRIVATE_MEMBER_SERIALIZATION
137 #endif
138 
139 
140 #define SLIPPAGE_IMP(classname) public:\
141  virtual SlippagePtr _clone() {\
142  return SlippagePtr(new classname());\
143  }\
144  virtual price_t getRealBuyPrice(const Datetime&, price_t); \
145  virtual price_t getRealSellPrice(const Datetime&, price_t); \
146  virtual void _calculate();
147 
148 
153 typedef shared_ptr<SlippageBase> SlippagePtr;
154 typedef shared_ptr<SlippageBase> SPPtr;
155 
156 HKU_API std::ostream & operator<<(std::ostream&, const SlippageBase&);
157 HKU_API std::ostream & operator<<(std::ostream&, const SlippagePtr&);
158 
159 
160 inline string SlippageBase::name() const {
161  return m_name;
162 }
163 
164 inline void SlippageBase::name(const string& name) {
165  m_name = name;
166 }
167 
168 inline KData SlippageBase::getTO() const {
169  return m_kdata;
170 }
171 
172 inline void SlippageBase::reset() {
173  _reset();
174 }
175 
176 } /* namespace hku */
177 #endif /* SLIPPAGEBASE_H_ */
void reset()
复位操作
Definition: SlippageBase.h:172
K线数据
Definition: KData.h:19
移滑价差算法基类
Definition: SlippageBase.h:27
virtual ~SlippageBase()
Definition: SlippageBase.h:33
日期类型
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
KData m_kdata
Definition: SlippageBase.h:83
shared_ptr< SlippageBase > SlippagePtr
客户程序都应使用该指针类型,操作移滑价差算法
Definition: SlippageBase.h:153
#define HKU_API
Definition: DataType.h:12
KData getTO() const
获取交易对象
Definition: SlippageBase.h:168
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
double price_t
Definition: DataType.h:53
shared_ptr< SlippageBase > SlippagePtr
Definition: SlippageBase.h:50
string m_name
Definition: SlippageBase.h:82
#define PARAMETER_SUPPORT
Definition: Parameter.h:233
string name() const
获取名称
Definition: SlippageBase.h:160
virtual void _reset()
子类复位接口
Definition: SlippageBase.h:76
#define UTF8ToGB(s)
Definition: util.h:56
Hikyuu核心命名空间,包含股票数据的管理、指标实现、交易系统框架等
Definition: Block.cpp:11
shared_ptr< SlippageBase > SPPtr
Definition: SlippageBase.h:154