From 810156176f8cfeb6b2ba5d2df745300a7407769e Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 24 Sep 2024 12:09:11 +0800 Subject: [PATCH] clear cppcheck infos --- .github/workflows/macos_arm64.yml | 2 +- hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp | 4 +- .../hikyuu/strategy/BrokerTradeManager.h | 52 +++++----- .../hikyuu/trade_manage/TradeManagerBase.h | 11 ++- .../trade_sys/condition/ConditionBase.h | 4 +- .../trade_sys/environment/EnvironmentBase.h | 12 +-- .../hikyuu/trade_sys/portfolio/Portfolio.cpp | 2 +- .../system/imp/WalkForwardSystem.cpp | 8 +- .../system/imp/WalkForwardTradeManager.h | 95 ++++++++++--------- 9 files changed, 97 insertions(+), 93 deletions(-) diff --git a/.github/workflows/macos_arm64.yml b/.github/workflows/macos_arm64.yml index 3045d16c..753043c8 100644 --- a/.github/workflows/macos_arm64.yml +++ b/.github/workflows/macos_arm64.yml @@ -50,4 +50,4 @@ jobs: - name: build run: | - xmake -bvD core + xmake -b core diff --git a/hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp b/hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp index 5a95ab68..3f2a2403 100644 --- a/hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp +++ b/hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp @@ -177,14 +177,14 @@ std::pair HKU_API findOptimalSystemMulti(const SystemList& sys_l }); if (0 == sort_mode) { - for (auto& v : all_result) { + for (const auto& v : all_result) { if (v.first > result.first) { result.first = v.first; result.second = v.second; } } } else { - for (auto& v : all_result) { + for (const auto& v : all_result) { if (v.first < result.first) { result.first = v.first; result.second = v.second; diff --git a/hikyuu_cpp/hikyuu/strategy/BrokerTradeManager.h b/hikyuu_cpp/hikyuu/strategy/BrokerTradeManager.h index 0ff9e7c6..ebebf247 100644 --- a/hikyuu_cpp/hikyuu/strategy/BrokerTradeManager.h +++ b/hikyuu_cpp/hikyuu/strategy/BrokerTradeManager.h @@ -94,48 +94,48 @@ public: * @param stock 指定证券 * @return true 是 | false 否 */ - virtual bool haveShort(const Stock& stock) const { + virtual bool haveShort(const Stock& stock) const override { HKU_WARN("The subclass does not implement this method"); return false; } /** 当前持有的证券种类数量 */ - virtual size_t getStockNumber() const { + virtual size_t getStockNumber() const override { return m_position.size(); } /** 当前空头持有的证券种类数量 */ - virtual size_t getShortStockNumber() const { + virtual size_t getShortStockNumber() const override { HKU_WARN("The subclass does not implement this method"); return 0; } /** 获取指定时刻的某证券持有数量 */ - virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) { + virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) override { HKU_WARN("The subclass does not implement this method"); return 0.0; } /** 获取指定时刻的空头某证券持有数量 */ - virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) { + virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) override { HKU_WARN("The subclass does not implement this method"); return 0.0; } /** 获取指定时刻已借入的股票数量 */ - virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) { + virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) override { HKU_WARN("The subclass does not implement this method"); return 0.0; } /** 获取指定时刻已借入的现金额 */ - virtual price_t getDebtCash(const Datetime& datetime) { + virtual price_t getDebtCash(const Datetime& datetime) override { HKU_WARN("The subclass does not implement this method"); return 0.0; } /** 获取全部交易记录 */ - virtual TradeRecordList getTradeList() const { + virtual TradeRecordList getTradeList() const override { HKU_WARN("The subclass does not implement this method"); return TradeRecordList(); } @@ -146,7 +146,8 @@ public: * @param end 结束日期 * @return 交易记录列表 */ - virtual TradeRecordList getTradeList(const Datetime& start, const Datetime& end) const { + virtual TradeRecordList getTradeList(const Datetime& start, + const Datetime& end) const override { HKU_WARN("The subclass does not implement this method"); return TradeRecordList(); } @@ -155,19 +156,19 @@ public: virtual PositionRecordList getPositionList() const override; /** 获取全部历史持仓记录,即已平仓记录 */ - virtual PositionRecordList getHistoryPositionList() const { + virtual PositionRecordList getHistoryPositionList() const override { HKU_WARN("The subclass does not implement this method"); return PositionRecordList(); } /** 获取当前全部空头仓位记录 */ - virtual PositionRecordList getShortPositionList() const { + virtual PositionRecordList getShortPositionList() const override { HKU_WARN("The subclass does not implement this method"); return PositionRecordList(); } /** 获取全部空头历史仓位记录 */ - virtual PositionRecordList getShortHistoryPositionList() const { + virtual PositionRecordList getShortHistoryPositionList() const override { HKU_WARN("The subclass does not implement this method"); return PositionRecordList(); } @@ -183,13 +184,13 @@ public: * 获取指定证券的空头持仓记录 * @param stock 指定的证券 */ - virtual PositionRecord getShortPosition(const Stock& stock) const { + virtual PositionRecord getShortPosition(const Stock& stock) const override { HKU_WARN("The subclass does not implement this method"); return PositionRecord(); } /** 获取当前借入的股票列表 */ - virtual BorrowRecordList getBorrowStockList() const { + virtual BorrowRecordList getBorrowStockList() const override { HKU_WARN("The subclass does not implement this method"); return BorrowRecordList(); } @@ -222,7 +223,7 @@ public: * @return true | false */ virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -237,7 +238,7 @@ public: * @note 应该不会被用到 */ virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -289,7 +290,8 @@ public: */ virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice, double number, price_t stoploss = 0.0, price_t goalPrice = 0.0, - price_t planPrice = 0.0, SystemPart from = PART_INVALID) { + price_t planPrice = 0.0, + SystemPart from = PART_INVALID) override { HKU_WARN("The subclass does not implement this method"); return TradeRecord(); } @@ -309,7 +311,7 @@ public: virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice, double number = MAX_DOUBLE, price_t stoploss = 0.0, price_t goalPrice = 0.0, price_t planPrice = 0.0, - SystemPart from = PART_INVALID) { + SystemPart from = PART_INVALID) override { HKU_WARN("The subclass does not implement this method"); return TradeRecord(); } @@ -320,7 +322,7 @@ public: * @param cash 借入的现金 * @return true | false */ - virtual bool borrowCash(const Datetime& datetime, price_t cash) { + virtual bool borrowCash(const Datetime& datetime, price_t cash) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -331,7 +333,7 @@ public: * @param cash 归还现金 * @return true | false */ - virtual bool returnCash(const Datetime& datetime, price_t cash) { + virtual bool returnCash(const Datetime& datetime, price_t cash) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -345,7 +347,7 @@ public: * @return true | false */ virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -359,7 +361,7 @@ public: * @return true | false */ virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -387,7 +389,7 @@ public: * @param tr 待加入的交易记录 * @return bool true 成功 | false 失败 */ - virtual bool addTradeRecord(const TradeRecord& tr) { + virtual bool addTradeRecord(const TradeRecord& tr) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -398,7 +400,7 @@ public: * @return true 成功 * @return false 失败 */ - virtual bool addPosition(const PositionRecord& pr) { + virtual bool addPosition(const PositionRecord& pr) override { HKU_WARN("The subclass does not implement this method"); return false; } @@ -410,7 +412,7 @@ public: * 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线 * @param path 输出文件所在目录 */ - virtual void tocsv(const string& path) { + virtual void tocsv(const string& path) override { HKU_WARN("The subclass does not implement this method"); } diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h index 7414278d..f201c5e8 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h @@ -197,7 +197,7 @@ public: * @param ktype K线类型,必须与日期列表匹配,默认KQuery::DAY * @return 日资产记录列表 */ - FundsList getFundsList(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) { + FundsList getFundsList(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) { size_t total = dates.size(); FundsList result(total); HKU_IF_RETURN(total == 0, result); @@ -213,7 +213,7 @@ public: * @param ktype K线类型,必须与日期列表匹配,默认KQuery::DAY * @return 资产净值列表 */ - PriceList getFundsCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) { + PriceList getFundsCurve(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) { FundsList funds_list = getFundsList(dates, ktype); PriceList ret(funds_list.size()); int precision = getParam("precision"); @@ -229,7 +229,7 @@ public: * @param ktype K线类型,必须与日期列表匹配,默认为KQuery::DAY * @return 收益曲线 */ - PriceList getProfitCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) { + PriceList getProfitCurve(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) { FundsList funds_list = getFundsList(dates, ktype); PriceList ret(funds_list.size()); int precision = getParam("precision"); @@ -246,7 +246,7 @@ public: * @return 收益率曲线 */ PriceList getProfitCumChangeCurve(const DatetimeList& dates, - KQuery::KType ktype = KQuery::DAY) { + const KQuery::KType& ktype = KQuery::DAY) { FundsList funds_list = getFundsList(dates, ktype); PriceList ret(funds_list.size()); for (size_t i = 0, total = funds_list.size(); i < total; i++) { @@ -261,7 +261,8 @@ public: * @param ktype K线类型,必须与日期列表匹配,默认为KQuery::DAY * @return 价格曲线 */ - PriceList getBaseAssetsCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) { + PriceList getBaseAssetsCurve(const DatetimeList& dates, + const KQuery::KType& ktype = KQuery::DAY) { FundsList funds_list = getFundsList(dates, ktype); PriceList ret(funds_list.size()); for (size_t i = 0, total = funds_list.size(); i < total; i++) { diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h b/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h index a7d6c095..fc0af676 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h @@ -180,10 +180,10 @@ typedef shared_ptr CNPtr; #define CONDITION_IMP(classname) \ public: \ - virtual ConditionPtr _clone() { \ + virtual ConditionPtr _clone() override { \ return std::make_shared(); \ } \ - virtual void _calculate(); + virtual void _calculate() override; HKU_API std::ostream& operator<<(std::ostream&, const ConditionPtr&); HKU_API std::ostream& operator<<(std::ostream&, const ConditionBase&); diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/EnvironmentBase.h b/hikyuu_cpp/hikyuu/trade_sys/environment/EnvironmentBase.h index b55a32ee..e74c08d6 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/environment/EnvironmentBase.h +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/EnvironmentBase.h @@ -151,12 +151,12 @@ private: \ typedef shared_ptr EnvironmentPtr; typedef shared_ptr EVPtr; -#define ENVIRONMENT_IMP(classname) \ -public: \ - virtual EnvironmentPtr _clone() { \ - return std::make_shared(); \ - } \ - virtual void _calculate(); +#define ENVIRONMENT_IMP(classname) \ +public: \ + virtual EnvironmentPtr _clone() override { \ + return std::make_shared(); \ + } \ + virtual void _calculate() override; /** * 输出Environment信息,如:Environment(name, params[...]) diff --git a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp index c4ed5311..8829ca6d 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp @@ -122,7 +122,7 @@ void Portfolio::_readyForRun() { #pragma GCC diagnostic ignored "-Wunused-variable" #endif try { - OptimalSelectorBase* _ = dynamic_cast(m_se.get()); + OptimalSelectorBase const* _ = dynamic_cast(m_se.get()); HKU_THROW("Can't use is OptimalSelectorBase type m_se in PF!"); } catch (...) { // do nothing diff --git a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp index 9f67f141..208b1922 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp @@ -52,7 +52,7 @@ WalkForwardSystem::WalkForwardSystem(const SystemList& candidate_sys_list, const #pragma GCC diagnostic ignored "-Wunused-variable" #endif try { - OptimalSelectorBase* _ = dynamic_cast(se.get()); + OptimalSelectorBase const* _ = dynamic_cast(se.get()); } catch (...) { CLS_THROW("Only the OptimalSelectorBase type is accepted!"); } @@ -192,7 +192,7 @@ void WalkForwardSystem::run(const KData& kdata, bool reset, bool resetAll) { readyForRun(); OptimalSelectorBase* se_ptr = dynamic_cast(m_se.get()); - const auto& m_run_ranges = se_ptr->getRunRanges(); + m_run_ranges = se_ptr->getRunRanges(); size_t run_ranges_len = m_run_ranges.size(); HKU_IF_RETURN(run_ranges_len == 0, void()); @@ -200,8 +200,6 @@ void WalkForwardSystem::run(const KData& kdata, bool reset, bool resetAll) { const Stock& stock = kdata.getStock(); for (size_t i = 0; i < run_ranges_len; i++) { - KQuery range_query = KQueryByDate(m_run_ranges[i].run_start, m_run_ranges[i].end, - query.kType(), query.recoverType()); m_train_kdata_list.emplace_back(stock.getKData(KQueryByDate( m_run_ranges[i].start, m_run_ranges[i].end, query.kType(), query.recoverType()))); } @@ -267,7 +265,7 @@ TradeRecord WalkForwardSystem::runMoment(const Datetime& datetime) { auto sw_list = m_se->getSelected(datetime); HKU_IF_RETURN(sw_list.empty(), ret); - auto& sys = sw_list.front().sys; + const auto& sys = sw_list.front().sys; if (sys && sys != m_cur_sys) { m_cur_kdata++; if (m_cur_kdata < m_train_kdata_list.size()) { diff --git a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h index c06c7156..8f69bb56 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +++ b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h @@ -26,11 +26,11 @@ public: virtual ~WalkForwardTradeManager() {} - virtual void _reset() { + virtual void _reset() override { m_tm->_reset(); } - virtual shared_ptr _clone() { + virtual shared_ptr _clone() override { WalkForwardTradeManager* p = new WalkForwardTradeManager(); p->m_tm = m_tm->clone(); p->m_run_start = m_run_start; @@ -42,7 +42,7 @@ public: * @note 必须按时间顺序调用 * @param datetime 当前时刻 */ - virtual void updateWithWeight(const Datetime& datetime) { + virtual void updateWithWeight(const Datetime& datetime) override { m_tm->updateWithWeight(datetime); } @@ -51,27 +51,27 @@ public: * @param datetime 日期 * @param stock 指定对象 */ - virtual double getMarginRate(const Datetime& datetime, const Stock& stock) { + virtual double getMarginRate(const Datetime& datetime, const Stock& stock) override { return (datetime >= m_run_start) ? m_tm->getMarginRate(datetime, stock) : 0.0; } /** 初始资金 */ - virtual price_t initCash() const { + virtual price_t initCash() const override { return m_tm->initCash(); } /** 账户建立日期 */ - virtual Datetime initDatetime() const { + virtual Datetime initDatetime() const override { return m_tm->initDatetime(); } /** 第一笔买入交易发生日期,如未发生交易返回Null() */ - virtual Datetime firstDatetime() const { + virtual Datetime firstDatetime() const override { return m_tm->firstDatetime(); } /** 最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期 */ - virtual Datetime lastDatetime() const { + virtual Datetime lastDatetime() const override { return m_tm->lastDatetime(); } @@ -79,7 +79,7 @@ public: * 返回当前现金 * @note 仅返回当前信息,不会根据权息进行调整 */ - virtual price_t currentCash() const { + virtual price_t currentCash() const override { return m_tm->currentCash(); } @@ -87,7 +87,7 @@ public: * 获取指定日期的现金 * @note 如果不带日期参数,无法根据权息信息调整持仓 */ - virtual price_t cash(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) { + virtual price_t cash(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) override { return m_tm->cash(datetime, ktype); } @@ -97,7 +97,7 @@ public: * @param stock 指定证券 * @return true 是 | false 否 */ - virtual bool have(const Stock& stock) const { + virtual bool have(const Stock& stock) const override { return m_tm->have(stock); } @@ -107,42 +107,42 @@ public: * @param stock 指定证券 * @return true 是 | false 否 */ - virtual bool haveShort(const Stock& stock) const { + virtual bool haveShort(const Stock& stock) const override { return m_tm->haveShort(stock); } /** 当前持有的证券种类数量 */ - virtual size_t getStockNumber() const { + virtual size_t getStockNumber() const override { return m_tm->getStockNumber(); } /** 当前空头持有的证券种类数量 */ - virtual size_t getShortStockNumber() const { + virtual size_t getShortStockNumber() const override { return m_tm->getShortStockNumber(); } /** 获取指定时刻的某证券持有数量 */ - virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) { + virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) override { return m_tm->getHoldNumber(datetime, stock); } /** 获取指定时刻的空头某证券持有数量 */ - virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) { + virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) override { return m_tm->getShortHoldNumber(datetime, stock); } /** 获取指定时刻已借入的股票数量 */ - virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) { + virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) override { return m_tm->getDebtNumber(datetime, stock); } /** 获取指定时刻已借入的现金额 */ - virtual price_t getDebtCash(const Datetime& datetime) { + virtual price_t getDebtCash(const Datetime& datetime) override { return m_tm->getDebtCash(datetime); } /** 获取全部交易记录 */ - virtual TradeRecordList getTradeList() const { + virtual TradeRecordList getTradeList() const override { return m_tm->getTradeList(); } @@ -152,27 +152,28 @@ public: * @param end 结束日期 * @return 交易记录列表 */ - virtual TradeRecordList getTradeList(const Datetime& start, const Datetime& end) const { + virtual TradeRecordList getTradeList(const Datetime& start, + const Datetime& end) const override { return m_tm->getTradeList(start, end); } /** 获取当前全部持仓记录 */ - virtual PositionRecordList getPositionList() const { + virtual PositionRecordList getPositionList() const override { return m_tm->getPositionList(); } /** 获取全部历史持仓记录,即已平仓记录 */ - virtual PositionRecordList getHistoryPositionList() const { + virtual PositionRecordList getHistoryPositionList() const override { return m_tm->getHistoryPositionList(); } /** 获取当前全部空头仓位记录 */ - virtual PositionRecordList getShortPositionList() const { + virtual PositionRecordList getShortPositionList() const override { return m_tm->getShortPositionList(); } /** 获取全部空头历史仓位记录 */ - virtual PositionRecordList getShortHistoryPositionList() const { + virtual PositionRecordList getShortHistoryPositionList() const override { return m_tm->getShortHistoryPositionList(); } @@ -181,7 +182,7 @@ public: * @param date 指定日期 * @param stock 指定的证券 */ - virtual PositionRecord getPosition(const Datetime& date, const Stock& stock) { + virtual PositionRecord getPosition(const Datetime& date, const Stock& stock) override { return m_tm->getPosition(date, stock); } @@ -189,12 +190,12 @@ public: * 获取指定证券的空头持仓记录 * @param stock 指定的证券 */ - virtual PositionRecord getShortPosition(const Stock& stock) const { + virtual PositionRecord getShortPosition(const Stock& stock) const override { return m_tm->getShortPosition(stock); } /** 获取当前借入的股票列表 */ - virtual BorrowRecordList getBorrowStockList() const { + virtual BorrowRecordList getBorrowStockList() const override { return m_tm->getBorrowStockList(); } @@ -204,7 +205,7 @@ public: * @param cash 存入的资金量 * @return true | false */ - virtual bool checkin(const Datetime& datetime, price_t cash) { + virtual bool checkin(const Datetime& datetime, price_t cash) override { return (datetime >= m_run_start) ? m_tm->checkin(datetime, cash) : false; } @@ -214,7 +215,7 @@ public: * @param cash 取出的资金量 * @return true | false */ - virtual bool checkout(const Datetime& datetime, price_t cash) { + virtual bool checkout(const Datetime& datetime, price_t cash) override { return (datetime >= m_run_start) ? m_tm->checkout(datetime, cash) : false; } @@ -227,7 +228,7 @@ public: * @return true | false */ virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { return (datetime >= m_run_start) ? m_tm->checkinStock(datetime, stock, price, number) : false; } @@ -242,7 +243,7 @@ public: * @note 应该不会被用到 */ virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { return (datetime >= m_run_start) ? m_tm->checkoutStock(datetime, stock, price, number) : false; } @@ -261,7 +262,7 @@ public: */ virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice, double number, price_t stoploss = 0.0, price_t goalPrice = 0.0, - price_t planPrice = 0.0, SystemPart from = PART_INVALID) { + price_t planPrice = 0.0, SystemPart from = PART_INVALID) override { return (datetime >= m_run_start) ? m_tm->buy(datetime, stock, realPrice, number, stoploss, goalPrice, planPrice, from) : TradeRecord(); @@ -282,7 +283,7 @@ public: virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice, double number = MAX_DOUBLE, price_t stoploss = 0.0, price_t goalPrice = 0.0, price_t planPrice = 0.0, - SystemPart from = PART_INVALID) { + SystemPart from = PART_INVALID) override { return (datetime >= m_run_start) ? m_tm->sell(datetime, stock, realPrice, number, stoploss, goalPrice, planPrice, from) : TradeRecord(); @@ -302,7 +303,8 @@ public: */ virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice, double number, price_t stoploss = 0.0, price_t goalPrice = 0.0, - price_t planPrice = 0.0, SystemPart from = PART_INVALID) { + price_t planPrice = 0.0, + SystemPart from = PART_INVALID) override { return (datetime >= m_run_start) ? m_tm->sellShort(datetime, stock, realPrice, number, stoploss, goalPrice, planPrice, from) : TradeRecord(); @@ -323,7 +325,7 @@ public: virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice, double number = MAX_DOUBLE, price_t stoploss = 0.0, price_t goalPrice = 0.0, price_t planPrice = 0.0, - SystemPart from = PART_INVALID) { + SystemPart from = PART_INVALID) override { return (datetime >= m_run_start) ? m_tm->buyShort(datetime, stock, realPrice, number, stoploss, goalPrice, planPrice, from) : TradeRecord(); @@ -335,7 +337,7 @@ public: * @param cash 借入的现金 * @return true | false */ - virtual bool borrowCash(const Datetime& datetime, price_t cash) { + virtual bool borrowCash(const Datetime& datetime, price_t cash) override { return (datetime >= m_run_start) ? m_tm->borrowCash(datetime, cash) : false; } @@ -345,7 +347,7 @@ public: * @param cash 归还现金 * @return true | false */ - virtual bool returnCash(const Datetime& datetime, price_t cash) { + virtual bool returnCash(const Datetime& datetime, price_t cash) override { return (datetime >= m_run_start) ? m_tm->returnCash(datetime, cash) : false; } @@ -358,7 +360,7 @@ public: * @return true | false */ virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { return (datetime >= m_run_start) ? m_tm->borrowStock(datetime, stock, price, number) : false; } @@ -372,7 +374,7 @@ public: * @return true | false */ virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price, - double number) { + double number) override { return (datetime >= m_run_start) ? m_tm->returnStock(datetime, stock, price, number) : false; } @@ -382,7 +384,7 @@ public: * @param ktype 日期的类型 * @return 资产详情 */ - virtual FundsRecord getFunds(KQuery::KType ktype = KQuery::DAY) const { + virtual FundsRecord getFunds(KQuery::KType ktype = KQuery::DAY) const override { return m_tm->getFunds(ktype); } @@ -393,7 +395,8 @@ public: * @return 资产详情 * @note 当datetime等于Null()时,与getFunds(KType)同 */ - virtual FundsRecord getFunds(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) { + virtual FundsRecord getFunds(const Datetime& datetime, + KQuery::KType ktype = KQuery::DAY) override { return m_tm->getFunds(datetime, ktype); } @@ -403,7 +406,7 @@ public: * @param tr 待加入的交易记录 * @return bool true 成功 | false 失败 */ - virtual bool addTradeRecord(const TradeRecord& tr) { + virtual bool addTradeRecord(const TradeRecord& tr) override { return (tr.datetime >= m_run_start) ? m_tm->addTradeRecord(tr) : false; } @@ -413,12 +416,12 @@ public: * @return true 成功 * @return false 失败 */ - virtual bool addPosition(const PositionRecord& pr) { + virtual bool addPosition(const PositionRecord& pr) override { return m_tm->addPosition(pr); } /** 字符串输出 */ - virtual string str() const { + virtual string str() const override { return m_tm->str(); } @@ -426,7 +429,7 @@ public: * 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线 * @param path 输出文件所在目录 */ - virtual void tocsv(const string& path) { + virtual void tocsv(const string& path) override { m_tm->tocsv(path); } @@ -434,7 +437,7 @@ public: * 从订单代理实例同步当前账户资产信息(包含资金、持仓等) * @param broker 订单代理实例 */ - virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) { + virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) override { m_tm->fetchAssetInfoFromBroker(broker); }