Merge pull request #152 from fasiondog/feature/python

Feature/python 同时支持多python版本
This commit is contained in:
fasiondog 2024-01-26 14:26:11 +08:00 committed by GitHub
commit c02a283337
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 69 additions and 27 deletions

View File

@ -5,7 +5,7 @@
# Author: fasiondog
import pandas as pd
from hikyuu.cpp.core import Block, Performance, _combinate_ind_analysis, _combinate_ind_analysis_with_block
from hikyuu.core import Block, Performance, inner_combinate_ind_analysis, inner_combinate_ind_analysis_with_block
def combinate_ind_analysis(
@ -20,7 +20,7 @@ def combinate_ind_analysis(
):
'''
:param Stock stk:
:param Query query:
:param TradeManager tm:
@ -31,7 +31,7 @@ def combinate_ind_analysis(
:param list keys: Performance
:rtype: pd.DataFrame
'''
pers = _combinate_ind_analysis(stk, query, tm, sys, buy_inds, sell_inds, n)
pers = inner_combinate_ind_analysis(stk, query, tm, sys, buy_inds, sell_inds, n)
if not keys:
per = Performance()
@ -82,7 +82,7 @@ def combinate_ind_analysis_multi(
for stk in stks:
blks.add(stk)
out = _combinate_ind_analysis_with_block(blks, query, tm, sys, buy_inds, sell_inds, n)
out = inner_combinate_ind_analysis_with_block(blks, query, tm, sys, buy_inds, sell_inds, n)
if not keys:
ret = out
else:

23
hikyuu/core.py Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# Create on: 20240126
# Author: fasiondog
import sys
try:
if sys.version_info[1] == 8:
from .cpp.core38 import *
elif sys.version_info[1] == 9:
from .cpp.core39 import *
elif sys.version_info[1] == 10:
from .cpp.core310 import *
elif sys.version_info[1] == 11:
from .cpp.core311 import *
elif sys.version_info[1] == 12:
from .cpp.core312 import *
else:
from .cpp.core import *
except:
from .cpp.core import *

View File

@ -24,12 +24,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# ===============================================================================
# history:
# 1. 20171122, Added by fasiondog
#===============================================================================
# ===============================================================================
from hikyuu.cpp.core import KData, Indicator, SignalBase, ConditionBase, System
from hikyuu.core import KData, Indicator, SignalBase, ConditionBase, System
import matplotlib
from matplotlib.pylab import gca as mpl_gca
@ -121,6 +121,7 @@ def use_draw_with_matplotlib():
System.plot = mpl_sysplot
def use_draw_with_echarts():
set_current_draw_engine('echarts')
@ -133,6 +134,7 @@ def use_draw_with_echarts():
System.plot = ec_sysplot
def create_figure(n=1, figsize=None):
"""生成含有指定坐标轴数量的窗口最大只支持4个坐标轴。
@ -181,7 +183,7 @@ def show_gcf():
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
"""绘制MACD
:param axes:
:param KData kdata: KData
:param int n1: MACD 1
@ -199,7 +201,7 @@ def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
"""绘制MACD
:param axes:
:param KData kdata: KData
:param int n1: MACD 1
@ -240,7 +242,7 @@ def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9):
def adjust_axes_show(axeslist):
"""用于调整上下紧密相连的坐标轴显示时,其上一坐标轴最小值刻度和下一坐标轴最大值刻度
:param axeslist: (ax1,ax2,...)
"""
engine = get_current_draw_engine()
@ -254,7 +256,7 @@ def adjust_axes_show(axeslist):
def ax_set_locator_formatter(axes, dates, typ):
""" 设置指定坐标轴的日期显示根据指定的K线类型优化X轴坐标显示
:param axes:
:param dates: Datetime构成可迭代序列
:param Query.KType typ: K线类型

View File

@ -5,7 +5,7 @@ from pyecharts.charts import Kline, Scatter, Line, Bar, Grid
from pyecharts.charts.base import Base as ChartBase
from pyecharts.commons.utils import JsCode
from hikyuu.cpp.core import KData, System
from hikyuu.core import KData, System
from .common import get_draw_title
from hikyuu import *

View File

@ -3,14 +3,8 @@
#
from datetime import *
from .cpp.core import *
from .util.slice import list_getitem
try:
from .cpp.core_pro import *
except:
pass
from .core import *
# ------------------------------------------------------------------
# 增加Datetime、Stock的hash支持以便可做为dict的key

View File

@ -24,7 +24,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from hikyuu.cpp.core import *
from hikyuu.core import *
from hikyuu import Datetime

View File

@ -1,8 +1,8 @@
# -*- coding: utf8 -*-
from hikyuu.util.slice import list_getitem
from hikyuu.cpp.core import SYS_Simple as cpp_SYS_Simple
from hikyuu.cpp.core import (
from hikyuu.core import SYS_Simple as cpp_SYS_Simple
from hikyuu.core import (
System, SystemPart, ConditionBase, EnvironmentBase, MoneyManagerBase,
ProfitGoalBase, SelectorBase, SignalBase, SlippageBase, StoplossBase
)

View File

@ -175,8 +175,8 @@ void export_analysis(py::module& m) {
:return:
:rtype: list)");
m.def("_combinate_ind_analysis", combinate_ind_analysis);
m.def("_combinate_ind_analysis_with_block", combinate_ind_analysis_with_block);
m.def("inner_combinate_ind_analysis", combinate_ind_analysis);
m.def("inner_combinate_ind_analysis_with_block", combinate_ind_analysis_with_block);
m.def("analysis_sys_list", analysis_sys_list);
}

View File

@ -48,7 +48,19 @@ void export_analysis(py::module& m);
void export_StrategeContext(py::module& m);
void export_strategy_main(py::module& m);
#if PY_MINOR_VERSION == 8
PYBIND11_MODULE(core38, m) {
#elif PY_MINOR_VERSION == 9
PYBIND11_MODULE(core39, m) {
#elif PY_MINOR_VERSION == 10
PYBIND11_MODULE(core310, m) {
#elif PY_MINOR_VERSION == 11
PYBIND11_MODULE(core311, m) {
#elif PY_MINOR_VERSION == 12
PYBIND11_MODULE(core312, m) {
#else
PYBIND11_MODULE(core, m) {
#endif
py::register_exception<hku::exception>(m, "HKUException");
export_bind_stl(m);

View File

@ -68,15 +68,26 @@ target("core")
end
local dst_dir = "$(projectdir)/hikyuu/cpp/"
local dst_obj = dst_dir .. "core.so"
if not is_plat("cross") then
import("lib.detect.find_tool")
local python = assert(find_tool("python", {version = true}), "python not found, please install it first! note: python version must > 3.0")
local tmp = string.split(python.version, "%.")
dst_obj = dst_dir .. "core" .. tmp[1] .. tmp[2]
end
-- print(dst_obj)
if is_plat("windows") then
os.cp(target:targetdir() .. '/core.pyd', dst_dir)
os.cp(target:targetdir() .. '/core.pyd', dst_obj .. ".pyd")
os.cp(target:targetdir() .. '/*.dll', dst_dir)
elseif is_plat("macosx") then
os.cp(target:targetdir() .. '/core.so', dst_dir)
os.cp(target:targetdir() .. '/core.so', dst_obj .. ".so")
os.cp(target:targetdir() .. '/libhikyuu.dylib', dst_dir)
else
os.trycp(target:targetdir() .. '/*.so', dst_dir)
os.trycp(target:targetdir() .. '/*.so.*', dst_dir)
if not is_plat("cross") then
os.trycp(target:targetdir() .. '/*.so', dst_obj .. ".so")
end
end
end)