diff --git a/libs/hikyuu/trade_manage/TradeManager.cpp b/libs/hikyuu/trade_manage/TradeManager.cpp index cb1a23af..fa63fcc3 100644 --- a/libs/hikyuu/trade_manage/TradeManager.cpp +++ b/libs/hikyuu/trade_manage/TradeManager.cpp @@ -154,6 +154,7 @@ TradeManager::TradeManager(const Datetime& datetime, price_t initcash, setParam("precision", 2); //计算精度 setParam("support_borrow_cash", false); //是否自动融资 setParam("support_borrow_stock", false); //是否自动融券 + setParam("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("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 diff --git a/libs/hikyuu/trade_manage/imp/FixedA2015TradeCost.cpp b/libs/hikyuu/trade_manage/imp/FixedA2015TradeCost.cpp index 190c64f0..bc2a0945 100644 --- a/libs/hikyuu/trade_manage/imp/FixedA2015TradeCost.cpp +++ b/libs/hikyuu/trade_manage/imp/FixedA2015TradeCost.cpp @@ -10,7 +10,7 @@ namespace hku { -FixedA2015TradeCost::FixedA2015TradeCost() : TradeCostBase("FixedA2015") { +FixedA2015TradeCost::FixedA2015TradeCost() : TradeCostBase("TC_FixedA2015") { setParam("commission", 0.0018); setParam("lowest_commission", 5.0); setParam("stamptax", 0.001); diff --git a/libs/hikyuu/trade_manage/imp/FixedATradeCost.cpp b/libs/hikyuu/trade_manage/imp/FixedATradeCost.cpp index 0fa0f73e..1fdda8aa 100644 --- a/libs/hikyuu/trade_manage/imp/FixedATradeCost.cpp +++ b/libs/hikyuu/trade_manage/imp/FixedATradeCost.cpp @@ -11,7 +11,7 @@ namespace hku { -FixedATradeCost::FixedATradeCost(): TradeCostBase("FixedA") { +FixedATradeCost::FixedATradeCost(): TradeCostBase("TC_FixedA") { setParam("commission", 0.0018); setParam("lowest_commission", 5.0); setParam("stamptax", 0.001); diff --git a/libs/hikyuu/trade_manage/imp/ZeroTradeCost.cpp b/libs/hikyuu/trade_manage/imp/ZeroTradeCost.cpp index 46ca7d7d..5938f356 100644 --- a/libs/hikyuu/trade_manage/imp/ZeroTradeCost.cpp +++ b/libs/hikyuu/trade_manage/imp/ZeroTradeCost.cpp @@ -9,7 +9,7 @@ namespace hku { -ZeroTradeCost::ZeroTradeCost(): TradeCostBase("Zero") { +ZeroTradeCost::ZeroTradeCost(): TradeCostBase("TC_Zero") { } diff --git a/libs/hikyuu/utilities/Parameter.cpp b/libs/hikyuu/utilities/Parameter.cpp index 69fc9e86..8b5974c9 100644 --- a/libs/hikyuu/utilities/Parameter.cpp +++ b/libs/hikyuu/utilities/Parameter.cpp @@ -128,7 +128,7 @@ string Parameter::getNameValueList() const { os << iter->first << equal << boost::any_cast(iter->second); } else if (iter->second.type() == typeid(string)) { - os << iter->first << equal + os << "\"" << iter->first << "\"" << equal << boost::any_cast(iter->second); } else { os << "Unsupported"; diff --git a/test/libs/hikyuu/trade_manage/test_crtZeroTC.cpp b/test/libs/hikyuu/trade_manage/test_crtZeroTC.cpp index 81d0a300..a66c643e 100644 --- a/test/libs/hikyuu/trade_manage/test_crtZeroTC.cpp +++ b/test/libs/hikyuu/trade_manage/test_crtZeroTC.cpp @@ -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()); 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()); result = zero2->getSellCost(Datetime(200101010000), stock, 9.01, 1000);