hikyuu2/hikyuu_cpp/hikyuu/trade_manage/TradeCostBase.h

176 lines
4.5 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* TradeCostBase.h
*
* Created on: 2013-2-13
* Author: fasiondog
*/
#ifndef TRADECOSTBASE_H_
#define TRADECOSTBASE_H_
#include "../Stock.h"
#include "../utilities/util.h"
#include "../utilities/Parameter.h"
#include "CostRecord.h"
#if HKU_SUPPORT_SERIALIZATION
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/base_object.hpp>
#endif
namespace hku {
/**
*
* @ingroup TradeCost
*/
class HKU_API TradeCostBase {
PARAMETER_SUPPORT
public:
TradeCostBase(const string& name);
virtual ~TradeCostBase();
typedef shared_ptr<TradeCostBase> TradeCostPtr;
/** 克隆操作 */
TradeCostPtr clone();
/** 获取名称 */
const string& name() const {
return m_name;
}
/**
*
* @param datetime
* @param stock
* @param price
* @param num
* @return CostRecord
*/
virtual CostRecord getBuyCost(const Datetime& datetime,
const Stock& stock, price_t price, size_t num) const = 0;
/**
*
* @param datetime
* @param stock
* @param price
* @param num
* @return CostRecord
*/
virtual CostRecord getSellCost(const Datetime& datetime,
const Stock& stock, price_t price, size_t num) const = 0;
/**
*
* @param datetime
* @param cash
*/
virtual CostRecord getBorrowCashCost(const Datetime& datetime,
price_t cash) const {
return CostRecord();
}
/**
*
* @param borrow_datetime
* @param return_datetime
* @param cash
*/
virtual CostRecord getReturnCashCost(
const Datetime& borrow_datetime,
const Datetime& return_datetime,
price_t cash) const {
return CostRecord();
}
/**
*
* @param datetime
* @param stock
* @param price
* @param num
*/
virtual CostRecord getBorrowStockCost(const Datetime& datetime,
const Stock& stock, price_t price, size_t num) const {
return CostRecord();
}
/**
*
* @param borrow_datetime
* @param return_datetime
* @param stock
* @param price
* @param num
*/
virtual CostRecord getReturnStockCost(const Datetime& borrow_datetime,
const Datetime& return_datetime,
const Stock& stock, price_t price, size_t num) const {
return CostRecord();
}
/** 继承子类必须实现私有变量的克隆接口 */
virtual TradeCostPtr _clone() = 0;
private:
string m_name;
//============================================
// 序列化支持
//============================================
#if HKU_SUPPORT_SERIALIZATION
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & BOOST_SERIALIZATION_NVP(m_name);
ar & BOOST_SERIALIZATION_NVP(m_params);
}
#endif /* HKU_SUPPORT_SERIALIZATION */
};
#if HKU_SUPPORT_SERIALIZATION
BOOST_SERIALIZATION_ASSUME_ABSTRACT(TradeCostBase)
#endif
#if HKU_SUPPORT_SERIALIZATION
/**
* 使
* @code
* class DrivedCost: public TradeCostBase {
* TRADE_COST_NO_PRIVATE_MEMBER_SERIALIZATION
*
* public:
* DrivedCost();
* ...
* };
* @endcode
* @ingroup TradeCost
*/
#define TRADE_COST_NO_PRIVATE_MEMBER_SERIALIZATION private:\
friend class boost::serialization::access; \
template<class Archive> \
void serialize(Archive & ar, const unsigned int version) { \
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(TradeCostBase); \
}
#else
#define TRADE_COST_NO_PRIVATE_MEMBER_SERIALIZATION
#endif
/**
*
* @ingroup TradeCost
*/
typedef shared_ptr<TradeCostBase> TradeCostPtr;
HKU_API std::ostream & operator<<(std::ostream &, const TradeCostBase&);
HKU_API std::ostream & operator<<(std::ostream &, const TradeCostPtr&);
} /* namespace hku */
#endif /* TRADECOSTBASE_H_ */