polars-ta 0.4.4__tar.gz → 0.4.6__tar.gz
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.
- {polars_ta-0.4.4 → polars_ta-0.4.6}/PKG-INFO +2 -2
- polars_ta-0.4.6/polars_ta/_version.py +1 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/tdx.py +68 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/__init__.py +3 -0
- polars_ta-0.4.6/polars_ta/tdx/_chip.py +121 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/logical.py +15 -12
- polars_ta-0.4.6/polars_ta/tdx/pattern.py +49 -0
- polars_ta-0.4.6/polars_ta/tdx/pattern_feature.py +236 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/reference.py +12 -1
- polars_ta-0.4.6/polars_ta/tdx/trend_feature.py +449 -0
- polars_ta-0.4.6/polars_ta/wq/arithmetic.py +863 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/cross_sectional.py +10 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/time_series.py +36 -3
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta.egg-info/PKG-INFO +2 -2
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta.egg-info/SOURCES.txt +4 -0
- polars_ta-0.4.4/polars_ta/_version.py +0 -1
- polars_ta-0.4.4/polars_ta/wq/arithmetic.py +0 -433
- {polars_ta-0.4.4 → polars_ta-0.4.6}/LICENSE +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/README.md +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/candles/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/candles/cdl1.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/candles/cdl1_limit.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/candles/cdl2.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/noise.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/performance/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/performance/drawdown.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/performance/returns.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/cdl.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/reports.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/ta.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/talib.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/prefix/wq.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/reports/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/reports/cicc.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/momentum.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/operators.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/overlap.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/price.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/statistic.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/transform.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/volatility.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/ta/volume.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/talib/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/_nb.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/_slow.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/arithmetic.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/choice.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/energy.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/moving_average.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/over_bought_over_sold.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/pressure_support.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/statistic.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/trend.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/tdx/volume.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/helper.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/numba_.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/pandas_.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/pit.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/utils/wrapper.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/__init__.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/_nb.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/_slow.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/logical.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/preprocess.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/transformational.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta/wq/vector.py +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta.egg-info/dependency_links.txt +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta.egg-info/requires.txt +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/polars_ta.egg-info/top_level.txt +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/pyproject.toml +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/setup.cfg +0 -0
- {polars_ta-0.4.4 → polars_ta-0.4.6}/setup.py +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.4.6"
|
@@ -56,28 +56,67 @@ from polars_ta.tdx.over_bought_over_sold import MFI as ts_MFI # noqa
|
|
56
56
|
from polars_ta.tdx.over_bought_over_sold import MTM as ts_MTM # noqa
|
57
57
|
from polars_ta.tdx.over_bought_over_sold import RSI as ts_RSI # noqa
|
58
58
|
from polars_ta.tdx.over_bought_over_sold import RSV as ts_RSV # noqa
|
59
|
+
from polars_ta.tdx.pattern import ts_WINNER_COST # noqa
|
60
|
+
from polars_ta.tdx.pattern_feature import 仙人指路 as ts_仙人指路 # noqa
|
61
|
+
from polars_ta.tdx.pattern_feature import 低开大阳线 as ts_低开大阳线 # noqa
|
62
|
+
from polars_ta.tdx.pattern_feature import 低点搜寻 as ts_低点搜寻 # noqa
|
63
|
+
from polars_ta.tdx.pattern_feature import 出水芙蓉 as ts_出水芙蓉 # noqa
|
64
|
+
from polars_ta.tdx.pattern_feature import 出水芙蓉II as ts_出水芙蓉II # noqa
|
65
|
+
from polars_ta.tdx.pattern_feature import 剑 as ts_剑 # noqa
|
66
|
+
from polars_ta.tdx.pattern_feature import 单阳不破选股 as ts_单阳不破选股 # noqa
|
67
|
+
from polars_ta.tdx.pattern_feature import 四串阳 as ts_四串阳 # noqa
|
68
|
+
from polars_ta.tdx.pattern_feature import 四串阴 as ts_四串阴 # noqa
|
69
|
+
from polars_ta.tdx.pattern_feature import 回补跳空向上缺口 as ts_回补跳空向上缺口 # noqa
|
70
|
+
from polars_ta.tdx.pattern_feature import 均线多头排列 as ts_均线多头排列 # noqa
|
71
|
+
from polars_ta.tdx.pattern_feature import 均线空头排列 as ts_均线空头排列 # noqa
|
72
|
+
from polars_ta.tdx.pattern_feature import 天量法则 as ts_天量法则 # noqa
|
73
|
+
from polars_ta.tdx.pattern_feature import 强势整理 as ts_强势整理 # noqa
|
74
|
+
from polars_ta.tdx.pattern_feature import 揉搓线 as ts_揉搓线 # noqa
|
75
|
+
from polars_ta.tdx.pattern_feature import 早晨之星 as ts_早晨之星 # noqa
|
76
|
+
from polars_ta.tdx.pattern_feature import 旭日初升 as ts_旭日初升 # noqa
|
77
|
+
from polars_ta.tdx.pattern_feature import 突破 as ts_突破 # noqa
|
78
|
+
from polars_ta.tdx.pattern_feature import 老鸭头 as ts_老鸭头 # noqa
|
79
|
+
from polars_ta.tdx.pattern_feature import 蜻蜓点水 as ts_蜻蜓点水 # noqa
|
80
|
+
from polars_ta.tdx.pattern_feature import 跳空缺口选股 as ts_跳空缺口选股 # noqa
|
81
|
+
from polars_ta.tdx.pattern_feature import 近日创历史新低 as ts_近日创历史新低 # noqa
|
82
|
+
from polars_ta.tdx.pattern_feature import 近日创历史新高 as ts_近日创历史新高 # noqa
|
83
|
+
from polars_ta.tdx.pattern_feature import 高开大阴线 as ts_高开大阴线 # noqa
|
84
|
+
from polars_ta.tdx.pattern_feature import 鸳鸯底 as ts_鸳鸯底 # noqa
|
59
85
|
from polars_ta.tdx.pressure_support import BOLL as ts_BOLL # noqa
|
60
86
|
from polars_ta.tdx.pressure_support import BOLL_M as ts_BOLL_M # noqa
|
61
87
|
from polars_ta.tdx.reference import BARSLAST as ts_BARSLAST # noqa
|
62
88
|
from polars_ta.tdx.reference import BARSLASTCOUNT as ts_BARSLASTCOUNT # noqa
|
63
89
|
from polars_ta.tdx.reference import BARSSINCE as ts_BARSSINCE # noqa
|
64
90
|
from polars_ta.tdx.reference import BARSSINCEN as ts_BARSSINCEN # noqa
|
91
|
+
from polars_ta.tdx.reference import COUNT as ts_COUNT # noqa
|
65
92
|
from polars_ta.tdx.reference import CUMSUM as ts_CUMSUM # noqa
|
93
|
+
from polars_ta.tdx.reference import DIFF as ts_DIFF # noqa
|
66
94
|
from polars_ta.tdx.reference import DMA as ts_DMA # noqa
|
67
95
|
from polars_ta.tdx.reference import EMA as ts_EMA # noqa
|
68
96
|
from polars_ta.tdx.reference import EXPMA as ts_EXPMA # noqa
|
69
97
|
from polars_ta.tdx.reference import EXPMEMA as ts_EXPMEMA # noqa
|
70
98
|
from polars_ta.tdx.reference import FILTER as ts_FILTER # noqa
|
99
|
+
from polars_ta.tdx.reference import HHV as ts_HHV # noqa
|
100
|
+
from polars_ta.tdx.reference import HHVBARS as ts_HHVBARS # noqa
|
71
101
|
from polars_ta.tdx.reference import HOD as ts_HOD # noqa
|
102
|
+
from polars_ta.tdx.reference import LLV as ts_LLV # noqa
|
103
|
+
from polars_ta.tdx.reference import LLVBARS as ts_LLVBARS # noqa
|
72
104
|
from polars_ta.tdx.reference import LOD as ts_LOD # noqa
|
105
|
+
from polars_ta.tdx.reference import LOWRANGE # noqa
|
106
|
+
from polars_ta.tdx.reference import MA as ts_MA # noqa
|
73
107
|
from polars_ta.tdx.reference import MAX # noqa
|
74
108
|
from polars_ta.tdx.reference import MEMA as ts_MEMA # noqa
|
75
109
|
from polars_ta.tdx.reference import MIN # noqa
|
110
|
+
from polars_ta.tdx.reference import MULAR as ts_MULAR # noqa
|
76
111
|
from polars_ta.tdx.reference import RANGE # noqa
|
112
|
+
from polars_ta.tdx.reference import REF as ts_REF # noqa
|
113
|
+
from polars_ta.tdx.reference import REFX as ts_REFX # noqa
|
77
114
|
from polars_ta.tdx.reference import SMA_CN as ts_SMA_CN # noqa
|
115
|
+
from polars_ta.tdx.reference import SUM as ts_SUM # noqa
|
78
116
|
from polars_ta.tdx.reference import SUMIF as ts_SUMIF # noqa
|
79
117
|
from polars_ta.tdx.reference import TMA as ts_TMA # noqa
|
80
118
|
from polars_ta.tdx.reference import TR as ts_TR # noqa
|
119
|
+
from polars_ta.tdx.reference import WMA as ts_WMA # noqa
|
81
120
|
from polars_ta.tdx.statistic import AVEDEV as ts_AVEDEV # noqa
|
82
121
|
from polars_ta.tdx.statistic import COVAR as ts_COVAR # noqa
|
83
122
|
from polars_ta.tdx.statistic import DEVSQ as ts_DEVSQ # noqa
|
@@ -97,5 +136,34 @@ from polars_ta.tdx.trend import MINUS_DI as ts_MINUS_DI # noqa
|
|
97
136
|
from polars_ta.tdx.trend import MINUS_DM as ts_MINUS_DM # noqa
|
98
137
|
from polars_ta.tdx.trend import PLUS_DI as ts_PLUS_DI # noqa
|
99
138
|
from polars_ta.tdx.trend import PLUS_DM as ts_PLUS_DM # noqa
|
139
|
+
from polars_ta.tdx.trend_feature import N天内出现以涨停收盘 as ts_N天内出现以涨停收盘 # noqa
|
140
|
+
from polars_ta.tdx.trend_feature import N天内出现涨停 as ts_N天内出现涨停 # noqa
|
141
|
+
from polars_ta.tdx.trend_feature import N天内有跳空向上缺口 as ts_N天内有跳空向上缺口 # noqa
|
142
|
+
from polars_ta.tdx.trend_feature import N天内经常涨停 as ts_N天内经常涨停 # noqa
|
143
|
+
from polars_ta.tdx.trend_feature import N日内上涨多于下跌 as ts_N日内上涨多于下跌 # noqa
|
144
|
+
from polars_ta.tdx.trend_feature import N日内下跌多于上涨 as ts_N日内下跌多于上涨 # noqa
|
145
|
+
from polars_ta.tdx.trend_feature import N日内创新低 as ts_N日内创新低 # noqa
|
146
|
+
from polars_ta.tdx.trend_feature import N日内创新高 as ts_N日内创新高 # noqa
|
147
|
+
from polars_ta.tdx.trend_feature import N日内阳线多于阴线 as ts_N日内阳线多于阴线 # noqa
|
148
|
+
from polars_ta.tdx.trend_feature import N日内阴线多于阳线 as ts_N日内阴线多于阳线 # noqa
|
149
|
+
from polars_ta.tdx.trend_feature import 下跌多日再放量上涨 as ts_下跌多日再放量上涨 # noqa
|
150
|
+
from polars_ta.tdx.trend_feature import 价量渐低后阳包阴 as ts_价量渐低后阳包阴 # noqa
|
151
|
+
from polars_ta.tdx.trend_feature import 单日放量 as ts_单日放量 # noqa
|
152
|
+
from polars_ta.tdx.trend_feature import 小步碎阳 as ts_小步碎阳 # noqa
|
153
|
+
from polars_ta.tdx.trend_feature import 平台整理 as ts_平台整理 # noqa
|
154
|
+
from polars_ta.tdx.trend_feature import 拉升后多日调整 as ts_拉升后多日调整 # noqa
|
155
|
+
from polars_ta.tdx.trend_feature import 持续放量 as ts_持续放量 # noqa
|
156
|
+
from polars_ta.tdx.trend_feature import 持续缩量 as ts_持续缩量 # noqa
|
157
|
+
from polars_ta.tdx.trend_feature import 放量上攻 as ts_放量上攻 # noqa
|
158
|
+
from polars_ta.tdx.trend_feature import 昨日底部十字星 as ts_昨日底部十字星 # noqa
|
159
|
+
from polars_ta.tdx.trend_feature import 温和放量上攻 as ts_温和放量上攻 # noqa
|
160
|
+
from polars_ta.tdx.trend_feature import 突然放量 as ts_突然放量 # noqa
|
161
|
+
from polars_ta.tdx.trend_feature import 突破长期盘整 as ts_突破长期盘整 # noqa
|
162
|
+
from polars_ta.tdx.trend_feature import 跳空高开或低开 as ts_跳空高开或低开 # noqa
|
163
|
+
from polars_ta.tdx.trend_feature import 连续N天收阳线 as ts_连续N天收阳线 # noqa
|
164
|
+
from polars_ta.tdx.trend_feature import 连续N天收阴线 as ts_连续N天收阴线 # noqa
|
165
|
+
from polars_ta.tdx.trend_feature import 间隔放量 as ts_间隔放量 # noqa
|
166
|
+
from polars_ta.tdx.trend_feature import 阶段放量 as ts_阶段放量 # noqa
|
167
|
+
from polars_ta.tdx.trend_feature import 阶段缩量 as ts_阶段缩量 # noqa
|
100
168
|
from polars_ta.tdx.volume import OBV as ts_OBV # noqa
|
101
169
|
from polars_ta.tdx.volume import VR as ts_VR # noqa
|
@@ -4,8 +4,11 @@ from polars_ta.tdx.energy import * # noqa
|
|
4
4
|
from polars_ta.tdx.logical import * # noqa
|
5
5
|
from polars_ta.tdx.moving_average import * # noqa
|
6
6
|
from polars_ta.tdx.over_bought_over_sold import * # noqa
|
7
|
+
from polars_ta.tdx.pattern import * # noqa
|
8
|
+
from polars_ta.tdx.pattern_feature import * # noqa
|
7
9
|
from polars_ta.tdx.pressure_support import * # noqa
|
8
10
|
from polars_ta.tdx.reference import * # noqa
|
9
11
|
from polars_ta.tdx.statistic import * # noqa
|
10
12
|
from polars_ta.tdx.trend import * # noqa
|
13
|
+
from polars_ta.tdx.trend_feature import * # noqa
|
11
14
|
from polars_ta.tdx.volume import * # noqa
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import numba
|
2
|
+
import numpy as np
|
3
|
+
|
4
|
+
|
5
|
+
@numba.jit(nopython=True, nogil=True, fastmath=True, cache=True)
|
6
|
+
def nb_chip(high, low, avg, turnover,
|
7
|
+
start=None, stop=None, step=0.2):
|
8
|
+
"""筹码分布,可用于WINNER或COST指标
|
9
|
+
|
10
|
+
不可能完全还原真实的筹码分布,只能接近。所以做了一下特别处理
|
11
|
+
|
12
|
+
1. 三角分布,比平均分布更接近
|
13
|
+
2. 步长。没有必要每个价格都统计,特别是复权后价格也无法正好是0.01间隔
|
14
|
+
高价股建议步长设大些,低价股步长需设小些
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
----------
|
18
|
+
high
|
19
|
+
low
|
20
|
+
avg
|
21
|
+
一维序列
|
22
|
+
turnover:
|
23
|
+
换手率,需要在外转成0~1范围内
|
24
|
+
start
|
25
|
+
开始价格
|
26
|
+
stop
|
27
|
+
结束价格
|
28
|
+
step
|
29
|
+
步长。一字涨停时,三角分布的底为1,高为2。但无法当成梯形计算面积,所以从中用半步长切开计算
|
30
|
+
|
31
|
+
Returns
|
32
|
+
-------
|
33
|
+
out
|
34
|
+
筹码分布
|
35
|
+
columns
|
36
|
+
价格表头
|
37
|
+
|
38
|
+
"""
|
39
|
+
# 网格范围
|
40
|
+
if start is None:
|
41
|
+
start = np.min(low)
|
42
|
+
if stop is None:
|
43
|
+
stop = np.max(high)
|
44
|
+
|
45
|
+
left = round(start / step) * 2 - 1
|
46
|
+
right = round(stop / step) * 2 + 1
|
47
|
+
|
48
|
+
# 最小最大值左右要留半格,range是左闭右开,长度必须为2n+1
|
49
|
+
columns = np.arange(left, right + 1)
|
50
|
+
grid_shape = (len(turnover), len(columns))
|
51
|
+
|
52
|
+
# numba中round写法特殊
|
53
|
+
_high = np.empty_like(high)
|
54
|
+
_low = np.empty_like(low)
|
55
|
+
_avg = np.empty_like(avg)
|
56
|
+
|
57
|
+
# high和low必须落到边缘上
|
58
|
+
_high = np.round(high / step, 0, _high) * 2 + 1
|
59
|
+
_low = np.round(low / step, 0, _low) * 2 - 1
|
60
|
+
# avg必须落在实体上
|
61
|
+
_avg = np.round(avg / step, 0, _avg) * 2
|
62
|
+
tri_height = 2 / ((_high - _low) // 2) # 三角形高度
|
63
|
+
|
64
|
+
# 得到三组值在网格中的位置
|
65
|
+
high_arg = np.argwhere(columns == _high.reshape(-1, 1))[:, 1]
|
66
|
+
avg_arg = np.argwhere(columns == _avg.reshape(-1, 1))[:, 1]
|
67
|
+
low_arg = np.argwhere(columns == _low.reshape(-1, 1))[:, 1]
|
68
|
+
|
69
|
+
# 高度表
|
70
|
+
height = np.zeros(grid_shape)
|
71
|
+
for i in range(len(height)):
|
72
|
+
la = low_arg[i]
|
73
|
+
aa = avg_arg[i]
|
74
|
+
ha = high_arg[i]
|
75
|
+
th = tri_height[i]
|
76
|
+
height[i, la:aa + 1] = np.linspace(0, th, aa - la + 1)
|
77
|
+
height[i, aa:ha + 1] = np.linspace(th, 0, ha - aa + 1)
|
78
|
+
|
79
|
+
# 计算半块面积, 三角形的高变成了梯形的上下底,梯形高固定为0.5,*0.5/2=/4
|
80
|
+
# 宽度-1,例如,原长度为5,-1后为4
|
81
|
+
area = (height[:, :-1] + height[:, 1:]) / 4
|
82
|
+
# 合成一块。宽度/2,例如原长度为4,/2后为2
|
83
|
+
weight = area[:, ::2] + area[:, 1::2]
|
84
|
+
|
85
|
+
# 输出
|
86
|
+
out = np.zeros_like(weight)
|
87
|
+
# 剩余换手率
|
88
|
+
turnover2 = 1 - turnover
|
89
|
+
# 第一天其实应当用上市发行价,过于麻烦,还是将第一天等权
|
90
|
+
# 取巧方法,利用-1的特性,可减少if判断,
|
91
|
+
out[-1] = weight[0]
|
92
|
+
# 这里现在用的numpy, 还要快可考虑numba
|
93
|
+
for i in range(len(turnover)):
|
94
|
+
out[i] = out[i - 1] * turnover2[i] + weight[i] * turnover[i]
|
95
|
+
|
96
|
+
# print(out.sum(axis=1))
|
97
|
+
return out, (step / 2) * columns[1::2]
|
98
|
+
|
99
|
+
|
100
|
+
@numba.jit(nopython=True, nogil=True, fastmath=True, cache=True)
|
101
|
+
def _WINNER_COST(high, low, avg, turnover, close, cost, step):
|
102
|
+
out, columns = nb_chip(high, low, avg, turnover, step=step)
|
103
|
+
|
104
|
+
# WINNER
|
105
|
+
cheap = np.where(columns <= close.reshape(-1, 1), out, 0)
|
106
|
+
sum_cheap = np.sum(cheap, axis=1)
|
107
|
+
|
108
|
+
# COST
|
109
|
+
# cum = np.cumsum(out, axis=1)
|
110
|
+
cum = np.copy(out)
|
111
|
+
for i in range(0, out.shape[0]):
|
112
|
+
cum[i, :] = np.cumsum(out[i, :])
|
113
|
+
|
114
|
+
prices = np.where(cum <= cost.reshape(-1, 1), columns, 0)
|
115
|
+
|
116
|
+
# np.max(prices, axis=1)
|
117
|
+
max_price = prices[:, 0]
|
118
|
+
for i in range(0, out.shape[0]):
|
119
|
+
max_price[i] = np.max(prices[i, :])
|
120
|
+
|
121
|
+
return sum_cheap, max_price
|
@@ -15,22 +15,25 @@ def CROSS(a: Expr, b: Expr) -> Expr:
|
|
15
15
|
'a': [None, -1, 1, 1, 2],
|
16
16
|
'b': [None, -1, 0, 1, 2],
|
17
17
|
'c': [None, 0, 0, 0, 0],
|
18
|
+
'd': [None, False, False, True, True],
|
18
19
|
}).with_columns(
|
19
20
|
out1=CROSS(pl.col('a'), pl.col('c')),
|
20
21
|
out2=CROSS(pl.col('b'), pl.col('c')),
|
22
|
+
out3=CROSS(0, pl.col('b')),
|
23
|
+
out4=CROSS(pl.col('d'), 0.5),
|
21
24
|
)
|
22
|
-
shape: (5,
|
23
|
-
|
24
|
-
│ a ┆ b ┆ c ┆ out1 ┆ out2 │
|
25
|
-
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
26
|
-
│ i64 ┆ i64 ┆ i64 ┆ bool ┆ bool │
|
27
|
-
|
28
|
-
│ null ┆ null ┆ null ┆ null ┆ null │
|
29
|
-
│ -1 ┆ -1 ┆ 0 ┆ false ┆ false │
|
30
|
-
│ 1 ┆ 0 ┆ 0 ┆ true ┆ false │
|
31
|
-
│ 1 ┆ 1 ┆ 0 ┆ false ┆ true │
|
32
|
-
│ 2 ┆ 2 ┆ 0 ┆ false ┆ false │
|
33
|
-
|
25
|
+
shape: (5, 8)
|
26
|
+
┌──────┬──────┬──────┬───────┬───────┬───────┬───────┬───────┐
|
27
|
+
│ a ┆ b ┆ c ┆ d ┆ out1 ┆ out2 ┆ out3 ┆ out4 │
|
28
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
29
|
+
│ i64 ┆ i64 ┆ i64 ┆ bool ┆ bool ┆ bool ┆ bool ┆ bool │
|
30
|
+
╞══════╪══════╪══════╪═══════╪═══════╪═══════╪═══════╪═══════╡
|
31
|
+
│ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ null │
|
32
|
+
│ -1 ┆ -1 ┆ 0 ┆ false ┆ false ┆ false ┆ null ┆ false │
|
33
|
+
│ 1 ┆ 0 ┆ 0 ┆ false ┆ true ┆ false ┆ false ┆ false │
|
34
|
+
│ 1 ┆ 1 ┆ 0 ┆ true ┆ false ┆ true ┆ false ┆ true │
|
35
|
+
│ 2 ┆ 2 ┆ 0 ┆ true ┆ false ┆ false ┆ false ┆ false │
|
36
|
+
└──────┴──────┴──────┴───────┴───────┴───────┴───────┴───────┘
|
34
37
|
```
|
35
38
|
|
36
39
|
"""
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from polars import Expr, Struct, Field, Float64, struct
|
2
|
+
|
3
|
+
from polars_ta.tdx._chip import _WINNER_COST
|
4
|
+
from polars_ta.utils.numba_ import batches_i2_o2
|
5
|
+
|
6
|
+
|
7
|
+
def ts_WINNER_COST(high: Expr, low: Expr, avg: Expr, turnover: Expr, close: Expr, cost: Expr = 0.5, step: float = 0.1) -> Expr:
|
8
|
+
"""
|
9
|
+
获利盘比例
|
10
|
+
WINNER(CLOSE),表示以当前收市价卖出的获利盘比例,例如返回0.1表示10%获利盘;WINNER(10.5)表示10.5元价格的获利盘比例
|
11
|
+
|
12
|
+
成本分布价
|
13
|
+
COST(10),表示10%获利盘的价格是多少,即有10%的持仓量在该价格以下,其余90%在该价格以上,为套牢盘
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
high
|
18
|
+
最高价
|
19
|
+
low
|
20
|
+
最低价
|
21
|
+
avg
|
22
|
+
平均价。可以用vwap
|
23
|
+
turnover:
|
24
|
+
换手率。需要在外转成0~1范围内
|
25
|
+
close
|
26
|
+
判断获利比例的价格,可以用收盘价,也可以用均价
|
27
|
+
cost
|
28
|
+
成本比例,0~1
|
29
|
+
step
|
30
|
+
步长。一字涨停时,三角分布的底为1,高为2。但无法当成梯形计算面积,所以从中用半步长切开计算
|
31
|
+
|
32
|
+
Returns
|
33
|
+
-------
|
34
|
+
winner
|
35
|
+
获利盘比例
|
36
|
+
cost
|
37
|
+
成本分布价
|
38
|
+
|
39
|
+
Examples
|
40
|
+
--------
|
41
|
+
>>> WINNER_COST = ts_WINNER_COST(HIGH, LOW, VWAP, turnover_ratio / 100, CLOSE, 0.5)
|
42
|
+
|
43
|
+
Notes
|
44
|
+
-----
|
45
|
+
该函数仅对日线分析周期有效
|
46
|
+
|
47
|
+
"""
|
48
|
+
dtype = Struct([Field(f"column_{i}", Float64) for i in range(2)])
|
49
|
+
return struct([high, low, avg, turnover, close, cost]).map_batches(lambda xx: batches_i2_o2([xx.struct[i].to_numpy().astype(float) for i in range(6)], _WINNER_COST, step), return_dtype=dtype)
|
@@ -0,0 +1,236 @@
|
|
1
|
+
from polars import Expr
|
2
|
+
|
3
|
+
from polars_ta.tdx.arithmetic import ABS, BETWEEN
|
4
|
+
from polars_ta.tdx.arithmetic import MAX
|
5
|
+
from polars_ta.tdx.arithmetic import MIN
|
6
|
+
from polars_ta.tdx.choice import IF
|
7
|
+
from polars_ta.tdx.logical import EVERY, CROSS, LAST, EXIST, NOT
|
8
|
+
from polars_ta.tdx.reference import COUNT, BARSLASTCOUNT, BARSLAST, EMA, FILTER, LOWRANGE
|
9
|
+
from polars_ta.tdx.reference import HHV
|
10
|
+
from polars_ta.tdx.reference import LLV
|
11
|
+
from polars_ta.tdx.reference import MA
|
12
|
+
from polars_ta.tdx.reference import REF
|
13
|
+
from polars_ta.wq.time_series import ts_cum_max, ts_cum_min
|
14
|
+
|
15
|
+
|
16
|
+
def 早晨之星(OPEN: Expr, CLOSE: Expr) -> Expr:
|
17
|
+
"""MSTAR 早晨之星"""
|
18
|
+
A1 = REF(CLOSE, 2) / REF(OPEN, 2) < 0.95
|
19
|
+
A2 = REF(OPEN, 1) < REF(CLOSE, 2)
|
20
|
+
A3 = ABS(REF(OPEN, 1) - REF(CLOSE, 1)) / REF(CLOSE, 1) < 0.03
|
21
|
+
A4 = CLOSE / OPEN > 1.05
|
22
|
+
A5 = CLOSE > REF(CLOSE, 2)
|
23
|
+
return A1 & A2 & A3 & A4 & A5
|
24
|
+
|
25
|
+
|
26
|
+
def 剑(OPEN: Expr, HIGH: Expr, LOW: Expr, CLOSE: Expr, VOL: Expr, CAPITAL: Expr) -> Expr:
|
27
|
+
"""SWORD 剑"""
|
28
|
+
AA = (VOL > REF(VOL, 1)) | (VOL > CAPITAL)
|
29
|
+
BB = (OPEN >= REF(HIGH, 1)) & (REF(HIGH, 1) > REF(HIGH, 2) * 1.06)
|
30
|
+
CC = CLOSE > (REF(CLOSE, 1) - REF(CLOSE, 1) * 0.01)
|
31
|
+
DD = (CLOSE < HIGH * 0.965) & (HIGH > OPEN * 1.05)
|
32
|
+
EE = (LOW < OPEN) & (LOW < CLOSE) & (HIGH > REF(CLOSE, 1) * 1.06)
|
33
|
+
FF = (HIGH - MAX(OPEN, CLOSE)) / 2 > (MIN(OPEN, CLOSE) - LOW)
|
34
|
+
GG = (ABS(OPEN - CLOSE)) / 2 < (MIN(OPEN, CLOSE) - LOW)
|
35
|
+
return AA & BB & CC & DD & EE & FF & GG
|
36
|
+
|
37
|
+
|
38
|
+
def 天量法则(OPEN: Expr, CLOSE: Expr) -> Expr:
|
39
|
+
"""TLFZ 天量法则"""
|
40
|
+
A1 = CLOSE > OPEN
|
41
|
+
A2 = HHV(CLOSE, 50) == CLOSE
|
42
|
+
# DYNAINFO(37) > 0.1 & &
|
43
|
+
# DYNAINFO(13) < 0.14;
|
44
|
+
raise
|
45
|
+
|
46
|
+
|
47
|
+
def 四串阴(OPEN: Expr, CLOSE: Expr) -> Expr:
|
48
|
+
"""GREEN4 四串阴"""
|
49
|
+
return EVERY(CLOSE < OPEN, 4)
|
50
|
+
|
51
|
+
|
52
|
+
def 四串阳(OPEN: Expr, CLOSE: Expr) -> Expr:
|
53
|
+
"""RED4 四串阳"""
|
54
|
+
return EVERY(CLOSE > OPEN, 4)
|
55
|
+
|
56
|
+
|
57
|
+
def 鸳鸯底(O: Expr, LOW: Expr, C: Expr, V: Expr, N: int = 50) -> Expr:
|
58
|
+
"""YYD 鸳鸯底"""
|
59
|
+
return (C > O) & (REF(C, 1) < REF(O, 1)) & (C > REF(O, 1)) & (V > REF(V, 1)) & EXIST(LOWRANGE(LOW) > N, 3)
|
60
|
+
|
61
|
+
|
62
|
+
def 出水芙蓉(OPEN: Expr, CLOSE: Expr, S: int = 20, M: int = 40, N: int = 60) -> Expr:
|
63
|
+
"""CSFR 出水芙蓉"""
|
64
|
+
AAA = CLOSE > OPEN
|
65
|
+
BBB = AAA & (CLOSE > MA(CLOSE, S)) & (CLOSE > MA(CLOSE, M)) & (CLOSE > MA(CLOSE, N))
|
66
|
+
CCC = BBB & (OPEN < MA(CLOSE, M)) & (OPEN < MA(CLOSE, N))
|
67
|
+
return CCC & (CLOSE - OPEN > 0.0618 * CLOSE)
|
68
|
+
|
69
|
+
|
70
|
+
def 出水芙蓉II(C: Expr, V: Expr, N: float = 0.05, M: float = 2.0) -> Expr:
|
71
|
+
"""CSFR2 出水芙蓉II"""
|
72
|
+
ZF = C / REF(C, 1)
|
73
|
+
FLTJ = V > REF(V, 1) * M
|
74
|
+
A1 = CROSS(C, MA(C, 5)) & CROSS(C, MA(C, 10)) & CROSS(C, MA(C, 20)) & CROSS(C, MA(C, 60))
|
75
|
+
return (ZF > 1 + N) & FLTJ & A1
|
76
|
+
|
77
|
+
|
78
|
+
def 近日创历史新高(HIGH: Expr, N: int = 3, M: int = 0) -> Expr:
|
79
|
+
"""NHIGH 近日创历史新高"""
|
80
|
+
if M == 0:
|
81
|
+
return HHV(HIGH, N) == ts_cum_max(HIGH)
|
82
|
+
else:
|
83
|
+
return HHV(HIGH, N) == HHV(HIGH, M)
|
84
|
+
|
85
|
+
|
86
|
+
def 近日创历史新低(LOW: Expr, N: int = 3, M: int = 0) -> Expr:
|
87
|
+
"""NLOW 近日创历史新低"""
|
88
|
+
if M == 0:
|
89
|
+
return LLV(LOW, N) == ts_cum_min(LOW)
|
90
|
+
else:
|
91
|
+
return LLV(LOW, N) == LLV(LOW, M)
|
92
|
+
|
93
|
+
|
94
|
+
def 旭日初升(CLOSE: Expr, VOL: Expr, N: int = 120) -> Expr:
|
95
|
+
"""XRDS 旭日初升"""
|
96
|
+
BUY1 = LAST(CLOSE < MA(CLOSE, N), 0, 5)
|
97
|
+
return (CLOSE > MA(CLOSE, N)) & (VOL > MA(VOL, 5) * 2) & BUY1
|
98
|
+
|
99
|
+
|
100
|
+
def 蜻蜓点水(CLOSE: Expr, N: int = 120) -> Expr:
|
101
|
+
"""QTDS 蜻蜓点水"""
|
102
|
+
BUY1 = LAST(CLOSE > MA(CLOSE, N), 0, 5)
|
103
|
+
BUY2 = EXIST(CLOSE < MA(CLOSE, N), 5)
|
104
|
+
return (CLOSE > MA(CLOSE, N)) & BUY1 & BUY2
|
105
|
+
|
106
|
+
|
107
|
+
def 均线多头排列(OPEN: Expr, CLOSE: Expr, N: int = 5, N1: int = 10, N2: int = 20, N3: int = 30) -> Expr:
|
108
|
+
"""DTPL 均线多头排列"""
|
109
|
+
A1 = MA(CLOSE, N)
|
110
|
+
A2 = MA(CLOSE, N1)
|
111
|
+
A3 = MA(CLOSE, N2)
|
112
|
+
A4 = MA(CLOSE, N3)
|
113
|
+
return (CLOSE > A1) & (A1 > A2) & (A2 > A3) & (A3 > A4) & (CLOSE > OPEN)
|
114
|
+
|
115
|
+
|
116
|
+
def 均线空头排列(OPEN: Expr, CLOSE: Expr, N: int = 5, N1: int = 10, N2: int = 20, N3: int = 30) -> Expr:
|
117
|
+
"""KTPL 均线空头排列"""
|
118
|
+
A1 = MA(CLOSE, N)
|
119
|
+
A2 = MA(CLOSE, N1)
|
120
|
+
A3 = MA(CLOSE, N2)
|
121
|
+
A4 = MA(CLOSE, N3)
|
122
|
+
return (CLOSE < A1) & (A1 < A2) & (A2 < A3) & (A3 < A4) & (CLOSE < OPEN)
|
123
|
+
|
124
|
+
|
125
|
+
def 强势整理(OPEN: Expr, CLOSE: Expr, N: int = 2, M: float = 0.05) -> Expr:
|
126
|
+
"""QSZL 强势整理"""
|
127
|
+
A1 = ABS(CLOSE - OPEN) / OPEN < 0.015
|
128
|
+
A2 = COUNT(A1, N) == N
|
129
|
+
A3 = (REF(OPEN, N) < REF(CLOSE, N)) & (REF(CLOSE, N) / REF(CLOSE, N + 1) > 1 + M)
|
130
|
+
return A2 & A3
|
131
|
+
|
132
|
+
|
133
|
+
def 高开大阴线(OPEN: Expr, CLOSE: Expr, N: float = 0.06, M: float = 0.04) -> Expr:
|
134
|
+
"""W103 高开大阴线"""
|
135
|
+
A1 = OPEN / REF(CLOSE, 1) >= 1 + M
|
136
|
+
A2 = CLOSE / OPEN <= 1 - N
|
137
|
+
return A1 & A2
|
138
|
+
|
139
|
+
|
140
|
+
def 低开大阳线(OPEN: Expr, CLOSE: Expr, N: float = 0.06, M: float = 0.04) -> Expr:
|
141
|
+
"""W104 低开大阳线"""
|
142
|
+
A1 = OPEN / REF(CLOSE, 1) <= 1 - M
|
143
|
+
A2 = CLOSE / OPEN >= 1 + N
|
144
|
+
return A1 & A2
|
145
|
+
|
146
|
+
|
147
|
+
def 跳空缺口选股(HIGH: Expr, LOW: Expr) -> Expr:
|
148
|
+
"""W105 跳空缺口选股"""
|
149
|
+
A1 = HIGH < (REF(LOW, 1) - 0.001)
|
150
|
+
A2 = LOW > (REF(HIGH, 1) + 0.001)
|
151
|
+
return A1 | A2
|
152
|
+
|
153
|
+
|
154
|
+
def 单阳不破选股(O: Expr, H: Expr, L: Expr, C: Expr, N1: int = 2, N2: int = 7) -> Expr:
|
155
|
+
"""W106 单阳不破选股
|
156
|
+
"""
|
157
|
+
A0 = ((C > O * 1.08) | (C > REF(C, 1) * 1.08)) & NOT(H == L) & NOT(H == C & H == O) # {大阳超8%,排除当天一字、T字板}
|
158
|
+
A1 = A0 & BARSLASTCOUNT(A0) == 1
|
159
|
+
A2 = BARSLAST(A1) # {距离大阳几根K}
|
160
|
+
ZCX = REF(O, A2) # {获取大阳位置的开盘价作为支撑线}
|
161
|
+
ZHX = REF(C, A2) # {获取大阳位置的收盘价作为选股最高区间}
|
162
|
+
ZD = LLV(L, A2) # {大阳之后的最低价}
|
163
|
+
ZH = HHV(H, A2) # {大阳之后的最高价}
|
164
|
+
A3 = BARSLASTCOUNT(ZD >= ZCX)
|
165
|
+
return (A3 <= N2) & (A3 > N1) & BETWEEN(C, ZCX, ZHX) & (ZH < ZHX) & (A2 > 0)
|
166
|
+
|
167
|
+
|
168
|
+
def 回补跳空向上缺口(O: Expr, H: Expr, L: Expr, C: Expr, N1: int = 2, N2: int = 7) -> Expr:
|
169
|
+
"""W107 回补跳空向上缺口"""
|
170
|
+
raise
|
171
|
+
|
172
|
+
|
173
|
+
def 揉搓线(O: Expr, H: Expr, L: Expr, C: Expr, V: Expr, N: int = 50) -> Expr:
|
174
|
+
"""RUBLINE 揉搓线
|
175
|
+
"""
|
176
|
+
A1 = (REF(H, 1) - MAX(REF(C, 1), REF(O, 1))) / (REF(H, 1) - REF(L, 1)) * 100 > N # {上影线占K线的N % 以上}
|
177
|
+
A2 = (MIN(O, C) - L) / (H - L) * 100 > N # {下影线占K线的N % 以上}
|
178
|
+
A3 = ABS(C - REF(C, 1)) / MIN(C, REF(C, 1)) * 100 < 2 # {下影K的跌幅不能超过2 %}
|
179
|
+
A4 = REF(C, 2) > REF(C, 3) # {揉搓形态前收涨}
|
180
|
+
A5 = V < REF(V, 1) # {缩量}
|
181
|
+
return A1 & A2 & A3 & A4 & A5
|
182
|
+
|
183
|
+
|
184
|
+
def 老鸭头(L: Expr, C: Expr, V: Expr) -> Expr:
|
185
|
+
"""OLDDUCK 老鸭头
|
186
|
+
"""
|
187
|
+
E1 = EMA(C, 13)
|
188
|
+
E2 = EMA(C, 55)
|
189
|
+
A1 = (COUNT(E1 < REF(E1, 1), 5) >= 3) & (E1 > REF(E1, 1))
|
190
|
+
A2 = (COUNT(E2 > REF(E2, 1), 13) >= 8) & (E2 < REF(E2, 1))
|
191
|
+
A3 = LLV((L / E2 - 1), 13) <= 0.1
|
192
|
+
A4 = COUNT(E1 > E2, 13) == 13
|
193
|
+
A5 = COUNT(C > E2, 5) == 5
|
194
|
+
A6 = CROSS(C, E1)
|
195
|
+
A7 = V > MA(V, 5)
|
196
|
+
YT = A1 & A2 & A3 & A4 & A5 & A6 & A7
|
197
|
+
LYT = FILTER(YT, 10)
|
198
|
+
# FXG:=FINANCE(42)>100;
|
199
|
+
# NTP:=DYNAINFO(8)>0;
|
200
|
+
# LYT AND FXG AND NTP;
|
201
|
+
return LYT
|
202
|
+
|
203
|
+
|
204
|
+
def 仙人指路(O: Expr, H: Expr, C: Expr) -> Expr:
|
205
|
+
"""WISEWAY 仙人指路
|
206
|
+
"""
|
207
|
+
TUPO = 0.5 * (C + H) > HHV(REF(C, 1), 60)
|
208
|
+
SSQS = (MA(C, 5) > MA(C, 60)) & (MA(C, 10) > MA(C, 60))
|
209
|
+
YINX = ((H - MAX(O, C)) / REF(C, 1) > 0.045) & (ABS(C - O) / REF(C, 1) < 0.035) & ((H - MAX(O, C)) > 2.0 * ABS(C - O))
|
210
|
+
QIANG1 = (REF(C, 1) / REF(C, 6) > 1.04) & (REF(C, 1) / REF(C, 6) < 1.18)
|
211
|
+
QIANG2 = (REF(C, 1) / REF(C, 6) > 1.04) & (REF(C, 1) / REF(C, 6) < 1.27)
|
212
|
+
QIANG = IF(True, QIANG2, QIANG1) # TODO 要改
|
213
|
+
QIANK = (REF((H - C), 1) / REF(C, 2) < 1.045) & (REF(C, 1) / REF(C, 2) > 0.97)
|
214
|
+
return TUPO & SSQS & YINX & QIANG & QIANK
|
215
|
+
|
216
|
+
|
217
|
+
def 低点搜寻(HIGH: Expr, LOW: Expr, CLOSE: Expr, N: int = 5) -> Expr:
|
218
|
+
"""SP 低点搜寻"""
|
219
|
+
W = MA((LLV(LOW, 45) - CLOSE) / (HHV(HIGH, 45) - LLV(LOW, 45)), N)
|
220
|
+
return CROSS(-0.05, W)
|
221
|
+
|
222
|
+
|
223
|
+
def 突破(C: Expr, N1: int = 5, N2: int = 10, N3: int = 30) -> Expr:
|
224
|
+
"""TP 突破"""
|
225
|
+
M1 = MA(C, N1) # {短期参数:5}
|
226
|
+
M2 = MA(C, N2) # {中期参数:10}
|
227
|
+
M3 = MA(C, N3) # {长期参数:30}
|
228
|
+
# {以下计算交叉点距今的天数}
|
229
|
+
D1 = BARSLAST(CROSS(M1, M2)) # {短上穿中}
|
230
|
+
D2 = BARSLAST(CROSS(M1, M3)) # {短上穿长}
|
231
|
+
D3 = BARSLAST(CROSS(M2, M3)) # {中上穿长}
|
232
|
+
T1 = CROSS(M2, M3) # {今天中线上穿长线}
|
233
|
+
T2 = (D1 >= D2) & (D2 >= D3) # {交叉按指定的先后出现}
|
234
|
+
T3 = COUNT(CROSS(M2, M1) | CROSS(M3, M2) | CROSS(M3, M1), D1) == 0 # {中间无夹杂其它交叉}
|
235
|
+
T4 = REF(M1 < M3 & M2 < M3, D1 + 1) # {短上穿中前一天短、中线在长线之下}
|
236
|
+
return T1 & T2 & T3 & T4 # {价托确定};
|
@@ -128,6 +128,12 @@ def LOD(close: Expr, N: int = 30) -> Expr:
|
|
128
128
|
return close.map_batches(lambda a: roll_rank(a, N, pct=False, ascending=True))
|
129
129
|
|
130
130
|
|
131
|
+
def LOWRANGE(close: Expr) -> Expr:
|
132
|
+
"""rolling rank of each data in ascending order
|
133
|
+
LOD(X,N):求当前X数据是N周期内的第几个低值"""
|
134
|
+
raise
|
135
|
+
|
136
|
+
|
131
137
|
def MEMA(close: Expr, N: int = 30) -> Expr:
|
132
138
|
"""Exponential moving average given N
|
133
139
|
Y = X / N + last_Y * (N-1) / N
|
@@ -154,7 +160,7 @@ def SMA_CN(X: Expr, N: int, M: int) -> Expr:
|
|
154
160
|
|
155
161
|
|
156
162
|
def SUMIF(condition: Expr, close: Expr, N: int = 30) -> Expr:
|
157
|
-
return SUM(condition.cast(Int32) * close, N)
|
163
|
+
return SUM(condition.cast(Boolean).cast(Int32) * close, N)
|
158
164
|
|
159
165
|
|
160
166
|
def TMA(close: Expr, N: int = 30) -> Expr:
|
@@ -164,3 +170,8 @@ def TMA(close: Expr, N: int = 30) -> Expr:
|
|
164
170
|
|
165
171
|
def FILTER(close: Expr, N: int = 30) -> Expr:
|
166
172
|
raise
|
173
|
+
|
174
|
+
|
175
|
+
def REFX(close: Expr, N: int = 30) -> Expr:
|
176
|
+
"""属于未来函数,引用若干周期后的数据"""
|
177
|
+
return REF(close, -N)
|