TM补充测试

This commit is contained in:
fasiondog 2022-11-22 00:31:14 +08:00
parent 44988948a4
commit 83f4d42031
2 changed files with 39 additions and 5 deletions

View File

@ -186,6 +186,7 @@ public:
/**
*
* @note
* @param ktype
* @return
*/

View File

@ -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;