mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-01 03:18:18 +08:00
完善TradeManager命令保存功能
Signed-off-by: fasiondog <fasiondog@163.com>
This commit is contained in:
parent
3a30342e9c
commit
06dd8ce7d0
@ -154,6 +154,7 @@ TradeManager::TradeManager(const Datetime& datetime, price_t initcash,
|
||||
setParam<int>("precision", 2); //计算精度
|
||||
setParam<bool>("support_borrow_cash", false); //是否自动融资
|
||||
setParam<bool>("support_borrow_stock", false); //是否自动融券
|
||||
setParam<bool>("save_action", true); //是否保存命令
|
||||
m_init_cash = roundEx(initcash, 2);
|
||||
m_cash = m_init_cash;
|
||||
m_checkin_cash = m_init_cash;
|
||||
@ -161,6 +162,7 @@ TradeManager::TradeManager(const Datetime& datetime, price_t initcash,
|
||||
BUSINESS_INIT, m_init_cash, m_init_cash, 0.0, 0,
|
||||
CostRecord(), 0.0, m_cash, PART_INVALID));
|
||||
m_broker_last_datetime = Datetime::now();
|
||||
_saveAction(m_trade_list.back());
|
||||
}
|
||||
|
||||
|
||||
@ -1885,21 +1887,34 @@ void TradeManager::_update(const Datetime& datetime){
|
||||
|
||||
|
||||
void TradeManager::_saveAction(const TradeRecord& record) {
|
||||
if (getParam<bool>("save_action") == false)
|
||||
return;
|
||||
|
||||
std::stringstream buf(std::stringstream::out);
|
||||
string my_tm("td = my_tm.");
|
||||
string sep(", ");
|
||||
switch (record.business) {
|
||||
case BUSINESS_INIT:
|
||||
buf << "my_tm = crtTM(datetime=Datetime('"
|
||||
<< record.datetime.toString() << "'), "
|
||||
<< "initCash=" << record.cash << sep
|
||||
<< "costFunc=" << m_costfunc->name() << "("
|
||||
<< m_costfunc->getParameter().getNameValueList() << "), "
|
||||
<< "name='" << m_name << "'"
|
||||
<< ")";
|
||||
break;
|
||||
|
||||
case BUSINESS_CHECKIN:
|
||||
buf << my_tm
|
||||
<< "checkin(Datetime('" << record.datetime.toString() << "'), "
|
||||
<< record.cash << sep
|
||||
<< record.cash
|
||||
<< ")";
|
||||
break;
|
||||
|
||||
case BUSINESS_CHECKOUT:
|
||||
buf << my_tm
|
||||
<< "checkout(Datetime('" << record.datetime.toString() << "'), "
|
||||
<< record.cash << sep
|
||||
<< record.cash
|
||||
<< ")";
|
||||
break;
|
||||
|
||||
@ -1919,7 +1934,7 @@ void TradeManager::_saveAction(const TradeRecord& record) {
|
||||
case BUSINESS_SELL:
|
||||
buf << my_tm
|
||||
<< "sell(Datetime('" << record.datetime.toString() << "'),"
|
||||
<< "sm['" << record.stock.market_code() << "']"
|
||||
<< "sm['" << record.stock.market_code() << "'], "
|
||||
<< record.realPrice << sep
|
||||
<< record.number << sep
|
||||
<< record.stoploss << sep
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
FixedA2015TradeCost::FixedA2015TradeCost() : TradeCostBase("FixedA2015") {
|
||||
FixedA2015TradeCost::FixedA2015TradeCost() : TradeCostBase("TC_FixedA2015") {
|
||||
setParam<price_t>("commission", 0.0018);
|
||||
setParam<price_t>("lowest_commission", 5.0);
|
||||
setParam<price_t>("stamptax", 0.001);
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
FixedATradeCost::FixedATradeCost(): TradeCostBase("FixedA") {
|
||||
FixedATradeCost::FixedATradeCost(): TradeCostBase("TC_FixedA") {
|
||||
setParam<price_t>("commission", 0.0018);
|
||||
setParam<price_t>("lowest_commission", 5.0);
|
||||
setParam<price_t>("stamptax", 0.001);
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
ZeroTradeCost::ZeroTradeCost(): TradeCostBase("Zero") {
|
||||
ZeroTradeCost::ZeroTradeCost(): TradeCostBase("TC_Zero") {
|
||||
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ string Parameter::getNameValueList() const {
|
||||
os << iter->first << equal
|
||||
<< boost::any_cast<double>(iter->second);
|
||||
} else if (iter->second.type() == typeid(string)) {
|
||||
os << iter->first << equal
|
||||
os << "\"" << iter->first << "\"" << equal
|
||||
<< boost::any_cast<string>(iter->second);
|
||||
} else {
|
||||
os << "Unsupported";
|
||||
|
@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE( test_TC_Zero ) {
|
||||
CostRecord result;
|
||||
|
||||
/** @arg 检查name */
|
||||
BOOST_CHECK(cost_func->name() == "Zero");
|
||||
BOOST_CHECK(cost_func->name() == "TC_Zero");
|
||||
|
||||
/** @arg 计算买入成本 */
|
||||
result = cost_func->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
|
||||
@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE( test_TC_Zero ) {
|
||||
|
||||
/** @arg 测试clone */
|
||||
TradeCostPtr cost_clone_func = cost_func->clone();
|
||||
BOOST_CHECK(cost_clone_func->name() == "Zero");
|
||||
BOOST_CHECK(cost_clone_func->name() == "TC_Zero");
|
||||
result = cost_clone_func->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
|
||||
BOOST_CHECK(result == Null<CostRecord>());
|
||||
result = cost_clone_func->getSellCost(Datetime(200101010000), stock, 9.01, 1000);
|
||||
@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE( test_ZeroCost_export ) {
|
||||
Stock stock = sm.getStock("sh600004");
|
||||
|
||||
CostRecord result;
|
||||
BOOST_CHECK(zero2->name() == "Zero");
|
||||
BOOST_CHECK(zero2->name() == "TC_Zero");
|
||||
result = zero2->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
|
||||
BOOST_CHECK(result == Null<CostRecord>());
|
||||
result = zero2->getSellCost(Datetime(200101010000), stock, 9.01, 1000);
|
||||
|
Loading…
Reference in New Issue
Block a user