Skip to content

Commit

Permalink
Merge pull request #231 from fasiondog/feature/tmpstock
Browse files Browse the repository at this point in the history
移除 Stock.get_history_finance_info,后续改用 FINANCE 指标获取
  • Loading branch information
fasiondog committed Apr 18, 2024
2 parents 19ab50e + ce4ce8b commit 21bafa8
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 71 deletions.
15 changes: 7 additions & 8 deletions hikyuu/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def deprecated_func(new_func, old_func_name, new_func_name):
def wrap_deprecated_func(func):
def wrapfunc(*args, **kwarg):
print(
#'Deprecated warning: "{}" will be deprecated, please use: "{}"'.format(
# 'Deprecated warning: "{}" will be deprecated, please use: "{}"'.format(
'警告: "{}" 函数即将废弃,请使用 "{}" 代替'.format(old_func_name, new_func_name)
)
return new_func(*args, **kwarg)
Expand All @@ -25,11 +25,11 @@ def wrapfunc(self, name):
clzname = self.__class__.__name__
if name in name_dict:
if name_dict[name] is None:
#print('Removed warning: the {}.{} will be removed!'.format(clzname, name))
# print('Removed warning: the {}.{} will be removed!'.format(clzname, name))
print('警告: "{}.{}" 接口已被删除!'.format(clzname, name))
else:
print(
#'Deprecated warning: the "{}.{}" will be deprecated, please use: "{}.{}"'.
# 'Deprecated warning: the "{}.{}" will be deprecated, please use: "{}.{}"'.
'警告: "{}.{}" 即将被废弃,请使用 "{}.{}" 代替'.format(clzname, name, clzname, name_dict[name])
)
return func(self, name_dict[name])
Expand All @@ -42,11 +42,11 @@ def wrapfunc(self, name):
return wrap_deprecated_attr


#--------------------------------------------------------------------
# --------------------------------------------------------------------
#
# 待废弃函数
#
#--------------------------------------------------------------------
# --------------------------------------------------------------------


@deprecated_func(get_version, 'getVersion', 'get_version')
Expand Down Expand Up @@ -104,11 +104,11 @@ def SL_FixedValue(*args, **kwargs):
pass


#--------------------------------------------------------------------
# --------------------------------------------------------------------
#
# 待废弃属性
#
#--------------------------------------------------------------------
# --------------------------------------------------------------------


