hikyuu 2.5.2__py3-none-win_amd64.whl → 2.5.5__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/__init__.py +5 -1
- hikyuu/__init__.pyi +522 -511
- hikyuu/analysis/__init__.pyi +490 -485
- hikyuu/analysis/analysis.pyi +491 -486
- hikyuu/core.pyi +492 -487
- hikyuu/cpp/__init__.pyi +2 -2
- hikyuu/cpp/core310.pyd +0 -0
- hikyuu/cpp/core310.pyi +249 -26
- hikyuu/cpp/core311.pyd +0 -0
- hikyuu/cpp/core311.pyi +249 -26
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/core312.pyi +249 -26
- hikyuu/cpp/core313.pyd +0 -0
- hikyuu/cpp/core313.pyi +243 -26
- hikyuu/cpp/core38.pyd +0 -0
- hikyuu/cpp/core38.pyi +249 -26
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/core39.pyi +249 -26
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/hikyuu.lib +0 -0
- hikyuu/data/mysql_upgrade/0027.sql +6 -0
- hikyuu/data/pytdx_to_h5.py +7 -4
- hikyuu/data/pytdx_to_mysql.py +7 -4
- hikyuu/data/sqlite_upgrade/0027.sql +8 -0
- hikyuu/draw/drawplot/__init__.py +8 -1
- hikyuu/draw/drawplot/__init__.pyi +11 -7
- hikyuu/draw/drawplot/bokeh_draw.pyi +509 -500
- hikyuu/draw/drawplot/common.pyi +1 -1
- hikyuu/draw/drawplot/echarts_draw.pyi +511 -502
- hikyuu/draw/drawplot/matplotlib_draw.py +129 -8
- hikyuu/draw/drawplot/matplotlib_draw.pyi +571 -515
- hikyuu/draw/elder.pyi +11 -11
- hikyuu/draw/kaufman.pyi +18 -18
- hikyuu/draw/volume.pyi +10 -10
- hikyuu/extend.pyi +501 -495
- hikyuu/fetcher/stock/zh_block_em.py +18 -7
- hikyuu/hub.py +112 -6
- hikyuu/hub.pyi +39 -13
- hikyuu/include/hikyuu/DataType.h +1 -2
- hikyuu/include/hikyuu/StockManager.h +2 -1
- hikyuu/include/hikyuu/StrategyContext.h +12 -3
- hikyuu/include/hikyuu/indicator/Indicator.h +24 -0
- hikyuu/include/hikyuu/indicator/Indicator2InImp.h +1 -0
- hikyuu/include/hikyuu/indicator/build_in.h +2 -0
- hikyuu/include/hikyuu/indicator/crt/ATR.h +2 -13
- hikyuu/include/hikyuu/indicator/crt/BARSSINCE.h +14 -2
- hikyuu/include/hikyuu/indicator/crt/KALMAN.h +30 -0
- hikyuu/include/hikyuu/indicator/crt/TR.h +32 -0
- hikyuu/include/hikyuu/indicator/imp/IAtr.h +3 -1
- hikyuu/include/hikyuu/indicator/imp/IBarsSince.h +6 -0
- hikyuu/include/hikyuu/indicator/imp/IKalman.h +27 -0
- hikyuu/include/hikyuu/indicator/imp/ITr.h +35 -0
- hikyuu/include/hikyuu/python/convert_any.h +299 -0
- hikyuu/include/hikyuu/trade_manage/PositionRecord.h +5 -4
- hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_MultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/MultiFactorAllocaterFunds.h +3 -0
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +4 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{SubCondition.h → logic/SubCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +20 -6
- hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Logic.h +35 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/AddEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/AndEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/DivEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/MultiEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/OrEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/SubEnvironment.h +42 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +0 -4
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Logic.h +68 -7
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AndSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OrSignal.h +19 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +2 -1
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/indicator/indicator.py +1 -0
- hikyuu/trade_manage/__init__.pyi +506 -499
- hikyuu/trade_manage/broker.pyi +3 -3
- hikyuu/trade_manage/broker_easytrader.pyi +1 -1
- hikyuu/trade_manage/trade.pyi +506 -499
- hikyuu/trade_sys/trade_sys.py +4 -3
- hikyuu/util/__init__.pyi +1 -1
- hikyuu/util/singleton.pyi +1 -1
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/METADATA +3 -2
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/RECORD +90 -73
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/top_level.txt +1 -0
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/LICENSE +0 -0
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/WHEEL +0 -0
- {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/entry_points.txt +0 -0
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"""
|
|
6
6
|
import sys
|
|
7
7
|
import os
|
|
8
|
-
import datetime
|
|
9
8
|
import logging
|
|
10
9
|
import numpy as np
|
|
11
10
|
import matplotlib
|
|
11
|
+
import seaborn as sns
|
|
12
12
|
import math
|
|
13
13
|
from typing import Union
|
|
14
14
|
from matplotlib.pylab import Rectangle, gca, gcf, figure, ylabel, axes, draw
|
|
@@ -499,6 +499,54 @@ def ibar(
|
|
|
499
499
|
# draw()
|
|
500
500
|
|
|
501
501
|
|
|
502
|
+
def iheatmap(ind, axes=None):
|
|
503
|
+
"""
|
|
504
|
+
绘制指标收益年-月收益热力图
|
|
505
|
+
|
|
506
|
+
指标收益率 = (当前月末值 - 上月末值) / 上月末值 * 100
|
|
507
|
+
|
|
508
|
+
指标应已计算(即有值),且为时间序列
|
|
509
|
+
|
|
510
|
+
:param ind: 指定指标
|
|
511
|
+
:param axes: 绘制的轴对象,默认为None,表示创建新的轴对象
|
|
512
|
+
:return: None
|
|
513
|
+
"""
|
|
514
|
+
if axes is None:
|
|
515
|
+
axes = create_figure()
|
|
516
|
+
|
|
517
|
+
if len(ind) == 0:
|
|
518
|
+
hku_error("指标长度为0, 指标应已计算(即有值")
|
|
519
|
+
return
|
|
520
|
+
|
|
521
|
+
dates = ind.get_datetime_list()
|
|
522
|
+
if len(dates) == 0:
|
|
523
|
+
hku_error("获取日期列表失败!指标应为时间序列")
|
|
524
|
+
return
|
|
525
|
+
|
|
526
|
+
data = pd.DataFrame({'date': dates, 'value': ind.to_np()})
|
|
527
|
+
data = data[(data[['value']] != 0).all(axis=1)]
|
|
528
|
+
|
|
529
|
+
# 提取年月信息
|
|
530
|
+
data['year'] = data['date'].apply(lambda v: v.year)
|
|
531
|
+
data['month'] = data['date'].apply(lambda v: v.month)
|
|
532
|
+
|
|
533
|
+
# 获取每个月的收益
|
|
534
|
+
monthly = data.groupby(['year', 'month']).last()['value'].reset_index()
|
|
535
|
+
if len(monthly) < 2:
|
|
536
|
+
hku_warn("月数据不足!")
|
|
537
|
+
return
|
|
538
|
+
|
|
539
|
+
monthly['return'] = ((monthly['value'] - monthly['value'].shift(1)) / monthly['value'].shift(1)) * 100.
|
|
540
|
+
|
|
541
|
+
pivot_data = monthly.pivot_table(index='year', columns='month', values='return')
|
|
542
|
+
|
|
543
|
+
sns.heatmap(pivot_data, cmap='RdYlGn_r', center=0, annot=True, fmt="<.2f", ax=axes)
|
|
544
|
+
# 设置标题和坐标轴标签
|
|
545
|
+
axes.set_title('年-月度收益率(%)热力图')
|
|
546
|
+
axes.set_xlabel('月度')
|
|
547
|
+
axes.set_ylabel('年份')
|
|
548
|
+
|
|
549
|
+
|
|
502
550
|
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
|
|
503
551
|
"""绘制MACD
|
|
504
552
|
|
|
@@ -641,13 +689,16 @@ def sgplot(sg, new=True, axes=None, style=1, kdata=None):
|
|
|
641
689
|
)
|
|
642
690
|
|
|
643
691
|
|
|
644
|
-
def evplot(ev, ref_kdata, new=True, axes=None):
|
|
692
|
+
def evplot(ev, ref_kdata, new=True, axes=None, upcolor='red', downcolor='blue', alpha=0.2):
|
|
645
693
|
"""绘制市场有效判断
|
|
646
694
|
|
|
647
695
|
:param EnvironmentBase cn: 系统有效条件
|
|
648
696
|
:param KData ref_kdata: 用于日期参考
|
|
649
697
|
:param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
|
|
650
698
|
:param axes: 指定在那个轴对象中进行绘制
|
|
699
|
+
:param upcolor: 有效时的颜色
|
|
700
|
+
:param downcolor: 无效时的颜色
|
|
701
|
+
:param alpha: 透明度
|
|
651
702
|
"""
|
|
652
703
|
refdates = ref_kdata.get_datetime_list()
|
|
653
704
|
if axes is None:
|
|
@@ -661,11 +712,11 @@ def evplot(ev, ref_kdata, new=True, axes=None):
|
|
|
661
712
|
x = np.array([i for i in range(len(refdates))])
|
|
662
713
|
y1 = np.array([1 if ev.is_valid(d) else -1 for d in refdates])
|
|
663
714
|
y2 = np.array([-1 if ev.is_valid(d) else 1 for d in refdates])
|
|
664
|
-
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=
|
|
665
|
-
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=
|
|
715
|
+
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=downcolor, alpha=alpha)
|
|
716
|
+
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=upcolor, alpha=alpha)
|
|
666
717
|
|
|
667
718
|
|
|
668
|
-
def cnplot(cn, new=True, axes=None, kdata=None):
|
|
719
|
+
def cnplot(cn, new=True, axes=None, kdata=None, upcolor='red', downcolor='blue', alpha=0.2):
|
|
669
720
|
"""绘制系统有效条件
|
|
670
721
|
|
|
671
722
|
:param ConditionBase cn: 系统有效条件
|
|
@@ -673,6 +724,9 @@ def cnplot(cn, new=True, axes=None, kdata=None):
|
|
|
673
724
|
:param axes: 指定在那个轴对象中进行绘制
|
|
674
725
|
:param KData kdata: 指定的KData,如该值为None,则认为该系统有效条件已经
|
|
675
726
|
指定了交易对象,否则,使用该参数作为交易对象
|
|
727
|
+
:param upcolor: 有效数时的颜色
|
|
728
|
+
:param downcolor: 无效时的颜色
|
|
729
|
+
:param alpha: 透明度
|
|
676
730
|
"""
|
|
677
731
|
if kdata is None:
|
|
678
732
|
kdata = cn.to
|
|
@@ -691,8 +745,8 @@ def cnplot(cn, new=True, axes=None, kdata=None):
|
|
|
691
745
|
x = np.array([i for i in range(len(refdates))])
|
|
692
746
|
y1 = np.array([1 if cn.is_valid(d) else -1 for d in refdates])
|
|
693
747
|
y2 = np.array([-1 if cn.is_valid(d) else 1 for d in refdates])
|
|
694
|
-
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=
|
|
695
|
-
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=
|
|
748
|
+
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=downcolor, alpha=alpha)
|
|
749
|
+
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=upcolor, alpha=alpha)
|
|
696
750
|
|
|
697
751
|
|
|
698
752
|
def sysplot(sys, new=True, axes=None, style=1, only_draw_close=False):
|
|
@@ -770,6 +824,13 @@ def sysplot(sys, new=True, axes=None, style=1, only_draw_close=False):
|
|
|
770
824
|
|
|
771
825
|
|
|
772
826
|
def sys_performance(sys, ref_stk=None):
|
|
827
|
+
"""
|
|
828
|
+
绘制系统绩效,即账户累积收益率曲线
|
|
829
|
+
|
|
830
|
+
:param SystemBase | PortfolioBase sys: SYS或PF实例
|
|
831
|
+
:param Stock ref_stk: 参考股票, 默认为沪深300: sh000300, 绘制参考标的的收益曲线
|
|
832
|
+
:return: None
|
|
833
|
+
"""
|
|
773
834
|
if ref_stk is None:
|
|
774
835
|
ref_stk = get_stock('sh000300')
|
|
775
836
|
|
|
@@ -847,10 +908,70 @@ def sys_performance(sys, ref_stk=None):
|
|
|
847
908
|
ax3.set_frame_on(False)
|
|
848
909
|
|
|
849
910
|
|
|
911
|
+
def tm_heatmap(tm, start_date, end_date=None, axes=None):
|
|
912
|
+
"""
|
|
913
|
+
绘制账户收益年-月收益热力图
|
|
914
|
+
|
|
915
|
+
:param tm: 交易账户
|
|
916
|
+
:param start_date: 开始日期
|
|
917
|
+
:param end_date: 结束日期,默认为今天
|
|
918
|
+
:param axes: 绘制的轴对象,默认为None,表示创建新的轴对象
|
|
919
|
+
:return: None
|
|
920
|
+
"""
|
|
921
|
+
if axes is None:
|
|
922
|
+
axes = create_figure()
|
|
923
|
+
|
|
924
|
+
if end_date is None:
|
|
925
|
+
end_date = Datetime.today() + Days(1)
|
|
926
|
+
|
|
927
|
+
dates = get_date_range(start_date, end_date)
|
|
928
|
+
if len(dates) == 0:
|
|
929
|
+
hku_error("没有数据,请检查日期范围!start_date={}, end_date={}", start_date, end_date)
|
|
930
|
+
return
|
|
931
|
+
|
|
932
|
+
funds = tm.get_funds_curve(dates)
|
|
933
|
+
if len(funds) == 0:
|
|
934
|
+
hku_error("获取 tm 收益曲线失败,请检查 tm 初始日期!tm.init_datetime={} start_date={}, end_date={}",
|
|
935
|
+
tm.init_datetime, start_date, end_date)
|
|
936
|
+
return
|
|
937
|
+
|
|
938
|
+
data = pd.DataFrame({'date': dates, 'value': funds})
|
|
939
|
+
data = data[(data[['value']] != 0).all(axis=1)]
|
|
940
|
+
|
|
941
|
+
# 提取年月信息
|
|
942
|
+
data['year'] = data['date'].apply(lambda v: v.year)
|
|
943
|
+
data['month'] = data['date'].apply(lambda v: v.month)
|
|
944
|
+
|
|
945
|
+
# 获取每个月的收益
|
|
946
|
+
monthly = data.groupby(['year', 'month']).last()['value'].reset_index()
|
|
947
|
+
if len(monthly) < 2:
|
|
948
|
+
hku_warn("月数据不足!")
|
|
949
|
+
return
|
|
950
|
+
|
|
951
|
+
monthly['return'] = ((monthly['value'] - monthly['value'].shift(1)) / monthly['value'].shift(1)) * 100.
|
|
952
|
+
|
|
953
|
+
pivot_data = monthly.pivot_table(index='year', columns='month', values='return')
|
|
954
|
+
|
|
955
|
+
sns.heatmap(pivot_data, cmap='RdYlGn_r', center=0, annot=True, fmt="<.2f", ax=axes)
|
|
956
|
+
# 设置标题和坐标轴标签
|
|
957
|
+
axes.set_title('年-月度收益率(%)热力图')
|
|
958
|
+
axes.set_xlabel('月度')
|
|
959
|
+
axes.set_ylabel('年份')
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def sys_heatmap(sys, axes=None):
|
|
963
|
+
"""
|
|
964
|
+
绘制系统收益年-月收益热力图
|
|
965
|
+
"""
|
|
966
|
+
hku_check(sys.tm is not None, "系统未初始化交易账户")
|
|
967
|
+
query = sys.query
|
|
968
|
+
k = get_kdata('sh000001', query)
|
|
969
|
+
tm_heatmap(sys.tm, k[0].datetime, k[-1].datetime, axes)
|
|
970
|
+
|
|
971
|
+
|
|
850
972
|
# ============================================================================
|
|
851
973
|
# 通达信画图函数
|
|
852
974
|
# ============================================================================
|
|
853
|
-
|
|
854
975
|
DRAWNULL = constant.null_price
|
|
855
976
|
|
|
856
977
|
|