Hikyuu
|
账户交易管理模块,管理帐户的交易记录及资金使用情况 更多...
#include <TradeManager.h>
Public 成员函数 | |
TradeManager (const Datetime &datetime=Datetime(199001010000LL), price_t initcash=100000.0, const TradeCostPtr &costfunc=TC_Zero(), const string &name="SYS") | |
virtual | ~TradeManager () |
void | reset () |
复位,清空交易、持仓记录 更多... | |
void | regBroker (const OrderBrokerPtr &broker) |
注册订单代理 更多... | |
void | clearBroker () |
清空已注册的订单代理 更多... | |
Datetime | getBrokerLastDatetime () const |
从哪个时刻开始启动订单代理进行下单操作 更多... | |
void | setBrokerLastDatetime (const Datetime &date) |
设置开始订单代理操作的时刻 更多... | |
shared_ptr< TradeManager > | clone () |
double | getMarginRate (const Datetime &datetime, const Stock &stock) |
获取指定对象的保证金比率 更多... | |
string | name () const |
账户名称 更多... | |
void | name (const string &name) |
设置账户名称 更多... | |
price_t | initCash () const |
初始资金 更多... | |
Datetime | initDatetime () const |
账户建立日期 更多... | |
Datetime | firstDatetime () const |
第一笔买入交易发生日期,如未发生交易返回Null<Datetime>() 更多... | |
Datetime | lastDatetime () const |
最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期 更多... | |
bool | reinvest () const |
红利/股息/送股再投资标志,即是否忽略权息信息 更多... | |
int | precision () const |
交易精度 更多... | |
TradeCostPtr | costFunc () const |
获取交易算法指针 更多... | |
void | costFunc (const TradeCostPtr &func) |
设置交易算法指针 更多... | |
price_t | currentCash () const |
返回当前现金 更多... | |
price_t | cash (const Datetime &datetime, KQuery::KType ktype=KQuery::DAY) |
获取指定日期的现金 更多... | |
bool | have (const Stock &stock) const |
当前是否持有指定的证券 更多... | |
bool | haveShort (const Stock &stock) const |
当前空头仓位是否持有指定的证券 更多... | |
size_t | getStockNumber () const |
当前持有的证券种类数量 更多... | |
size_t | getShortStockNumber () const |
当前空头持有的证券种类数量 更多... | |
size_t | getHoldNumber (const Datetime &datetime, const Stock &stock) |
获取指定时刻的某证券持有数量 更多... | |
size_t | getShortHoldNumber (const Datetime &datetime, const Stock &stock) |
获取指定时刻的空头某证券持有数量 更多... | |
size_t | getDebtNumber (const Datetime &datetime, const Stock &stock) |
获取指定时刻已借入的股票数量 更多... | |
price_t | getDebtCash (const Datetime &datetime) |
获取指定时刻已借入的现金额 更多... | |
const TradeRecordList & | getTradeList () const |
获取全部交易记录 更多... | |
TradeRecordList | getTradeList (const Datetime &start, const Datetime &end) const |
获取指定日期范围内的交易记录[start, end) 更多... | |
PositionRecordList | getPositionList () const |
获取当前全部持仓记录 更多... | |
const PositionRecordList & | getHistoryPositionList () const |
获取全部历史持仓记录,即已平仓记录 更多... | |
PositionRecordList | getShortPositionList () const |
获取当前全部空头仓位记录 更多... | |
const PositionRecordList & | getShortHistoryPositionList () const |
获取全部空头历史仓位记录 更多... | |
PositionRecord | getPosition (const Stock &) const |
获取指定证券的当前持仓记录,如当前未持有该票,返回Null<PositionRecord>() 更多... | |
PositionRecord | getShortPosition (const Stock &) const |
获取指定证券的当前空头仓位持仓记录,如当前未持有该票,返回Null<PositionRecord>() 更多... | |
BorrowRecordList | getBorrowStockList () const |
获取当前借入的股票列表 更多... | |
CostRecord | getBuyCost (const Datetime &datetime, const Stock &stock, price_t price, size_t num) const |
计算买入成本 更多... | |
CostRecord | getSellCost (const Datetime &datetime, const Stock &stock, price_t price, size_t num) const |
计算卖出成本 更多... | |
CostRecord | getBorrowCashCost (const Datetime &datetime, price_t cash) |
计算计入现金时的费用成本 更多... | |
CostRecord | getReturnCashCost (const Datetime &borrow_datetime, const Datetime &return_datetime, price_t cash) |
计算归还融资成本 更多... | |
CostRecord | getBorrowStockCost (const Datetime &datetime, const Stock &stock, price_t price, size_t num) |
计算融劵借入成本 更多... | |
CostRecord | getReturnStockCost (const Datetime &borrow_datetime, const Datetime &return_datetime, const Stock &stock, price_t price, size_t num) |
计算融劵归还成本 更多... | |
bool | checkin (const Datetime &datetime, price_t cash) |
存入资金 更多... | |
bool | checkout (const Datetime &datetime, price_t cash) |
取出资金 更多... | |
bool | checkinStock (const Datetime &datetime, const Stock &stock, price_t price, size_t number) |
存入资产 更多... | |
bool | checkoutStock (const Datetime &datetime, const Stock &stock, price_t price, size_t number) |
取出当前资产 更多... | |
TradeRecord | buy (const Datetime &datetime, const Stock &stock, price_t realPrice, size_t number, price_t stoploss=0.0, price_t goalPrice=0.0, price_t planPrice=0.0, SystemPart from=PART_INVALID) |
买入操作 更多... | |
TradeRecord | sell (const Datetime &datetime, const Stock &stock, price_t realPrice, size_t number=Null< size_t >(), price_t stoploss=0.0, price_t goalPrice=0.0, price_t planPrice=0.0, SystemPart from=PART_INVALID) |
卖出操作 更多... | |
TradeRecord | sellShort (const Datetime &datetime, const Stock &stock, price_t realPrice, size_t number, price_t stoploss=0.0, price_t goalPrice=0.0, price_t planPrice=0.0, SystemPart from=PART_INVALID) |
卖空 更多... | |
TradeRecord | buyShort (const Datetime &datetime, const Stock &stock, price_t realPrice, size_t number=Null< size_t >(), price_t stoploss=0.0, price_t goalPrice=0.0, price_t planPrice=0.0, SystemPart from=PART_INVALID) |
卖空后回补 更多... | |
bool | borrowCash (const Datetime &datetime, price_t cash) |
借入资金,从其他来源借取的资金,如融资 更多... | |
bool | returnCash (const Datetime &datetime, price_t cash) |
归还资金 更多... | |
bool | borrowStock (const Datetime &datetime, const Stock &stock, price_t price, size_t number) |
借入证券 更多... | |
bool | returnStock (const Datetime &datetime, const Stock &stock, price_t price, size_t number) |
归还证券 更多... | |
FundsRecord | getFunds (KQuery::KType ktype=KQuery::DAY) const |
获取账户当前时刻的资产详情 更多... | |
FundsRecord | getFunds (const Datetime &datetime, KQuery::KType ktype=KQuery::DAY) |
获取指定时刻的资产市值详情 更多... | |
PriceList | getFundsCurve (const DatetimeList &dates, KQuery::KType ktype=KQuery::DAY) |
获取资产净值曲线,含借入的资产 更多... | |
PriceList | getProfitCurve (const DatetimeList &dates, KQuery::KType ktype=KQuery::DAY) |
获取收益曲线,即扣除历次存入资金后的资产净值曲线 更多... | |
bool | addTradeRecord (const TradeRecord &tr) |
直接加入交易记录 更多... | |
string | toString () const |
字符串输出 更多... | |
void | tocsv (const string &path) |
以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线 更多... | |
友元 | |
class | boost::serialization::access |
账户交易管理模块,管理帐户的交易记录及资金使用情况
默认参数: reinvest(bool): false 红利/股息/送股再投资标志,即是否忽略权息信息 precision(int): 2 计算精度 support_borrow_cash(bool): false 买入操作时是否自动融资 support_borrow_stock(bool): false 卖空时是否自动融劵
hku::TradeManager::TradeManager | ( | const Datetime & | datetime = Datetime(199001010000LL) , |
price_t | initcash = 100000.0 , |
||
const TradeCostPtr & | costfunc = TC_Zero() , |
||
const string & | name = "SYS" |
||
) |
|
virtual |
bool hku::TradeManager::addTradeRecord | ( | const TradeRecord & | tr | ) |
直接加入交易记录
tr | 待加入的交易记录 |
借入资金,从其他来源借取的资金,如融资
datetime | 借入时间 |
cash | 借入的现金 |
bool hku::TradeManager::borrowStock | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | price, | ||
size_t | number | ||
) |
借入证券
datetime | 借入时间 |
stock | 借入的stock |
price | 借入时单股价格 |
number | 借入时数量 |
TradeRecord hku::TradeManager::buy | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | realPrice, | ||
size_t | number, | ||
price_t | stoploss = 0.0 , |
||
price_t | goalPrice = 0.0 , |
||
price_t | planPrice = 0.0 , |
||
SystemPart | from = PART_INVALID |
||
) |
买入操作
datetime | 买入时间 |
stock | 买入的证券 |
realPrice | 实际买入价格 |
number | 买入数量 |
stoploss | 止损价 |
goalPrice | 目标价格 |
planPrice | 计划买入价格 |
from | 记录是哪个系统部件发出的买入指示 |
TradeRecord hku::TradeManager::buyShort | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | realPrice, | ||
size_t | number = Null<size_t>() , |
||
price_t | stoploss = 0.0 , |
||
price_t | goalPrice = 0.0 , |
||
price_t | planPrice = 0.0 , |
||
SystemPart | from = PART_INVALID |
||
) |
卖空后回补
datetime | 买入时间 |
stock | 买入的证券 |
realPrice | 实际买入价格 |
number | 卖出数量,如果等于Null<size_t>(), 表示全部卖出 |
stoploss | 止损价 |
goalPrice | 目标价格 |
planPrice | 计划买入价格 |
from | 记录是哪个系统部件发出的卖出指示 |
price_t hku::TradeManager::cash | ( | const Datetime & | datetime, |
KQuery::KType | ktype = KQuery::DAY |
||
) |
获取指定日期的现金
存入资金
datetime | 存入时间 |
cash | 存入的资金量 |
bool hku::TradeManager::checkinStock | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | price, | ||
size_t | number | ||
) |
存入资产
datetime | 存入日期 |
stock | 待存入的股票 |
price | 存入股票的每股价格 |
number | 存入股票的数量 |
取出资金
datetime | 取出时间 |
cash | 取出的资金量 |
bool hku::TradeManager::checkoutStock | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | price, | ||
size_t | number | ||
) |
取出当前资产
datetime | 取出日期 |
stock | 待取出的股票 |
price | 取出的每股价格 |
number | 取出的数量 |
void hku::TradeManager::clearBroker | ( | ) |
清空已注册的订单代理
TradeManagerPtr hku::TradeManager::clone | ( | ) |
|
inline |
获取交易算法指针
|
inline |
设置交易算法指针
|
inline |
返回当前现金
Datetime hku::TradeManager::firstDatetime | ( | ) | const |
第一笔买入交易发生日期,如未发生交易返回Null<Datetime>()
|
inline |
计算计入现金时的费用成本
datetime | 借入日期 |
cash | 现金额 |
|
inline |
计算融劵借入成本
datetime | 融劵日期 |
stock | 借入的对象 |
price | 每股价格 |
num | 借入的数量 |
BorrowRecordList hku::TradeManager::getBorrowStockList | ( | ) | const |
获取当前借入的股票列表
|
inline |
从哪个时刻开始启动订单代理进行下单操作
|
inline |
获取指定时刻已借入的股票数量
FundsRecord hku::TradeManager::getFunds | ( | KQuery::KType | ktype = KQuery::DAY | ) | const |
获取账户当前时刻的资产详情
ktype | 日期的类型 |
FundsRecord hku::TradeManager::getFunds | ( | const Datetime & | datetime, |
KQuery::KType | ktype = KQuery::DAY |
||
) |
获取指定时刻的资产市值详情
datetime | 必须大于帐户建立的初始日期,或为Null<Datetime>() |
ktype | 日期的类型 |
PriceList hku::TradeManager::getFundsCurve | ( | const DatetimeList & | dates, |
KQuery::KType | ktype = KQuery::DAY |
||
) |
获取资产净值曲线,含借入的资产
dates | 日期列表,根据该日期列表获取其对应的资产净值曲线 |
ktype | K线类型,必须与日期列表匹配,默认KQuery::DAY |
|
inline |
获取全部历史持仓记录,即已平仓记录
获取指定时刻的某证券持有数量
获取指定对象的保证金比率
datetime | 日期 |
stock | 指定对象 |
PositionRecord hku::TradeManager::getPosition | ( | const Stock & | stock | ) | const |
获取指定证券的当前持仓记录,如当前未持有该票,返回Null<PositionRecord>()
PositionRecordList hku::TradeManager::getPositionList | ( | ) | const |
获取当前全部持仓记录
PriceList hku::TradeManager::getProfitCurve | ( | const DatetimeList & | dates, |
KQuery::KType | ktype = KQuery::DAY |
||
) |
获取收益曲线,即扣除历次存入资金后的资产净值曲线
dates | 日期列表,根据该日期列表获取其对应的收益曲线,应为递增顺序 |
ktype | K线类型,必须与日期列表匹配,默认为KQuery::DAY |
|
inline |
计算归还融资成本
borrow_datetime | 借入日期 |
return_datetime | 归还日期 |
cash | 归还金额 |
|
inline |
计算融劵归还成本
borrow_datetime | 借入日期 |
return_datetime | 归还日期 |
stock | 归还的对象 |
price | 归还时每股价格 |
num | 归还的数量 |
|
inline |
|
inline |
获取全部空头历史仓位记录
获取指定时刻的空头某证券持有数量
PositionRecord hku::TradeManager::getShortPosition | ( | const Stock & | stock | ) | const |
获取指定证券的当前空头仓位持仓记录,如当前未持有该票,返回Null<PositionRecord>()
PositionRecordList hku::TradeManager::getShortPositionList | ( | ) | const |
获取当前全部空头仓位记录
|
inline |
当前空头持有的证券种类数量
|
inline |
当前持有的证券种类数量
|
inline |
获取全部交易记录
TradeRecordList hku::TradeManager::getTradeList | ( | const Datetime & | start, |
const Datetime & | end | ||
) | const |
获取指定日期范围内的交易记录[start, end)
start | 起始日期 |
end | 结束日期 |
|
inline |
当前是否持有指定的证券
stock | 指定证券 |
|
inline |
当前空头仓位是否持有指定的证券
stock | 指定证券 |
|
inline |
初始资金
|
inline |
账户建立日期
|
inline |
最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期
|
inline |
账户名称
|
inline |
设置账户名称
|
inline |
交易精度
void hku::TradeManager::regBroker | ( | const OrderBrokerPtr & | broker | ) |
注册订单代理
broker | 订单代理实例 |
|
inline |
红利/股息/送股再投资标志,即是否忽略权息信息
void hku::TradeManager::reset | ( | ) |
复位,清空交易、持仓记录
归还资金
datetime | 归还日期 |
cash | 归还现金 |
bool hku::TradeManager::returnStock | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | price, | ||
size_t | number | ||
) |
归还证券
datetime | 归还时间 |
stock | 归还的stock |
price | 归还时单股价格 |
number | 归还数量 |
TradeRecord hku::TradeManager::sell | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | realPrice, | ||
size_t | number = Null<size_t>() , |
||
price_t | stoploss = 0.0 , |
||
price_t | goalPrice = 0.0 , |
||
price_t | planPrice = 0.0 , |
||
SystemPart | from = PART_INVALID |
||
) |
卖出操作
datetime | 卖出时间 |
stock | 卖出的证券 |
realPrice | 实际卖出价格 |
number | 卖出数量,如果等于Null<size_t>(), 表示全部卖出 |
stoploss | 新的止损价 |
goalPrice | 新的目标价格 |
planPrice | 原计划卖出价格 |
from | 记录是哪个系统部件发出的卖出指示 |
TradeRecord hku::TradeManager::sellShort | ( | const Datetime & | datetime, |
const Stock & | stock, | ||
price_t | realPrice, | ||
size_t | number, | ||
price_t | stoploss = 0.0 , |
||
price_t | goalPrice = 0.0 , |
||
price_t | planPrice = 0.0 , |
||
SystemPart | from = PART_INVALID |
||
) |
卖空
datetime | 卖空时间 |
stock | 卖空的证券 |
realPrice | 实际卖空价格 |
number | 卖出数量 |
stoploss | 止损价 |
goalPrice | 目标价格 |
planPrice | 计划卖空价格 |
from | 记录是哪个系统部件发出的买入指示 |
|
inline |
设置开始订单代理操作的时刻
void hku::TradeManager::tocsv | ( | const string & | path | ) |
以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线
path | 输出文件所在目录 |
string hku::TradeManager::toString | ( | ) | const |
字符串输出
|
friend |