@deprecated_attr(
Expand Down Expand Up @@ -486,7 +486,6 @@ def SlippageBase_getattr(self, name):
'getKRecordList': 'get_krecord_list',
'getDatetimeList': 'get_datetime_list',
'getFinanceInfo': 'get_finance_info',
'getHistoryFinanceInfo': 'get_history_finance_info',
'realtimeUpdate': 'realtime_update',
'getWeight': 'get_weight',
'loadKDataToBuffer': 'load_kdata_to_buffer',
Expand Down
12 changes: 0 additions & 12 deletions hikyuu_cpp/hikyuu/Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "GlobalInitializer.h"
#include "StockManager.h"
#include "data_driver/KDataDriver.h"
#include "data_driver/HistoryFinanceReader.h"
#include "KData.h"

namespace hku {
Expand Down Expand Up @@ -832,17 +831,6 @@ Parameter Stock::getFinanceInfo() const {
return result;
}

PriceList Stock::getHistoryFinanceInfo(const Datetime& date) const {
PriceList result;
HKU_IF_RETURN(type() != STOCKTYPE_A && type() != STOCKTYPE_GEM && type() != STOCKTYPE_START &&
type() != STOCKTYPE_A_BJ,
result);
const StockManager& sm = StockManager::instance();
HistoryFinanceReader rd(sm.datadir() + "/downloads/finance");
result = rd.getHistoryFinanceInfo(date, market(), code());
return result;
}

// 判断是否在交易时间段内(不判断日期)
bool Stock::isTransactionTime(Datetime time) {
MarketInfo market_info = StockManager::instance().getMarketInfo(market());
Expand Down
3 changes: 0 additions & 3 deletions hikyuu_cpp/hikyuu/Stock.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ class HKU_API Stock {

/**
* 获取历史财务信息
* @param date 指定日期必须是0331、0630、0930、1231,如 Datetime(201109300000)
*/
PriceList getHistoryFinanceInfo(const Datetime& date) const;

const vector<HistoryFinanceInfo>& getHistoryFinance() const;

/** 设置权息信息, 仅供初始化时调用 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ vector<HistoryFinanceInfo> MySQLBaseInfoDriver::getHistoryFinance(const string &
to_upper(market_code);
vector<HistoryFinanceTable> finances;
con->batchLoad(finances, ((Field("market_code") == market_code) &
(Field("report_date") >= new_start.ymd())) +
(Field("report_date") >= new_start.ymd()) &
Field("report_date") < new_end.ymd()) +
ASC("report_date"));
size_t total = finances.size();
result.resize(total);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ vector<HistoryFinanceInfo> SQLiteBaseInfoDriver::getHistoryFinance(const string&
to_upper(market_code);
vector<HistoryFinanceTable> finances;
con->batchLoad(finances, ((Field("market_code") == market_code) &
(Field("report_date") >= start.ymd())) +
(Field("report_date") >= new_start.ymd()) &
(Field("report_date") < new_end.ymd())) +
ASC("report_date"));
size_t total = finances.size();
result.resize(total);
Expand Down
29 changes: 4 additions & 25 deletions hikyuu_cpp/unit_test/hikyuu/hikyuu/test_Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ TEST_CASE("test_Stock_getKRecord_By_Date") {
Stock stock = sm.getStock("sh000001");
KRecord record;

///测试日线
/// 测试日线
///===================================

/** @arg 日期小于第一条记录 */
Expand Down Expand Up @@ -1873,7 +1873,7 @@ TEST_CASE("test_Stock_getKRecord_By_Date") {
CHECK_EQ(record, Null<KRecord>());

///===================================
///测试周线
/// 测试周线
///===================================

/** @arg 日期小于第一条记录 */
Expand Down Expand Up @@ -1904,7 +1904,7 @@ TEST_CASE("test_Stock_getKRecord_By_Date") {
CHECK_EQ(record, Null<KRecord>());

///===================================
///测试月线
/// 测试月线
///===================================

/** @arg 日期小于第一条记录 */
Expand Down Expand Up @@ -1935,7 +1935,7 @@ TEST_CASE("test_Stock_getKRecord_By_Date") {
CHECK_EQ(record, Null<KRecord>());

///===================================
///测试15分钟线
/// 测试15分钟线
///===================================

/** @arg 日期小于第一条记录 */
Expand Down Expand Up @@ -2051,27 +2051,6 @@ TEST_CASE("test_Stock_id_map") {
MEMORY_CHECK;
}

/** @par 检测点 */
TEST_CASE("test_Stock_getHistoryFinanceInfo") {
StockManager& sm = StockManager::instance();
Stock stk = getStock("sh600000");
PriceList result = stk.getHistoryFinanceInfo(Datetime(201109300000));
CHECK_EQ(result.size(), 286);
CHECK_EQ(result[0], doctest::Approx(1.067).epsilon(0.00001));
CHECK_EQ(result[1], doctest::Approx(1.061).epsilon(0.00001));
CHECK_EQ(result[2], doctest::Approx(1.360).epsilon(0.00001));
CHECK_EQ(result[3], doctest::Approx(7.482).epsilon(0.00001));
CHECK_EQ(result[9], doctest::Approx(0.0).epsilon(0.00001));
CHECK_EQ(result[14], doctest::Approx(7.87818e+09).epsilon(0.00001));
CHECK_EQ(result[282], doctest::Approx(6.327156e+06).epsilon(0.00001));
CHECK_EQ(result[285], doctest::Approx(0.0).epsilon(0.00001));
// for (int i = 0; i < 286; i++) {
// std::cout << result[i] << std::endl;
//}

MEMORY_CHECK;
}

/** @par 检测点 */
TEST_CASE("test_Stock_getFinanceInfo") {
StockManager& sm = StockManager::instance();
Expand Down
8 changes: 0 additions & 8 deletions hikyuu_pywrap/_Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ void export_Stock(py::module& m) {
:rtype: Parameter)")

.def("get_history_finance_info", &Stock::getHistoryFinanceInfo,
R"(get_history_finance_info(self, date)
获取历史财务信息, 字段含义参见:https://hikyuu.org/finance_fields.html
:param Datetime date: 指定日期必须是0331、0630、0930、1231,如 Datetime(201109300000)
:rtype: list)")

.def("realtime_update", &Stock::realtimeUpdate, py::arg("krecord"),
py::arg("ktype") = KQuery::DAY,
R"(realtime_update(self, krecord)
Expand Down
21 changes: 12 additions & 9 deletions hikyuu_pywrap/_StockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,18 @@ void export_StockManager(py::module& m) {
根据字段名称,获取历史财务信息相应字段索引)")

.def("get_history_finance_all_fields",
[](const StockManager& sm) {
auto fields = sm.getHistoryFinanceAllFields();
py::list ret;
for (const auto& f : fields) {
ret.append(py::make_tuple(f.first, f.second));
}
return ret;
})
.def(
"get_history_finance_all_fields",
[](const StockManager& sm) {
auto fields = sm.getHistoryFinanceAllFields();
py::list ret;
for (const auto& f : fields) {
ret.append(py::make_tuple(f.first, f.second));
}
return ret;
},
R"(get_history_finance_all_fields(self)
获取所有历史财务信息字段及其索引)")

.def("add_stock", &StockManager::addStock, R"(add_stock(self, stock)
Expand Down
19 changes: 15 additions & 4 deletions hikyuu_pywrap/indicator/_build_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,8 +1825,19 @@ void export_Indicator_build_in(py::module& m) {
:param Indicator data: 指定的指标
:param int result_ix: 指定的结果集)");

m.def("FINANCE", py::overload_cast<int>(FINANCE));
m.def("FINANCE", py::overload_cast<const string&>(FINANCE));
m.def("FINANCE", py::overload_cast<const KData&, int>(FINANCE));
m.def("FINANCE", py::overload_cast<const KData&, const string&>(FINANCE));
m.def("FINANCE", py::overload_cast<int>(FINANCE), py::arg("ix"));
m.def("FINANCE", py::overload_cast<const string&>(FINANCE), py::arg("name"));
m.def("FINANCE", py::overload_cast<const KData&, int>(FINANCE), py::arg("kdata"),
py::arg("ix"));
m.def("FINANCE", py::overload_cast<const KData&, const string&>(FINANCE), py::arg("kdata"),
py::arg("name"),
R"(FINANCE([kdata, ix, name])
获取历史财务信息。(可通过 StockManager.get_history_finance_all_fields 查询相应的历史财务字段信息)
ix, name 使用时,为二选一。即要不使用 ix,要不就使用 name 进行获取。
:param KData kdata: K线数据
:param int ix: 历史财务信息字段索引
:param int name: 历史财务信息字段名称)");
}

0 comments on commit 21bafa8

Please sign in to comment.