/*
* test_Stock.cpp
*
* Created on: 2011-12-10
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <cmath>
#include <hikyuu/StockManager.h>
#include <hikyuu/KQuery.h>
#include <hikyuu/KData.h>
#include <hikyuu/Stock.h>
using namespace hku;
#define MEMORY_CHECK \
{ \
Stock mem_stock = sm["sh000001"]; \
CHECK_EQ(mem_stock.isBuffer(KQuery::DAY), true); \
CHECK_EQ(mem_stock.isBuffer(KQuery::WEEK), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MONTH), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::QUARTER), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::HALFYEAR), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::YEAR), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN5), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN15), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN30), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN60), false); \
}
/**
* @defgroup test_hikyuu_Stock test_hikyuu_Stock
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_Stock_Relational_comparison") {
StockManager& sm = StockManager::instance();
Stock s1;
/** @arg 和Null<Stock>()进行相等比较 */
CHECK_EQ(s1, Null<Stock>());
/** @arg 和Null<Stock>()进行不等比较 */
s1 = sm.getStock("sh000001");
CHECK_NE(s1, Null<Stock>());
/** @arg 相等比较 */
Stock s2 = sm.getStock("sh000001");
CHECK_EQ(s1, s2);
/** @arg 不等比较 */
s2 = sm.getStock("sz000001");
CHECK_NE(s1, s2);
MEMORY_CHECK;
}
/** @par 检测点 */
TEST_CASE("test_Stock_getWeight") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sz000001");
StockWeight weight;
/** @arg 查询全部权息信息 */
StockWeightList weightList = stock.getWeight();
CHECK_EQ(weightList.size(), 23);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199104030000L));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 150);
CHECK_EQ(weight.freeCount(), 68);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(201108050000L));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
/** @arg 查询指定日期范围内的权息信息,指定的起始日期和结束日期没有刚好对应的权息记录 */
weightList = stock.getWeight(Datetime(199501010000), Datetime(199701010000));
CHECK_EQ(weightList.size(), 2);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(199605270000));
CHECK_EQ(weight.countAsGift(), 5.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 5.0);
CHECK_EQ(weight.totalCount(), 103456);
CHECK_EQ(weight.freeCount(), 71393);
/** @arg 查询指定日期范围内的权息信息,指定的起始日期刚好存在对应权息记录,而结束日期没有 */
weightList = stock.getWeight(Datetime(199509250000), Datetime(199701010000));
CHECK_EQ(weightList.size(), 2);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(199605270000));
CHECK_EQ(weight.countAsGift(), 5.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 5.0);
CHECK_EQ(weight.totalCount(), 103456);
CHECK_EQ(weight.freeCount(), 71393);
/** @arg 查询指定日期范围内的权息信息,指定的结束日期刚好存在对应权息记录,而起始日期没有 */
weightList = stock.getWeight(Datetime(199501010000), Datetime(199605270000));
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
/** @arg 查询指定日期范围内的权息信息,结束日期为Null<Datetime>() */
weightList = stock.getWeight(Datetime(201101010000), Null<Datetime>());
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(201108050000));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
/** @arg 查询指定日期范围内的权息信息,只指定起始日期,结束日期为默认值 */
weightList = stock.getWeight(Datetime(201101010000));
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(201108050000));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
MEMORY_CHECK;
}
/** @par 检测点 */
TEST_CASE("test_Stock_getCount") {
StockManager& sm = StockManager::instance();
/** @arg 查询sh000001的日线数量*/
Stock stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::DAY), 5121);
/** @arg 查询sz000001的日线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::DAY), 4937);
/** @arg 查询sh000001的周线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::WEEK), 1059);
/** @arg 查询sz000001的周线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::WEEK), 1037);
/** @arg 查询sh000001的月线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::MONTH), 253);
/** @arg 查询sz000001的月线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::MONTH), 250);
/** @arg 查询sh000001的季线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::QUARTER), 85);
/** @arg 查询sz000001的季线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::QUARTER), 84);
/** @arg 查询sh000001的半年线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery:
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Hikyuu Quant Framework是一款基于C++/Python的开源量化交易研究框架,用于策略分析及回测(目前主要用于国内A股市场)。其核心思想基于当前成熟的系统化交易方法,将整个系统化交易抽象为由市场环境判断策略、系统有效条件、信号指示器、止损/止盈策略、资金管理策略、盈利目标策略、移滑价差算法七大组件,你可以分别构建这些组件的策略资产库,在实际研究中对它们自由组合来观察系统的有效性、稳定性以及单一种类策略的效果。
资源推荐
资源详情
资源评论
收起资源包目录
基于C++/Python的开源量化交易研究框架 (1287个子文件)
make.bat 778B
.clang-format 3KB
test_Stock.cpp 86KB
TradeManager.cpp 79KB
_build_in.cpp 72KB
test_KData.cpp 60KB
IndicatorImp.cpp 46KB
System.cpp 42KB
H5KDataDriver.cpp 39KB
test_TradeManager.cpp 35KB
Stock.cpp 31KB
test_SE_Operator.cpp 26KB
_TradeManager.cpp 23KB
test_Indicator.cpp 23KB
test_Datetime.cpp 22KB
AllocateFundsBase.cpp 21KB
test_iniparser.cpp 20KB
StockManager.cpp 20KB
Datetime.cpp 19KB
Performance.cpp 18KB
MultiFactorBase.cpp 17KB
Portfolio.cpp 17KB
MySQLBaseInfoDriver.cpp 16KB
KDataImp.cpp 16KB
test_Simple_SYS_for_ev.cpp 16KB
SQLiteBaseInfoDriver.cpp 16KB
MySQLStatement.cpp 16KB
MySQLKDataDriver.cpp 13KB
IniParser.cpp 13KB
test_TimeDelta.cpp 13KB
TdxKDataDriver.cpp 12KB
test_Simple_SYS_for_cn.cpp 12KB
test_ALIGN.cpp 12KB
_System.cpp 12KB
SQLiteKDataDriver.cpp 11KB
BrokerTradeManager.cpp 11KB
_MultiFactor.cpp 11KB
Indicator.cpp 11KB
Parameter.cpp 10KB
_MoneyManager.cpp 10KB
md5.cpp 10KB
_Stock.cpp 10KB
GlobalSpotAgent.cpp 9KB
test_StockManager.cpp 9KB
_Selector.cpp 9KB
os.cpp 9KB
OperatorSelector.cpp 9KB
_StockManager.cpp 9KB
Strategy.cpp 8KB
test_Simple_SYS_for_pg.cpp 8KB
test_TransList.cpp 8KB
test_SPEARMAN.cpp 8KB
_Signal.cpp 8KB
test_Simple_SYS_for_tp.cpp 8KB
test_MF_EqualWeight.cpp 8KB
SpotAgent.cpp 8KB
_Indicator.cpp 7KB
test_MA.cpp 7KB
test_RECOVER.cpp 7KB
test_TimeLine.cpp 7KB
MoneyManagerBase.cpp 7KB
IAma.cpp 7KB
_analysis.cpp 7KB
test_MACD.cpp 7KB
TimeDelta.cpp 7KB
test_Simple_SYS_for_base.cpp 7KB
MySQLConnect.cpp 7KB
test_export.cpp 7KB
test_SUMBARS.cpp 7KB
test_TIME.cpp 7KB
test_Parameter.cpp 7KB
test_IKData.cpp 6KB
IInSum.cpp 6KB
test_Simple_SYS_for_st.cpp 6KB
KDataTempCsvDriver.cpp 6KB
SQLiteConnect.cpp 6KB
_Datetime.cpp 6KB
test_SAFTYLOSS.cpp 6KB
DataDriverFactory.cpp 6KB
test_LLVBARS.cpp 6KB
test_mysql.cpp 6KB
KQuery.cpp 6KB
test_HHVBARS.cpp 6KB
main.cpp 6KB
test_sqlite.cpp 6KB
test_crtFixedATC.cpp 6KB
IKData.cpp 6KB
test_FILTER.cpp 6KB
SQLiteStatement.cpp 6KB
HttpClient.cpp 5KB
_TimeDelta.cpp 5KB
IAlign.cpp 5KB
test_AMA.cpp 5KB
_Stoploss.cpp 5KB
QLBlockInfoDriver.cpp 5KB
MultiFactorSelector.cpp 5KB
_ProfitGoal.cpp 5KB
ISaftyLoss.cpp 5KB
test_LAST.cpp 5KB
ICMultiFactor.cpp 5KB
共 1287 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7361
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功