mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-05 05:17:47 +08:00
TM补充测试
This commit is contained in:
parent
44988948a4
commit
83f4d42031
@ -186,6 +186,7 @@ public:
|
||||
|
||||
/**
|
||||
* 获取账户当前时刻的资产详情
|
||||
* @note 由于没有日期,此时计算的市值其实为买入时的市值
|
||||
* @param ktype 日期的类型
|
||||
* @return 资产详情
|
||||
*/
|
||||
|
@ -397,13 +397,46 @@ TEST_CASE("test_TradeManager_normal_buy_and_sell_no_margin_by_day") {
|
||||
CHECK_EQ(contract.marginRatio, 1.0);
|
||||
|
||||
/** @arg 5月26日卖出剩余股票,中间经历权息变化, 检测 tm 所有接口正确性 */
|
||||
tr = tm->sell(Datetime(199305260000LL), stk, 28.1, 100.);
|
||||
CHECK_EQ(tr, TradeRecord(stk, Datetime(199305260000LL), BUSINESS_SELL, 0., 28.1, 0., 100., cost,
|
||||
0., 102680., 1., PART_INVALID));
|
||||
|
||||
HKU_INFO("{}", tr);
|
||||
HKU_INFO("{}", stk.getKRecord(Datetime(199305260000LL)));
|
||||
|
||||
HKU_INFO("{}", tm);
|
||||
HKU_INFO("{}", tm->getFunds(KQuery::DAY));
|
||||
|
||||
auto current_num = tm->getHoldNumber(Datetime(199305260000LL), stk);
|
||||
CHECK_EQ(current_num, 185); // 24日送转85股, 红利30元
|
||||
HKU_INFO("{}", tr);
|
||||
HKU_INFO("{}", stk.getKRecord(Datetime(199305260000LL)));
|
||||
HKU_INFO("{}", tm);
|
||||
HKU_INFO("{}", tm->getFunds(KQuery::DAY));
|
||||
|
||||
tr = tm->sell(Datetime(199305260000LL), stk, 28.1, MAX_DOUBLE);
|
||||
CHECK_EQ(tm->currentCash(), 99458.50);
|
||||
CHECK_EQ(tr, TradeRecord(stk, Datetime(199305260000LL), BUSINESS_SELL, 0., 28.1, 0., 185., cost,
|
||||
0., 99458.5, 1., PART_INVALID));
|
||||
CHECK(tm->getPositionList().empty());
|
||||
CHECK_EQ(tm->getFunds(KQuery::DAY), FundsRecord(99458.5, 0., 100000.0, 0.));
|
||||
CHECK_EQ(tm->getFunds(Null<Datetime>(), KQuery::DAY), tm->getFunds(KQuery::DAY));
|
||||
|
||||
// CHECK_EQ(tm->getFunds(KQuery::DAY), FundsRecord(100000., 0., 100000.0, 0.));
|
||||
// CHECK_EQ(tm->getFunds(Null<Datetime>(), KQuery::DAY), tm->getFunds(KQuery::DAY));
|
||||
CHECK_EQ(tm->getFunds(Datetime(199304300000LL), KQuery::DAY), FundsRecord(0., 0., 0., 0.));
|
||||
CHECK_EQ(tm->getFunds(Datetime(199305010900LL), KQuery::DAY),
|
||||
FundsRecord(100000., 0., 100000.0, 0.));
|
||||
CHECK_EQ(tm->getFunds(Datetime(199305100000LL), KQuery::DAY),
|
||||
FundsRecord(100000., 0., 100000.0, 0.));
|
||||
|
||||
// date_list = getDateRange(Datetime(199304300000LL), Datetime(199305030000LL));
|
||||
// funds_curve = tm->getFundsCurve(date_list, KQuery::DAY);
|
||||
// CHECK_EQ(funds_curve.size(), 3);
|
||||
// CHECK_EQ(funds_curve[0], 0.);
|
||||
// CHECK_EQ(funds_curve[1], 100000.);
|
||||
// CHECK_EQ(funds_curve[2], 100000.);
|
||||
// profit_curve = tm->getProfitCurve(date_list, KQuery::DAY);
|
||||
// CHECK_EQ(profit_curve.size(), 3);
|
||||
// CHECK_EQ(profit_curve[0], 0.);
|
||||
// CHECK_EQ(profit_curve[1], 0.);
|
||||
// CHECK_EQ(profit_curve[2], 0.);
|
||||
}
|
||||
|
||||
/** @par 检测点,正常买卖 */
|
||||
@ -411,7 +444,7 @@ TEST_CASE("test_TradeManager_normal_buy_and_sell_with_margin") {
|
||||
Stock stk = getStock("sz000001");
|
||||
|
||||
// 创建使用合约交易的账户
|
||||
TradeManagerPtr tm = crtTM(Datetime(199305010000), 1000, TC_Zero(), MR_Fixed(0.1));
|
||||
TradeManagerPtr tm = crtTM(Datetime(199305010000), 1000., TC_Zero(), MR_Fixed(0.1));
|
||||
tm->setParam<bool>("use_contract", true);
|
||||
|
||||
TradeRecord tr;
|
||||
|
Loading…
Reference in New Issue
Block a user