Skip to content

Commit

Permalink
clear cppcheck infos
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Sep 24, 2024
1 parent f3a0a29 commit 8101561
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
- name: build
run: |
xmake -bvD core
xmake -b core
4 changes: 2 additions & 2 deletions hikyuu_cpp/hikyuu/analysis/analysis_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ std::pair<double, SYSPtr> 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;
Expand Down
52 changes: 27 additions & 25 deletions hikyuu_cpp/hikyuu/strategy/BrokerTradeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,48 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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();
}
Expand All @@ -146,7 +146,8 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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();
}
Expand All @@ -155,19 +156,19 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
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();
}
Expand All @@ -183,13 +184,13 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* 获取指定证券的空头持仓记录
* @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();
}
Expand Down Expand Up @@ -222,7 +223,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -237,7 +238,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand Down Expand Up @@ -289,7 +290,8 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
*/
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();
}
Expand All @@ -309,7 +311,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
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();
}
Expand All @@ -320,7 +322,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -331,7 +333,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -345,7 +347,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -359,7 +361,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand Down Expand Up @@ -387,7 +389,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -398,7 +400,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* @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;
}
Expand All @@ -410,7 +412,7 @@ class HKU_API BrokerTradeManager : public TradeManagerBase {
* 以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");
}

Expand Down
11 changes: 6 additions & 5 deletions hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class HKU_API TradeManagerBase {
* @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);
Expand All @@ -213,7 +213,7 @@ class HKU_API TradeManagerBase {
* @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<int>("precision");
Expand All @@ -229,7 +229,7 @@ class HKU_API TradeManagerBase {
* @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<int>("precision");
Expand All @@ -246,7 +246,7 @@ class HKU_API TradeManagerBase {
* @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++) {
Expand All @@ -261,7 +261,8 @@ class HKU_API TradeManagerBase {
* @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++) {
Expand Down
4 changes: 2 additions & 2 deletions hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ typedef shared_ptr<ConditionBase> CNPtr;

#define CONDITION_IMP(classname) \
public: \
virtual ConditionPtr _clone() { \
virtual ConditionPtr _clone() override { \
return std::make_shared<classname>(); \
} \
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&);
Expand Down
12 changes: 6 additions & 6 deletions hikyuu_cpp/hikyuu/trade_sys/environment/EnvironmentBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ private: \
typedef shared_ptr<EnvironmentBase> EnvironmentPtr;
typedef shared_ptr<EnvironmentBase> EVPtr;

#define ENVIRONMENT_IMP(classname) \
public: \
virtual EnvironmentPtr _clone() { \
return std::make_shared<classname>(); \
} \
virtual void _calculate();
#define ENVIRONMENT_IMP(classname) \
public: \
virtual EnvironmentPtr _clone() override { \
return std::make_shared<classname>(); \
} \
virtual void _calculate() override;

/**
* 输出Environment信息,如:Environment(name, params[...])
Expand Down
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void Portfolio::_readyForRun() {
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
try {
OptimalSelectorBase* _ = dynamic_cast<OptimalSelectorBase*>(m_se.get());
OptimalSelectorBase const* _ = dynamic_cast<OptimalSelectorBase*>(m_se.get());
HKU_THROW("Can't use is OptimalSelectorBase type m_se in PF!");
} catch (...) {
// do nothing
Expand Down
8 changes: 3 additions & 5 deletions hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ WalkForwardSystem::WalkForwardSystem(const SystemList& candidate_sys_list, const
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
try {
OptimalSelectorBase* _ = dynamic_cast<OptimalSelectorBase*>(se.get());
OptimalSelectorBase const* _ = dynamic_cast<OptimalSelectorBase*>(se.get());
} catch (...) {
CLS_THROW("Only the OptimalSelectorBase type is accepted!");
}
Expand Down Expand Up @@ -192,16 +192,14 @@ void WalkForwardSystem::run(const KData& kdata, bool reset, bool resetAll) {
readyForRun();

OptimalSelectorBase* se_ptr = dynamic_cast<OptimalSelectorBase*>(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());

const KQuery& query = kdata.getQuery();
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())));
}
Expand Down Expand Up @@ -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()) {
Expand Down
Loading

0 comments on commit 8101561

Please sign in to comment.