Merge pull request #204 from fasiondog/feature/param

清理 checkcpp 信息
This commit is contained in:
fasiondog 2024-03-26 02:59:11 +08:00 committed by GitHub
commit 3e805e7fa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 36 additions and 49 deletions

View File

@ -69,6 +69,17 @@ except Exception as e:
issue "用户目录/.hikyuu" hikyuu_py.log hikyuu.log """)
raise e
__version__ = get_version()
sm = StockManager.instance()
# 如果是在 jupyter 环境中运行重定向C++ stdout/stderr输出至python
if in_ipython_frontend():
sm.python_in_jupyter = True
hku_info("hikyuu version: {}", get_version_with_build())
iodog = OstreamRedirect()
iodog.open()
# ==============================================================================
#
@ -84,7 +95,3 @@ V = VOL()
D = Datetime
K = None
Q = Query
sm = StockManager.instance()
__version__ = get_version()

View File

@ -58,14 +58,6 @@ import configparser
from hikyuu.data.hku_config_template import generate_default_config
from hikyuu import *
# 如果是在 jupyter 环境中运行重定向C++ stdout/stderr输出至python
if in_ipython_frontend():
sm.python_in_jupyter = True
hku_info("hikyuu version: {}", get_version_with_build())
iodog = OstreamRedirect()
iodog.open()
# ==============================================================================
# 引入扯线木偶
# ==============================================================================

View File

@ -63,6 +63,7 @@ std::shared_ptr<spdlog::logger> getHikyuuLogger() {
#if HKU_USE_SPDLOG_ASYNC_LOGGER
void initLogger(bool inJupyter) {
std::string logname = "hikyuu";
spdlog::drop(logname);
std::shared_ptr<spdlog::logger> logger = spdlog::get(logname);
if (logger) {
spdlog::drop(logname);
@ -91,6 +92,7 @@ void initLogger(bool inJupyter) {
void initLogger(bool inJupyter) {
std::string logname = "hikyuu";
spdlog::drop(logname);
std::shared_ptr<spdlog::logger> logger = spdlog::get(logname);
if (logger) {
spdlog::drop(logname);

View File

@ -13,8 +13,8 @@ namespace hku {
struct ZhBond10Table {
TABLE_BIND2(ZhBond10Table, zh_bond10, date, value)
int64_t date;
int64_t value;
int64_t date{0};
int64_t value{0};
};
} // namespace hku

View File

@ -1514,8 +1514,8 @@ bool IndicatorImp::alike(const IndicatorImp &other) const {
m_ind_params.size() != other.m_ind_params.size() || m_params != other.m_params,
false);
auto &self_id = typeid(*this);
auto &cval_id = typeid(ICval);
const auto &self_id = typeid(*this);
const auto &cval_id = typeid(ICval);
if (self_id == cval_id) {
HKU_IF_RETURN(isLeaf() && other.isLeaf(), true);
return m_right && m_right->alike(*other.m_right);

View File

@ -131,7 +131,7 @@ void IAlign::_calculate(const Indicator& ind) {
for (size_t r = 0; r < m_result_num; r++) {
_set(ind.get(j, r), i, r);
}
} else if (!fill_null && j < ind_total) {
} else if (!fill_null) {
for (size_t r = 0; r < m_result_num; r++) {
_set(ind.get(j - 1, r), i, r);
}

View File

@ -57,7 +57,7 @@ void IAma::_calculate(const Indicator& data) {
price_t slowest = 2.0 / (slow_n + 1);
price_t delta = fastest - slowest;
price_t prevol = 0.0, vol = 0.0, er = 1.0, c = 0.0;
price_t prevol = 0.0, vol = 0.0, er = 1.0;
price_t ama = src[start];
size_t first_end = start + n + 1 >= total ? total : start + n + 1;
_set(ama, start, 0);
@ -67,7 +67,7 @@ void IAma::_calculate(const Indicator& data) {
er = (vol == 0.0) ? 1.0 : (src[i] - src[start]) / vol;
if (er > 1.0)
er = 1.0;
c = std::pow((std::fabs(er) * delta + slowest), 2);
price_t c = std::pow((std::fabs(er) * delta + slowest), 2);
ama += c * (src[i] - ama);
dst0[i] = ama;
dst1[i] = er;
@ -81,7 +81,7 @@ void IAma::_calculate(const Indicator& data) {
er = 1.0;
if (er < -1.0)
er = -1.0;
c = std::pow((std::fabs(er) * delta + slowest), 2);
price_t c = std::pow((std::fabs(er) * delta + slowest), 2);
ama += c * (src[i] - ama);
prevol = vol;
dst0[i] = ama;

View File

@ -14,7 +14,7 @@ namespace hku {
class ICorr : public IndicatorImp {
public:
ICorr();
ICorr(int n);
explicit ICorr(int n);
ICorr(const Indicator& ref_ind, int n);
virtual ~ICorr();

View File

@ -17,7 +17,7 @@ class IRecover : public IndicatorImp {
public:
IRecover();
IRecover(int recoverType);
explicit IRecover(int recoverType);
IRecover(const KData&, int recoverType);
virtual ~IRecover();

View File

@ -14,7 +14,7 @@ namespace hku {
class ISpearman : public IndicatorImp {
public:
ISpearman();
ISpearman(int n);
explicit ISpearman(int n);
ISpearman(const Indicator& ref_ind, int n);
virtual ~ISpearman();

View File

@ -84,7 +84,7 @@ void IStdev::_calculate(const Indicator& data) {
price_t d_pow = std::pow(d, 2);
pow_buf[i] = d_pow;
ex2 += d_pow;
size_t num = i - j;
num = i - j;
if (num != 1) {
dst[i] = std::sqrt((ex2 - std::pow(ex, 2) / num) / (num - 1));
}

View File

@ -23,7 +23,7 @@ class IZhBond10 : public IndicatorImp {
public:
IZhBond10();
IZhBond10(const DatetimeList& dates, double default_val = 4.0);
explicit IZhBond10(const DatetimeList& dates, double default_val = 4.0);
virtual ~IZhBond10();
};

View File

@ -432,14 +432,6 @@ void Performance ::statistics(const TradeManagerPtr& tm, const Datetime& datetim
continue;
}
cur_iter = cur_position.begin();
for (; cur_iter != cur_position.end(); ++cur_iter) {
if (cur_iter->takeDatetime <= *day_iter) {
hold = false;
break;
}
}
// 当前是空仓
total_short_days++;
if (pre_short) {

View File

@ -1187,12 +1187,11 @@ FundsRecord TradeManager::getFunds(KQuery::KType inktype) const {
string ktype(inktype);
to_upper(ktype);
price_t price(0.0);
price_t value(0.0); // 当前市值
price_t value{0.0}; // 当前市值
position_map_type::const_iterator iter = m_position.begin();
for (; iter != m_position.end(); ++iter) {
const PositionRecord& record = iter->second;
price = record.stock.getMarketValue(lastDatetime(), ktype);
auto price = record.stock.getMarketValue(lastDatetime(), ktype);
value = roundEx((value + record.number * price * record.stock.unit()), precision);
}
@ -1200,7 +1199,7 @@ FundsRecord TradeManager::getFunds(KQuery::KType inktype) const {
iter = m_short_position.begin();
for (; iter != m_short_position.end(); ++iter) {
const PositionRecord& record = iter->second;
price = record.stock.getMarketValue(lastDatetime(), ktype);
auto price = record.stock.getMarketValue(lastDatetime(), ktype);
short_value =
roundEx((short_value + record.number * price * record.stock.unit()), precision);
}

View File

@ -354,7 +354,6 @@ SystemWeightList AllocateFundsBase::_adjust_with_running(
auto tr =
iter->sys->sellForceOnClose(date, need_back_num, PART_ALLOCATEFUNDS);
if (!tr.isNull()) {
auto sub_tm = iter->sys->getTM();
auto sub_cash = sub_tm->currentCash();
if (sub_tm->checkout(date, sub_cash)) {
m_cash_tm->checkin(date, sub_cash);
@ -420,7 +419,6 @@ SystemWeightList AllocateFundsBase::_adjust_with_running(
need_cash = can_allocate_cash;
}
// 如果期望的资金连一手都买不起,则跳过
const KQuery& query = iter->sys->getTO().getQuery();
auto krecord = iter->sys->getStock().getKRecord(date, query.kType());
if (krecord.isValid() &&
need_cash < krecord.closePrice * iter->sys->getStock().minTradeNumber()) {

View File

@ -27,7 +27,7 @@ BoolEnvironment::~BoolEnvironment() {}
void BoolEnvironment::_checkParam(const string& name) const {
if ("market" == name) {
string market = getParam<string>(name);
auto market_info = StockManager::instance().getMarketInfo(name);
auto market_info = StockManager::instance().getMarketInfo(market);
HKU_CHECK(market_info != Null<MarketInfo>(), "Invalid market: {}", market);
}
}

View File

@ -29,7 +29,7 @@ TwoLineEnvironment::~TwoLineEnvironment() {}
void TwoLineEnvironment::_checkParam(const string& name) const {
if ("market" == name) {
string market = getParam<string>(name);
auto market_info = StockManager::instance().getMarketInfo(name);
auto market_info = StockManager::instance().getMarketInfo(market);
HKU_CHECK(market_info != Null<MarketInfo>(), "Invalid market: {}", market);
}
}

View File

@ -265,7 +265,7 @@ Indicator MultiFactorBase::getIC(int ndays) {
return result;
}
Indicator MultiFactorBase::getICIR(int ic_n, int ir_n) {
Indicator MultiFactorBase::getICIR(int ir_n, int ic_n) {
Indicator ic = getIC(ic_n);
Indicator x = MA(ic, ir_n) / STDEV(ic, ir_n);
x.name("ICIR");
@ -306,10 +306,8 @@ vector<IndicatorList> MultiFactorBase::getAllSrcFactors() {
// 每日截面归一化
if (getParam<bool>("enable_min_max_normalize")) {
vector<Indicator::value_t> one_day(stk_count, Null<Indicator::value_t>());
for (size_t di = 0, days_total = m_ref_dates.size(); di < days_total; di++) {
for (size_t ii = 0; ii < ind_count; ii++) {
auto* one_day_data = one_day.data();
Indicator::value_t min_value = std::numeric_limits<Indicator::value_t>::max();
Indicator::value_t max_value = std::numeric_limits<Indicator::value_t>::min();
for (size_t si = 0; si < stk_count; si++) {

View File

@ -16,7 +16,7 @@ struct HKU_API ScoreRecord {
typedef Indicator::value_t value_t;
Stock stock;
value_t value;
value_t value{0.0};
ScoreRecord() = default;
ScoreRecord(const Stock& stock_, value_t value_);

View File

@ -23,7 +23,7 @@ class FixedPercentStoploss : public StoplossBase {
public:
FixedPercentStoploss();
virtual ~FixedPercentStoploss();
virtual void _checkParam(const string& name) const;
virtual void _checkParam(const string& name) const override;
};
} /* namespace hku */

View File

@ -19,8 +19,8 @@ public:
IndicatorStoploss(); // 仅用于序列化默认构造函数
IndicatorStoploss(const Indicator& op, const string& kdata_part);
virtual ~IndicatorStoploss();
virtual void _checkParam(const string& name) const;
virtual void _checkParam(const string& name) const override;
virtual price_t getPrice(const Datetime& datetime, price_t price) override;
virtual void _reset() override;
virtual StoplossPtr _clone() override;

View File

@ -334,8 +334,7 @@ bool System::readyForRun() {
m_pre_cn_valid = false; // 默认的前一日市场有效标志置为false
}
if (m_mm)
m_mm->setTM(m_tm);
m_mm->setTM(m_tm);
if (m_pg)
m_pg->setTM(m_tm);
if (m_st)