hikyuu2/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.h
2020-08-13 00:35:19 +08:00

81 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* FundsRecord.h
*
* Created on: 2013-5-2
* Author: fasiondog
*/
#pragma once
#ifndef FUNDSRECORD_H_
#define FUNDSRECORD_H_
#include "../DataType.h"
#include "../config.h"
#if HKU_SUPPORT_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#endif
namespace hku {
/**
* 当前资产情况记录由TradeManager::getFunds返回
* @ingroup TradeManagerClass
*/
class HKU_API FundsRecord {
public:
FundsRecord();
FundsRecord(price_t cash, price_t market_value, price_t short_market_value, price_t base_cash,
price_t base_asset, price_t borrow_cash, price_t borrow_asset);
price_t cash; /**< 当前现金 */
price_t market_value; /**< 当前多头市值 */
price_t short_market_value; /**< 当前空头仓位市值 */
price_t base_cash; /**< 当前投入本金principal */
price_t base_asset; /**< 当前投入的资产价值 */
price_t borrow_cash; /**< 当前借入的资金,即负债 */
price_t borrow_asset; /**< 当前借入证券资产价值 */
//当前总资产 = 现金 + 多头市值 + 空头数量×(借入价格 - 当前价格)
// = cash + market_value + borrow_asset - short_market_value
//当前负债 = 借入的资金 + 借入的资产价值
// = borrow_cash + borrow_asset
//当前净资产 = 总资产 - 负债
// = cash + market_value - short_market_value - borrow_cash
//当前投入本值资产 = 投入本金 + 投入资产价值
// = base_cash + base_asset
//当前收益 = 当前净资产 - 当前投入本值资产
// = cash + market_value - short_market_value - borrow_cash - base_cash - base_asset
FundsRecord operator+(const FundsRecord other);
FundsRecord& operator+=(const FundsRecord other);
//序列化支持
#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(cash);
ar& BOOST_SERIALIZATION_NVP(market_value);
ar& BOOST_SERIALIZATION_NVP(short_market_value);
ar& BOOST_SERIALIZATION_NVP(base_cash);
ar& BOOST_SERIALIZATION_NVP(base_asset);
ar& BOOST_SERIALIZATION_NVP(borrow_cash);
ar& BOOST_SERIALIZATION_NVP(borrow_asset);
}
#endif
};
/**
* 输出TradeRecord信息
* @ingroup TradeManagerClass
*/
HKU_API std::ostream& operator<<(std::ostream&, const FundsRecord&);
bool HKU_API operator==(const FundsRecord& d1, const FundsRecord& d2);
} /* namespace hku */
#endif /* FUNDSRECORD_H_ */