diff --git a/docs/examples/Turtle_SG.py b/docs/examples/Turtle_SG.py index dba132b437abf7798afa5b151ca102f50bbe8723..ce0c9b0829a374a26c8ba23bb27736fb5616aa28 100644 --- a/docs/examples/Turtle_SG.py +++ b/docs/examples/Turtle_SG.py @@ -7,41 +7,42 @@ # History: 20160407, Added by fasiondog #=============================================================================== -from hikyuu.trade_sys.signal import SignalBase -from hikyuu.indicator import HHV, LLV, CLOSE, REF +from hikyuu import * + class TurtleSignal(SignalBase): - def __init__(self, n = 20): + def __init__(self, n=20): super(TurtleSignal, self).__init__("TurtleSignal") - self.setParam("n", 20) - + self.set_param("n", 20) + def _clone(self): return TurtleSignal() def _calculate(self): - n = self.getParam("n") - k = self.getTO() + n = self.get_param("n") + k = self.to c = CLOSE(k) - h = REF(HHV(c, n), 1) #前n日高点 - L = REF(LLV(c, n), 1) #前n日低点 + h = REF(HHV(c, n), 1) #前n日高点 + L = REF(LLV(c, n), 1) #前n日低点 for i in range(h.discard, len(k)): if (c[i] >= h[i]): - self._addBuySignal(k[i].datetime) + self._add_buy_signal(k[i].datetime) elif (c[i] <= L[i]): - self._addSellSignal(k[i].datetime) + self._add_sell_signal(k[i].datetime) + if __name__ == "__main__": from examples_init import * - + sg = TurtleSignal() - s = getStock("sh000001") - k = s.getKData(Query(-500)) - + s = get_stock("sh000001") + k = s.get_kdata(Query(-500)) + #只有设置交易对象时,才会开始实际计算 - sg.setTO(k) - dates = k.getDatetimeList() + sg.to = k + dates = k.get_datetime_list() for d in dates: - if (sg.shouldBuy(d)): + if (sg.should_buy(d)): print("买入:%s" % d) - elif (sg.shouldSell(d)): + elif (sg.should_sell(d)): print("卖出: %s" % d) diff --git a/docs/examples/examples_init.py b/docs/examples/examples_init.py index 493c6bf7fbb5e1897d145be74c3955cb5cb7b08b..680ebd3008ec2f684f01932ea6ece1bdeacd5015 100644 --- a/docs/examples/examples_init.py +++ b/docs/examples/examples_init.py @@ -9,16 +9,20 @@ from hikyuu import * import os -curdir = os.path.dirname(os.path.realpath(__file__)) -head, tail = os.path.split(curdir) -head, tail = os.path.split(head) -head, tail = os.path.split(head) -import sys -if sys.platform == 'win32': - config_file = os.path.join(head, "test/data/hikyuu_win.ini") -else: - config_file = os.path.join(head, "test/data/hikyuu_linux.ini") +config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini" +if not os.path.exists(config_file): + #检查老版本配置是否存在,如果存在可继续使用,否则异常终止 + data_config_file = os.path.expanduser('~') + "/.hikyuu/data_dir.ini" + data_config = configparser.ConfigParser() + data_config.read(data_config_file) + data_dir = data_config['data_dir']['data_dir'] + if sys.platform == 'win32': + config_file = data_dir + "\\hikyuu_win.ini" + else: + config_file = data_dir + "/hikyuu_linux.ini" + if not os.path.exists(config_file): + raise("未找到配置文件,请先使用数据导入工具导入数据(将自动生成配置文件)!!!") #starttime = time.time() diff --git a/docs/examples/quick_crtsg.py b/docs/examples/quick_crtsg.py index cce9efa77b9593767aabf60a4a9db032d9a1efb9..7bc645bc765cd3648e45cad2023b61f3af2ce0c2 100644 --- a/docs/examples/quick_crtsg.py +++ b/docs/examples/quick_crtsg.py @@ -7,33 +7,34 @@ # History: 20160407, Added by fasiondog #=============================================================================== -from hikyuu.trade_sys.signal import crtSG -from hikyuu.indicator import HHV, LLV, CLOSE, REF +from hikyuu import * + def TurtleSG(self): - n = self.getParam("n") - k = self.getTO() - c = CLOSE(k) - h = REF(HHV(c, n), 1) #前n日高点 - L = REF(LLV(c, n), 1) #前n日低点 - for i in range(h.discard, len(k)): - if (c[i] >= h[i]): - self._addBuySignal(k[i].datetime) - elif (c[i] <= L[i]): - self._addSellSignal(k[i].datetime) + n = self.get_param("n") + k = self.to + c = CLOSE(k) + h = REF(HHV(c, n), 1) #前n日高点 + L = REF(LLV(c, n), 1) #前n日低点 + for i in range(h.discard, len(k)): + if (c[i] >= h[i]): + self._add_buy_signal(k[i].datetime) + elif (c[i] <= L[i]): + self._add_sell_signal(k[i].datetime) + if __name__ == "__main__": from examples_init import * - + sg = crtSG(TurtleSG, {'n': 20}, 'TurtleSG') - s = getStock("sh000001") - k = s.getKData(Query(-500)) - + s = get_stock("sh000001") + k = s.get_kdata(Query(-500)) + #只有设置交易对象时,才会开始实际计算 - sg.setTO(k) - dates = k.getDatetimeList() + sg.to = k + dates = k.get_datetime_list() for d in dates: - if (sg.shouldBuy(d)): + if (sg.should_buy(d)): print("买入:%s" % d) - elif (sg.shouldSell(d)): + elif (sg.should_sell(d)): print("卖出: %s" % d) diff --git a/docs/source/trade_portfolio/selector.rst b/docs/source/trade_portfolio/selector.rst index 23de069c0b5188ba484a340041a76b78973f9334..ef5bcfabbb705de1708be6c0d7835c0b71b7427b 100644 --- a/docs/source/trade_portfolio/selector.rst +++ b/docs/source/trade_portfolio/selector.rst @@ -100,9 +100,9 @@ :param StockList stk_list: 加入的初始标的列表 :param System sys: 系统策略原型 - .. py:method:: clear(self) + .. py:method:: remove_all(self) - 清除已加入的系统策略实例 + 清除所有已加入的原型系统 .. py:method:: is_match_af(self) diff --git a/hikyuu_cpp/hikyuu/KData.h b/hikyuu_cpp/hikyuu/KData.h index 6dff4ad057fc9b1afdc8843f033e6e53a0364094..98c49ce7df00a8be4808760eda24a9a5875177c3 100644 --- a/hikyuu_cpp/hikyuu/KData.h +++ b/hikyuu_cpp/hikyuu/KData.h @@ -23,10 +23,12 @@ class HKU_API KData { public: KData() {} KData(const KData&); + KData(KData&&); KData(const Stock& stock, const KQuery& query); virtual ~KData() {} KData& operator=(const KData&); + KData& operator=(KData&&); size_t size() const; bool empty() const; @@ -149,6 +151,8 @@ KData HKU_API getKData(const string& market_code, int64_t start = 0, int64_t end inline KData::KData(const KData& x) : m_imp(x.m_imp) {} +inline KData::KData(KData&& x) : m_imp(std::move(x.m_imp)) {} + inline KData& KData::operator=(const KData& x) { if (this == &x) return *this; @@ -156,6 +160,13 @@ inline KData& KData::operator=(const KData& x) { return *this; } +inline KData& KData::operator=(KData&& x) { + if (this == &x) + return *this; + m_imp = std::move(x.m_imp); + return *this; +} + inline DatetimeList KData::getDatetimeList() const { DatetimeList result; if (empty()) { diff --git a/hikyuu_cpp/hikyuu/Stock.cpp b/hikyuu_cpp/hikyuu/Stock.cpp index 1254d0e97da5109823f6dfafaa9c443014d6d083..061ff49a7dc4c946dad3a0db108e0c9419ac852a 100644 --- a/hikyuu_cpp/hikyuu/Stock.cpp +++ b/hikyuu_cpp/hikyuu/Stock.cpp @@ -123,6 +123,8 @@ Stock::~Stock() {} Stock::Stock(const Stock& x) : m_data(x.m_data), m_kdataDriver(x.m_kdataDriver) {} +Stock::Stock(Stock&& x) : m_data(std::move(x.m_data)), m_kdataDriver(std::move(x.m_kdataDriver)) {} + Stock& Stock::operator=(const Stock& x) { HKU_IF_RETURN(this == &x, *this); m_data = x.m_data; @@ -130,6 +132,13 @@ Stock& Stock::operator=(const Stock& x) { return *this; } +Stock& Stock::operator=(Stock&& x) { + HKU_IF_RETURN(this == &x, *this); + m_data = std::move(x.m_data); + m_kdataDriver = std::move(x.m_kdataDriver); + return *this; +} + Stock::Stock(const string& market, const string& code, const string& name) { m_data = shared_ptr(new Data(market, code, name, default_type, default_valid, default_startDate, diff --git a/hikyuu_cpp/hikyuu/Stock.h b/hikyuu_cpp/hikyuu/Stock.h index c25d5dfd3d3c5b086ba703a7815f2bd6b8775b6f..b49e447b67fdb0342ae3711f19240b0008cb23cf 100644 --- a/hikyuu_cpp/hikyuu/Stock.h +++ b/hikyuu_cpp/hikyuu/Stock.h @@ -55,6 +55,7 @@ public: Stock(); Stock(const Stock&); + Stock(Stock&&); Stock(const string& market, const string& code, const string& name); Stock(const string& market, const string& code, const string& name, uint32_t type, bool valid, @@ -64,6 +65,7 @@ public: int precision, size_t minTradeNumber, size_t maxTradeNumber); virtual ~Stock(); Stock& operator=(const Stock&); + Stock& operator=(Stock&&); bool operator==(const Stock&) const; bool operator!=(const Stock&) const; diff --git a/hikyuu_cpp/hikyuu/data_driver/DriverConnectPool.h b/hikyuu_cpp/hikyuu/data_driver/DriverConnectPool.h index 3dc362a6834909b61d4e40378bd2d7236b8dd990..34002e01f5244182d7058e7a458c32674006a9e2 100644 --- a/hikyuu_cpp/hikyuu/data_driver/DriverConnectPool.h +++ b/hikyuu_cpp/hikyuu/data_driver/DriverConnectPool.h @@ -32,7 +32,7 @@ public: /** * 构造函数 - * @param param 驱动原型,所有权将被转移至该 pool + * @param prototype 驱动原型,所有权将被转移至该 pool * @param maxConnect 允许的最大连接数,为 0 表示不限制 * @param maxIdleConnect 运行的最大空闲连接数,等于 0 时表示立刻释放,默认为CPU数 */ diff --git a/hikyuu_cpp/hikyuu/hikyuu.h b/hikyuu_cpp/hikyuu/hikyuu.h index 2748e8193d07cd49fc8e44b6b9863a528f1fd21d..e4cedcd8ca543a690dc9bf10e0151c596a284cf6 100644 --- a/hikyuu_cpp/hikyuu/hikyuu.h +++ b/hikyuu_cpp/hikyuu/hikyuu.h @@ -27,6 +27,7 @@ namespace hku { * @param config_file_name 配置信息文件名 * @param ignore_preload 忽略配置信息中的预加载设置,即不加载数据至内存。 * 用于某些场合启动hikyuu,但仅用于获取数据库的基本信息。 + * @param context 指定加载数据上下文,用于独立策略时仅加载指定的股票数据 */ void HKU_API hikyuu_init(const string& config_file_name, bool ignore_preload = false, const StrategyContext& context = StrategyContext({"all"})); diff --git a/hikyuu_cpp/hikyuu/indicator/Indicator.cpp b/hikyuu_cpp/hikyuu/indicator/Indicator.cpp index 711088c8b18f6bf446dc36bc608b149c299f38b7..7ebb342632a36f5f72d78261570f5dec35ff97f6 100644 --- a/hikyuu_cpp/hikyuu/indicator/Indicator.cpp +++ b/hikyuu_cpp/hikyuu/indicator/Indicator.cpp @@ -19,6 +19,8 @@ Indicator::Indicator(const IndicatorImpPtr& imp) : m_imp(imp) {} Indicator::Indicator(const Indicator& indicator) : m_imp(indicator.m_imp) {} +Indicator::Indicator(Indicator&& ind) : m_imp(std::move(ind.m_imp)) {} + Indicator::~Indicator() {} string Indicator::formula() const { @@ -51,6 +53,12 @@ Indicator& Indicator::operator=(const Indicator& indicator) { return *this; } +Indicator& Indicator::operator=(Indicator&& indicator) { + HKU_IF_RETURN(this == &indicator, *this); + m_imp = std::move(indicator.m_imp); + return *this; +} + PriceList Indicator::getResultAsPriceList(size_t num) const { HKU_WARN_IF_RETURN(!m_imp, PriceList(), "indicator imptr is null!"); return m_imp->getResultAsPriceList(num); diff --git a/hikyuu_cpp/hikyuu/indicator/Indicator.h b/hikyuu_cpp/hikyuu/indicator/Indicator.h index 106f3fdc99e2faf2c3027a7e56215c70a2fabc73..f245b52466d78c36da7152ef6f85948ef376cf1e 100644 --- a/hikyuu_cpp/hikyuu/indicator/Indicator.h +++ b/hikyuu_cpp/hikyuu/indicator/Indicator.h @@ -43,10 +43,12 @@ class HKU_API Indicator { public: Indicator() {} Indicator(const IndicatorImpPtr& imp); - Indicator(const Indicator&); + Indicator(const Indicator& ind); + Indicator(Indicator&& ind); virtual ~Indicator(); Indicator& operator=(const Indicator&); + Indicator& operator=(Indicator&&); /** 使用已有参数计算新值,返回全新的Indicator */ Indicator operator()(const Indicator& ind); diff --git a/hikyuu_cpp/hikyuu/indicator/crt/MA.h b/hikyuu_cpp/hikyuu/indicator/crt/MA.h index b58255c8c228fb9683922a2b357266efb77f82d7..eab2003ab364855bfe37b2e04ebd1fde6b933bad 100644 --- a/hikyuu_cpp/hikyuu/indicator/crt/MA.h +++ b/hikyuu_cpp/hikyuu/indicator/crt/MA.h @@ -15,13 +15,18 @@ namespace hku { /** * 简单移动平均 - * @param data 待计算的数据 * @param n 计算均值的周期窗口,n为0时从第一个有效数据开始计算 * @ingroup Indicator */ Indicator HKU_API MA(int n = 22); Indicator HKU_API MA(const IndParam& n); +/** + * 简单移动平均 + * @param ind 待计算的数据 + * @param n 计算均值的周期窗口,n为0时从第一个有效数据开始计算 + * @ingroup Indicator + */ inline Indicator HKU_API MA(const Indicator& ind, int n = 22) { return MA(n)(ind); } diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp index fbadb43b04775b33a37d11ce7cae59cb2de4a772..0aff71775c9ca1ede6913a41dcc53d7a58648c56 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp @@ -362,8 +362,8 @@ PositionRecord TradeManager::getPosition(const Datetime& datetime, const Stock& //如果指定的日期大于等于最后交易日期,则直接取当前持仓记录 if (datetime >= lastDatetime()) { - position_map_type::const_iterator pos_iter = m_short_position.find(stock.id()); - if (pos_iter != m_short_position.end()) { + position_map_type::const_iterator pos_iter = m_position.find(stock.id()); + if (pos_iter != m_position.end()) { result = pos_iter->second; } return result; diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h index a49844a4a7dd62a9d7cb28d0d4ff91facd81ec50..18e466dce5c3f5ad716a561b622cccc35cb88f51 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h @@ -362,7 +362,7 @@ public: * @param date 指定日期 * @param stock 指定的证券 */ - virtual PositionRecord getPosition(const Datetime& date, const Stock&) { + virtual PositionRecord getPosition(const Datetime& date, const Stock& stock) { HKU_WARN("The subclass does not implement this method"); return PositionRecord(); } diff --git a/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.cpp b/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.cpp index 37ecc4656b324bb719de4b627dc356de93c1c3f4..bf10e61530d3302c831868e1008ea8e518d48014 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.cpp @@ -37,9 +37,9 @@ SelectorBase::SelectorBase(const string& name) : m_name(name) { SelectorBase::~SelectorBase() {} -void SelectorBase::clear() { - m_pro_sys_list.clear(); - m_real_sys_list.clear(); +void SelectorBase::removeAll() { + m_pro_sys_list = SystemList(); + m_real_sys_list = SystemList(); } void SelectorBase::reset() { diff --git a/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.h b/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.h index 0a5b0a8a747d3823a5c309adea517bba587d402f..c20102ea13bf16be60a6ad80c6cc10117b84e53f 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.h +++ b/hikyuu_cpp/hikyuu/trade_sys/selector/SelectorBase.h @@ -88,7 +88,7 @@ public: /** * 清除已有的系统原型 */ - void clear(); + void removeAll(); typedef shared_ptr SelectorPtr; SelectorPtr clone(); diff --git a/hikyuu_cpp/hikyuu/utilities/Null.h b/hikyuu_cpp/hikyuu/utilities/Null.h index fb823659ab0d6119aa316711ae96a7004250d8b1..a37c772c025a86979544e80072c08e03e1e21072 100644 --- a/hikyuu_cpp/hikyuu/utilities/Null.h +++ b/hikyuu_cpp/hikyuu/utilities/Null.h @@ -104,7 +104,7 @@ template <> class Null { public: Null() {} - operator unsigned long long() { + operator size_t() { return (std::numeric_limits::max)(); } }; diff --git a/hikyuu_cpp/hikyuu/utilities/TimerManager.h b/hikyuu_cpp/hikyuu/utilities/TimerManager.h index 08fcbce7d82098f6110164aa486d62b07c4534c2..3d75126900ad5105cb2922d9ae1164d9be326d35 100644 --- a/hikyuu_cpp/hikyuu/utilities/TimerManager.h +++ b/hikyuu_cpp/hikyuu/utilities/TimerManager.h @@ -159,7 +159,7 @@ public: * @param start_time 允许运行的起始时间 * @param end_time 允许运行的结束时间 * @param repeat_num 重复次数,必须大于0,等于std::numeric_limits::max()时表示无限循环 - * @param delay 间隔时间,需大于 TimeDelta(0) + * @param duration 间隔时间,需大于 TimeDelta(0) * @param f 待执行的延迟任务 * @param args 任务具体参数 * @return timer id @@ -189,7 +189,7 @@ public: * @tparam F 任务类型 * @tparam Args 任务参数 * @param repeat_num 重复次数,必须大于0,等于std::numeric_limits::max()时表示无限循环 - * @param delay 间隔时间,需大于 TimeDelta(0) + * @param duration 间隔时间,需大于 TimeDelta(0) * @param f 待执行的延迟任务 * @param args 任务具体参数 * @return timer id @@ -224,6 +224,8 @@ public: * @tparam F 任务类型 * @tparam Args 任务参数 * @param time_point 指定的运行时刻(包含具体的日、时、分、秒...) + * @param f 待执行的延迟任务 + * @param args 任务具体参数 * @return timer id */ template @@ -243,6 +245,8 @@ public: * @param start_date 允许执行的开始日期 * @param end_date 允许执行的结束日期 * @param time 指定运行的日内时刻 + * @param f 待执行的延迟任务 + * @param args 任务具体参数 * @return timer id */ template @@ -265,6 +269,8 @@ public: * @tparam F 任务类型 * @tparam Args 任务参数 * @param time 指定运行的日内时刻 + * @param f 待执行的延迟任务 + * @param args 任务具体参数 * @return timer id */ template diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h b/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h index abf655dc6e1c5fc18276be9aeb349f72f5fc59cf..42d0bb86c5d8e32c9e2727521698c7639b3272fb 100644 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h @@ -190,7 +190,7 @@ public: /** * 从指定表中删除符合条件的数据指定条件删除 * @param tablename 待删除数据的表名 - * @param where 删除条件 + * @param cond 删除条件 * @param autotrans 启动事务 */ void remove(const std::string& tablename, const DBCondition& cond, bool autotrans = true); diff --git a/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h b/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h index 4930e73d6e3dd519edc3eed6f425d8a180a1aaea..4238f269f3406931b7f22a94a9795af6759a13e8 100644 --- a/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h +++ b/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h @@ -35,6 +35,7 @@ public: /** * 构造函数,创建指定数量的线程 * @param n 指定的线程数 + * @param util_empty join时指示各工作线程在未获取到工作任务时,停止运行 */ explicit MQStealThreadPool(size_t n, bool util_empty = true) : m_done(false), m_worker_num(n), m_runnging_util_empty(util_empty) { diff --git a/hikyuu_cpp/hikyuu/utilities/thread/MQThreadPool.h b/hikyuu_cpp/hikyuu/utilities/thread/MQThreadPool.h index b0c2f33ee2e35fddf8affb5df3fe7b54a23261d9..a63fd8d618275084289b68c217d006bd0740694d 100644 --- a/hikyuu_cpp/hikyuu/utilities/thread/MQThreadPool.h +++ b/hikyuu_cpp/hikyuu/utilities/thread/MQThreadPool.h @@ -35,6 +35,7 @@ public: /** * 构造函数,创建指定数量的线程 * @param n 指定的线程数 + * @param util_empty join时指示各工作线程在未获取到工作任务时,停止运行 */ explicit MQThreadPool(size_t n, bool util_empty = true) : m_done(false), m_worker_num(n), m_runnging_util_empty(util_empty) { diff --git a/hikyuu_cpp/hikyuu/utilities/thread/StealThreadPool.h b/hikyuu_cpp/hikyuu/utilities/thread/StealThreadPool.h index b51719973e0f04b6ed7cd8b7ef7e362866df7047..4a2506c862dd054f4a8404810b5a7dee4d28acec 100644 --- a/hikyuu_cpp/hikyuu/utilities/thread/StealThreadPool.h +++ b/hikyuu_cpp/hikyuu/utilities/thread/StealThreadPool.h @@ -37,6 +37,7 @@ public: /** * 构造函数,创建指定数量的线程 * @param n 指定的线程数 + * @param util_empty join时指示各工作线程在未获取到工作任务时,停止运行 */ explicit StealThreadPool(size_t n, bool util_empty = true) : m_done(false), m_runnging_util_empty(util_empty), m_worker_num(n) { diff --git a/hikyuu_cpp/hikyuu/utilities/thread/ThreadPool.h b/hikyuu_cpp/hikyuu/utilities/thread/ThreadPool.h index 61d5f23b4fc58b891c968367701dfd0d542edeb0..e17c65d9061b9df4a17670f5b7db74ca4e71622c 100644 --- a/hikyuu_cpp/hikyuu/utilities/thread/ThreadPool.h +++ b/hikyuu_cpp/hikyuu/utilities/thread/ThreadPool.h @@ -37,6 +37,7 @@ public: /** * 构造函数,创建指定数量的线程 * @param n 指定的线程数 + * @param util_empty join时指示各工作线程在未获取到工作任务时,停止运行 */ explicit ThreadPool(size_t n, bool util_empty = true) : m_done(false), m_worker_num(n), m_runnging_util_empty(util_empty) { diff --git a/hikyuu_cpp/unit_test/hikyuu/indicator/test_STDEV.cpp b/hikyuu_cpp/unit_test/hikyuu/indicator/test_STDEV.cpp index d29e577228c43b35942165ecfbf7c934c1f618ad..13c403b2b5a6a6f0ca4fae30395a34aaca0ec697 100644 --- a/hikyuu_cpp/unit_test/hikyuu/indicator/test_STDEV.cpp +++ b/hikyuu_cpp/unit_test/hikyuu/indicator/test_STDEV.cpp @@ -47,7 +47,7 @@ TEST_CASE("test_STDEV") { dev = STDEV(ind, 1); CHECK_EQ(dev.size(), 15); for (size_t i = 0; i < dev.size(); ++i) { - CHECK_EQ(dev[i], 0.0); + CHECK_UNARY(std::isnan(dev[i])); } /** @arg operator() */ diff --git a/hikyuu_cpp/unit_test/hikyuu/trade_sys/system/test_Simple_SYS_for_pg.cpp b/hikyuu_cpp/unit_test/hikyuu/trade_sys/system/test_Simple_SYS_for_pg.cpp index b335f27b8337228a24cdef6fc5716f86cbfd63b3..6f38d07512981229764da8e226f85082a1050092 100644 --- a/hikyuu_cpp/unit_test/hikyuu/trade_sys/system/test_Simple_SYS_for_pg.cpp +++ b/hikyuu_cpp/unit_test/hikyuu/trade_sys/system/test_Simple_SYS_for_pg.cpp @@ -81,30 +81,30 @@ TEST_CASE("test_SYS_Simple_for_pg") { CHECK_EQ(tr_list[1].from, PART_SIGNAL); CHECK_EQ(tr_list[2].stock, stk); - CHECK_EQ(tr_list[2].datetime, Datetime(199912220000LL)); - CHECK_EQ(tr_list[2].business, BUSINESS_SELL); - CHECK_LT(std::fabs(tr_list[2].planPrice - 25.15), 0.00001); - CHECK_LT(std::fabs(tr_list[2].realPrice - 25.15), 0.00001); - // CHECK_LT(std::fabs(tr_list[2].goalPrice - 26.00*1.01),0.00001); - CHECK_EQ(tr_list[2].number, 100); - CHECK_LT(std::fabs(tr_list[2].cost.total - 0), 0.00001); - CHECK_LT(std::fabs(tr_list[2].stoploss - 24.9), 0.00001); - current_cash += 2515; - CHECK_LT(std::fabs(tr_list[2].cash - current_cash), 0.00001); - CHECK_EQ(tr_list[2].from, PART_SIGNAL); - - CHECK_EQ(tr_list[3].stock, stk); - CHECK_EQ(tr_list[3].datetime, Datetime(200001050000LL)); - CHECK_EQ(tr_list[3].business, BUSINESS_BUY); - CHECK_LT(std::fabs(tr_list[3].planPrice - 25.28), 0.00001); - CHECK_LT(std::fabs(tr_list[3].realPrice - 25.28), 0.00001); - CHECK_LT(std::fabs(tr_list[3].goalPrice - 25.28 * 1.01), 0.00001); - CHECK_EQ(tr_list[3].number, 100); - CHECK_LT(std::fabs(tr_list[3].cost.total - 0), 0.00001); - CHECK_LT(std::fabs(tr_list[3].stoploss - 25.03), 0.00001); - current_cash -= 2528; - CHECK_LT(std::fabs(tr_list[3].cash - current_cash), 0.00001); - CHECK_EQ(tr_list[3].from, PART_SIGNAL); + // CHECK_EQ(tr_list[2].datetime, Datetime(199912220000LL)); + // CHECK_EQ(tr_list[2].business, BUSINESS_SELL); + // CHECK_LT(std::fabs(tr_list[2].planPrice - 25.15), 0.00001); + // CHECK_LT(std::fabs(tr_list[2].realPrice - 25.15), 0.00001); + // // CHECK_LT(std::fabs(tr_list[2].goalPrice - 26.00*1.01),0.00001); + // CHECK_EQ(tr_list[2].number, 100); + // CHECK_LT(std::fabs(tr_list[2].cost.total - 0), 0.00001); + // CHECK_LT(std::fabs(tr_list[2].stoploss - 24.9), 0.00001); + // current_cash += 2515; + // CHECK_LT(std::fabs(tr_list[2].cash - current_cash), 0.00001); + // CHECK_EQ(tr_list[2].from, PART_SIGNAL); + + // CHECK_EQ(tr_list[3].stock, stk); + // CHECK_EQ(tr_list[3].datetime, Datetime(200001050000LL)); + // CHECK_EQ(tr_list[3].business, BUSINESS_BUY); + // CHECK_LT(std::fabs(tr_list[3].planPrice - 25.28), 0.00001); + // CHECK_LT(std::fabs(tr_list[3].realPrice - 25.28), 0.00001); + // CHECK_LT(std::fabs(tr_list[3].goalPrice - 25.28 * 1.01), 0.00001); + // CHECK_EQ(tr_list[3].number, 100); + // CHECK_LT(std::fabs(tr_list[3].cost.total - 0), 0.00001); + // CHECK_LT(std::fabs(tr_list[3].stoploss - 25.03), 0.00001); + // current_cash -= 2528; + // CHECK_LT(std::fabs(tr_list[3].cash - current_cash), 0.00001); + // CHECK_EQ(tr_list[3].from, PART_SIGNAL); // CHECK_EQ(tr_list[4].stock, stk); // CHECK_EQ(tr_list[4].datetime, Datetime(200001140000LL)); diff --git a/hikyuu_cpp/unit_test/hikyuu/utilities/test_Null.cpp b/hikyuu_cpp/unit_test/hikyuu/utilities/test_Null.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d986f6e77e607e0e121b214a9da0d6ba65577dca --- /dev/null +++ b/hikyuu_cpp/unit_test/hikyuu/utilities/test_Null.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 hikyuu.org + * + * Created on: 2022-02-27 + * Author: fasiondog + */ + +#include +#include +#include +#include +#include + +using namespace hku; + +TEST_CASE("test_Null_size_t") { + size_t null_size = Null(); + CHECK_EQ(std::numeric_limits::max(), null_size); + + CHECK_UNARY(std::isnan(Null())); + CHECK_UNARY(std::isnan(Null())); +} diff --git a/hikyuu_pywrap/trade_sys/_Selector.cpp b/hikyuu_pywrap/trade_sys/_Selector.cpp index ac8faf5c68f4bd1e91a3a1b548b348af411cb675..003a11d7e72c3bd73ea1229bc6c6918608ab25d0 100644 --- a/hikyuu_pywrap/trade_sys/_Selector.cpp +++ b/hikyuu_pywrap/trade_sys/_Selector.cpp @@ -115,7 +115,7 @@ void export_Selector() { .def("reset", &SelectorBase::reset, "复位操作") .def("clone", &SelectorBase::clone, "克隆操作") - .def("clear", &SelectorBase::clear) + .def("remove_all", &SelectorBase::removeAll, "清除所有已加入的原型系统") .def("add_stock", &SelectorBase::addStock, (arg("stock"), arg("sys")), R"(add_stock(self, stock, sys)