expr-codegen 0.7.1__tar.gz → 0.7.2__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.
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/PKG-INFO +42 -40
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/README.md +41 -39
- expr_codegen-0.7.2/expr_codegen/_version.py +1 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/polars/printer.py +1 -1
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen.egg-info/PKG-INFO +42 -40
- expr_codegen-0.7.1/expr_codegen/_version.py +0 -1
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/LICENSE +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/__init__.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/codes.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/dag.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/expr.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/latex/__init__.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/latex/printer.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/model.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/pandas/__init__.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/pandas/code.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/pandas/printer.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/pandas/template.py.j2 +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/polars/__init__.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/polars/code.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/polars/template.py.j2 +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen/tool.py +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen.egg-info/SOURCES.txt +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen.egg-info/dependency_links.txt +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen.egg-info/requires.txt +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/expr_codegen.egg-info/top_level.txt +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/pyproject.toml +0 -0
- {expr_codegen-0.7.1 → expr_codegen-0.7.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: expr_codegen
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: symbol expression to polars expression tool
|
|
5
5
|
Author-email: wukan <wu-kan@163.com>
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -90,28 +90,28 @@ from expr_codegen.tool import codegen_exec
|
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
def _code_block_1():
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
# 因子编辑区,可利用IDE的智能提示在此区域编辑因子
|
|
94
|
+
LOG_MC_ZS = cs_mad_zscore(log1p(market_cap))
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
def _code_block_2():
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
# 模板中已经默认导入了from polars_ta.prefix下大量的算子,但
|
|
99
|
+
# talib在模板中没有默认导入。这种写法可实现在生成的代码中导入
|
|
100
|
+
from polars_ta.prefix.talib import ts_LINEARREG_SLOPE # noqa
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
# 1. 下划线开头的变量只是中间变量,会被自动更名,最终输出时会被剔除
|
|
103
|
+
# 2. 下划线开头的变量可以重复使用。多个复杂因子多行书写时有重复中间变时不再冲突
|
|
104
|
+
_avg = ts_mean(corr, 20)
|
|
105
|
+
_std = ts_std_dev(corr, 20)
|
|
106
|
+
_beta = ts_LINEARREG_SLOPE(corr, 20)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
# 3. 下划线开头的变量有环循环赋值。在调试时可快速用注释进行切换
|
|
109
|
+
_avg = cs_mad_zscore_resid(_avg, LOG_MC_ZS, ONE)
|
|
110
|
+
_std = cs_mad_zscore_resid(_std, LOG_MC_ZS, ONE)
|
|
111
|
+
# _beta = cs_mad_zscore_resid(_beta, LOG_MC_ZS, ONE)
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
_corr = cs_zscore(_avg) + cs_zscore(_std)
|
|
114
|
+
CPV = cs_zscore(_corr) + cs_zscore(_beta)
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
df = None # 替换成真实的polars数据
|
|
@@ -189,10 +189,12 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
189
189
|
2. 然后`printer.py`有可能需要添加对应函数的打印代码
|
|
190
190
|
- 注意:需要留意是否要加括号`()`,不加时可能优先级混乱,可以每次都加括号,也可用提供的`parenthesize`简化处理
|
|
191
191
|
|
|
192
|
-
##
|
|
192
|
+
## `expr_codegen`局限性
|
|
193
193
|
|
|
194
|
-
1.
|
|
195
|
-
2.
|
|
194
|
+
1. `DAG`只能增加列无法删除。增加列时,遇到同名列会覆盖
|
|
195
|
+
2. 不支持`删除行`,但可以添加删除标记列,然后在外进行删除行。删除行影响了所有列,不满足`DAG`
|
|
196
|
+
3. 不支持`重采样`,原理同不支持删除行。需在外进行
|
|
197
|
+
4. 可以将`删除行`与`重采样`做为分割线,一大块代码分成多个`DAG`串联。复杂不易理解,所以最终没有实现
|
|
196
198
|
|
|
197
199
|
## 小技巧
|
|
198
200
|
|
|
@@ -213,35 +215,35 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
213
215
|
|
|
214
216
|
```python
|
|
215
217
|
def func_0_ts__asset(df: pl.DataFrame) -> pl.DataFrame:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
218
|
+
df = df.sort(by=[_DATE_])
|
|
219
|
+
# ========================================
|
|
220
|
+
df = df.with_columns(
|
|
221
|
+
_x_0=1 / ts_delay(OPEN, -1),
|
|
222
|
+
LABEL_CC_1=(-CLOSE + ts_delay(CLOSE, -1)) / CLOSE,
|
|
223
|
+
)
|
|
224
|
+
# ========================================
|
|
225
|
+
df = df.with_columns(
|
|
226
|
+
LABEL_OO_1=_x_0 * ts_delay(OPEN, -2) - 1,
|
|
227
|
+
LABEL_OO_2=_x_0 * ts_delay(OPEN, -3) - 1,
|
|
228
|
+
)
|
|
229
|
+
return df
|
|
228
230
|
```
|
|
229
231
|
|
|
230
232
|
转译后的代码片段,详细代码请参考[Pandas版](examples/output_pandas.py)
|
|
231
233
|
|
|
232
234
|
```python
|
|
233
235
|
def func_2_cs__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
# expr_4 = cs_rank(x_7)
|
|
237
|
+
df["expr_4"] = (df["x_7"]).rank(pct=True)
|
|
238
|
+
return df
|
|
237
239
|
|
|
238
240
|
|
|
239
241
|
def func_3_ts__asset__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
# expr_5 = -ts_corr(OPEN, CLOSE, 10)
|
|
243
|
+
df["expr_5"] = -(df["OPEN"]).rolling(10).corr(df["CLOSE"])
|
|
244
|
+
# expr_6 = ts_delta(OPEN, 10)
|
|
245
|
+
df["expr_6"] = df["OPEN"].diff(10)
|
|
246
|
+
return df
|
|
245
247
|
|
|
246
248
|
```
|
|
247
249
|
|
|
@@ -40,28 +40,28 @@ from expr_codegen.tool import codegen_exec
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
def _code_block_1():
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
# 因子编辑区,可利用IDE的智能提示在此区域编辑因子
|
|
44
|
+
LOG_MC_ZS = cs_mad_zscore(log1p(market_cap))
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def _code_block_2():
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
# 模板中已经默认导入了from polars_ta.prefix下大量的算子,但
|
|
49
|
+
# talib在模板中没有默认导入。这种写法可实现在生成的代码中导入
|
|
50
|
+
from polars_ta.prefix.talib import ts_LINEARREG_SLOPE # noqa
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
# 1. 下划线开头的变量只是中间变量,会被自动更名,最终输出时会被剔除
|
|
53
|
+
# 2. 下划线开头的变量可以重复使用。多个复杂因子多行书写时有重复中间变时不再冲突
|
|
54
|
+
_avg = ts_mean(corr, 20)
|
|
55
|
+
_std = ts_std_dev(corr, 20)
|
|
56
|
+
_beta = ts_LINEARREG_SLOPE(corr, 20)
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
# 3. 下划线开头的变量有环循环赋值。在调试时可快速用注释进行切换
|
|
59
|
+
_avg = cs_mad_zscore_resid(_avg, LOG_MC_ZS, ONE)
|
|
60
|
+
_std = cs_mad_zscore_resid(_std, LOG_MC_ZS, ONE)
|
|
61
|
+
# _beta = cs_mad_zscore_resid(_beta, LOG_MC_ZS, ONE)
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
_corr = cs_zscore(_avg) + cs_zscore(_std)
|
|
64
|
+
CPV = cs_zscore(_corr) + cs_zscore(_beta)
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
df = None # 替换成真实的polars数据
|
|
@@ -139,10 +139,12 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
139
139
|
2. 然后`printer.py`有可能需要添加对应函数的打印代码
|
|
140
140
|
- 注意:需要留意是否要加括号`()`,不加时可能优先级混乱,可以每次都加括号,也可用提供的`parenthesize`简化处理
|
|
141
141
|
|
|
142
|
-
##
|
|
142
|
+
## `expr_codegen`局限性
|
|
143
143
|
|
|
144
|
-
1.
|
|
145
|
-
2.
|
|
144
|
+
1. `DAG`只能增加列无法删除。增加列时,遇到同名列会覆盖
|
|
145
|
+
2. 不支持`删除行`,但可以添加删除标记列,然后在外进行删除行。删除行影响了所有列,不满足`DAG`
|
|
146
|
+
3. 不支持`重采样`,原理同不支持删除行。需在外进行
|
|
147
|
+
4. 可以将`删除行`与`重采样`做为分割线,一大块代码分成多个`DAG`串联。复杂不易理解,所以最终没有实现
|
|
146
148
|
|
|
147
149
|
## 小技巧
|
|
148
150
|
|
|
@@ -163,35 +165,35 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
163
165
|
|
|
164
166
|
```python
|
|
165
167
|
def func_0_ts__asset(df: pl.DataFrame) -> pl.DataFrame:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
df = df.sort(by=[_DATE_])
|
|
169
|
+
# ========================================
|
|
170
|
+
df = df.with_columns(
|
|
171
|
+
_x_0=1 / ts_delay(OPEN, -1),
|
|
172
|
+
LABEL_CC_1=(-CLOSE + ts_delay(CLOSE, -1)) / CLOSE,
|
|
173
|
+
)
|
|
174
|
+
# ========================================
|
|
175
|
+
df = df.with_columns(
|
|
176
|
+
LABEL_OO_1=_x_0 * ts_delay(OPEN, -2) - 1,
|
|
177
|
+
LABEL_OO_2=_x_0 * ts_delay(OPEN, -3) - 1,
|
|
178
|
+
)
|
|
179
|
+
return df
|
|
178
180
|
```
|
|
179
181
|
|
|
180
182
|
转译后的代码片段,详细代码请参考[Pandas版](examples/output_pandas.py)
|
|
181
183
|
|
|
182
184
|
```python
|
|
183
185
|
def func_2_cs__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
# expr_4 = cs_rank(x_7)
|
|
187
|
+
df["expr_4"] = (df["x_7"]).rank(pct=True)
|
|
188
|
+
return df
|
|
187
189
|
|
|
188
190
|
|
|
189
191
|
def func_3_ts__asset__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
# expr_5 = -ts_corr(OPEN, CLOSE, 10)
|
|
193
|
+
df["expr_5"] = -(df["OPEN"]).rolling(10).corr(df["CLOSE"])
|
|
194
|
+
# expr_6 = ts_delta(OPEN, 10)
|
|
195
|
+
df["expr_6"] = df["OPEN"].diff(10)
|
|
196
|
+
return df
|
|
195
197
|
|
|
196
198
|
```
|
|
197
199
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.2"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: expr_codegen
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: symbol expression to polars expression tool
|
|
5
5
|
Author-email: wukan <wu-kan@163.com>
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -90,28 +90,28 @@ from expr_codegen.tool import codegen_exec
|
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
def _code_block_1():
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
# 因子编辑区,可利用IDE的智能提示在此区域编辑因子
|
|
94
|
+
LOG_MC_ZS = cs_mad_zscore(log1p(market_cap))
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
def _code_block_2():
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
# 模板中已经默认导入了from polars_ta.prefix下大量的算子,但
|
|
99
|
+
# talib在模板中没有默认导入。这种写法可实现在生成的代码中导入
|
|
100
|
+
from polars_ta.prefix.talib import ts_LINEARREG_SLOPE # noqa
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
# 1. 下划线开头的变量只是中间变量,会被自动更名,最终输出时会被剔除
|
|
103
|
+
# 2. 下划线开头的变量可以重复使用。多个复杂因子多行书写时有重复中间变时不再冲突
|
|
104
|
+
_avg = ts_mean(corr, 20)
|
|
105
|
+
_std = ts_std_dev(corr, 20)
|
|
106
|
+
_beta = ts_LINEARREG_SLOPE(corr, 20)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
# 3. 下划线开头的变量有环循环赋值。在调试时可快速用注释进行切换
|
|
109
|
+
_avg = cs_mad_zscore_resid(_avg, LOG_MC_ZS, ONE)
|
|
110
|
+
_std = cs_mad_zscore_resid(_std, LOG_MC_ZS, ONE)
|
|
111
|
+
# _beta = cs_mad_zscore_resid(_beta, LOG_MC_ZS, ONE)
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
_corr = cs_zscore(_avg) + cs_zscore(_std)
|
|
114
|
+
CPV = cs_zscore(_corr) + cs_zscore(_beta)
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
df = None # 替换成真实的polars数据
|
|
@@ -189,10 +189,12 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
189
189
|
2. 然后`printer.py`有可能需要添加对应函数的打印代码
|
|
190
190
|
- 注意:需要留意是否要加括号`()`,不加时可能优先级混乱,可以每次都加括号,也可用提供的`parenthesize`简化处理
|
|
191
191
|
|
|
192
|
-
##
|
|
192
|
+
## `expr_codegen`局限性
|
|
193
193
|
|
|
194
|
-
1.
|
|
195
|
-
2.
|
|
194
|
+
1. `DAG`只能增加列无法删除。增加列时,遇到同名列会覆盖
|
|
195
|
+
2. 不支持`删除行`,但可以添加删除标记列,然后在外进行删除行。删除行影响了所有列,不满足`DAG`
|
|
196
|
+
3. 不支持`重采样`,原理同不支持删除行。需在外进行
|
|
197
|
+
4. 可以将`删除行`与`重采样`做为分割线,一大块代码分成多个`DAG`串联。复杂不易理解,所以最终没有实现
|
|
196
198
|
|
|
197
199
|
## 小技巧
|
|
198
200
|
|
|
@@ -213,35 +215,35 @@ df = codegen_exec(df, _code_block_1, _code_block_2) # 只执行,不保存代
|
|
|
213
215
|
|
|
214
216
|
```python
|
|
215
217
|
def func_0_ts__asset(df: pl.DataFrame) -> pl.DataFrame:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
218
|
+
df = df.sort(by=[_DATE_])
|
|
219
|
+
# ========================================
|
|
220
|
+
df = df.with_columns(
|
|
221
|
+
_x_0=1 / ts_delay(OPEN, -1),
|
|
222
|
+
LABEL_CC_1=(-CLOSE + ts_delay(CLOSE, -1)) / CLOSE,
|
|
223
|
+
)
|
|
224
|
+
# ========================================
|
|
225
|
+
df = df.with_columns(
|
|
226
|
+
LABEL_OO_1=_x_0 * ts_delay(OPEN, -2) - 1,
|
|
227
|
+
LABEL_OO_2=_x_0 * ts_delay(OPEN, -3) - 1,
|
|
228
|
+
)
|
|
229
|
+
return df
|
|
228
230
|
```
|
|
229
231
|
|
|
230
232
|
转译后的代码片段,详细代码请参考[Pandas版](examples/output_pandas.py)
|
|
231
233
|
|
|
232
234
|
```python
|
|
233
235
|
def func_2_cs__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
# expr_4 = cs_rank(x_7)
|
|
237
|
+
df["expr_4"] = (df["x_7"]).rank(pct=True)
|
|
238
|
+
return df
|
|
237
239
|
|
|
238
240
|
|
|
239
241
|
def func_3_ts__asset__date(df: pd.DataFrame) -> pd.DataFrame:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
# expr_5 = -ts_corr(OPEN, CLOSE, 10)
|
|
243
|
+
df["expr_5"] = -(df["OPEN"]).rolling(10).corr(df["CLOSE"])
|
|
244
|
+
# expr_6 = ts_delta(OPEN, 10)
|
|
245
|
+
df["expr_6"] = df["OPEN"].diff(10)
|
|
246
|
+
return df
|
|
245
247
|
|
|
246
248
|
```
|
|
247
249
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.7.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|