mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 20:08:26 +08:00
Merge pull request #152 from fasiondog/feature/python
Feature/python 同时支持多python版本
This commit is contained in:
commit
c02a283337
@ -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
23
hikyuu/core.py
Normal 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 *
|
@ -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线类型
|
||||
|
@ -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 *
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user