wukan1986 / expr_codegen Goto Github PK
View Code? Open in Web Editor NEWcodegen from expression to others, such as polars, pandas
Home Page: https://exprcodegen.streamlit.app
License: BSD 3-Clause "New" or "Revised" License
codegen from expression to others, such as polars, pandas
Home Page: https://exprcodegen.streamlit.app
License: BSD 3-Clause "New" or "Revised" License
def _code_block_():
cond_1 = cs_rank(-amount, False) <= 10
filter = and_(cond_1,
True)
会报错
File "D:\Users\Kan\miniconda3\envs\py311_1\Lib\site-packages\expr_codegen\tool.py", line 41, in extract
expr = simplify(expr)
^^^^^^^^^^^^^^
File "D:\Users\Kan\miniconda3\envs\py311_1\Lib\site-packages\sympy\simplify\simplify.py", line 601, in simplify
return _eval_simplify(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\Kan\miniconda3\envs\py311_1\Lib\site-packages\sympy\core\relational.py", line 428, in _eval_simplify
elif dif.equals(0): # XXX this is expensive
.....
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\Kan\miniconda3\envs\py311_1\Lib\site-packages\sympy\core\basic.py", line 1871, in _eval_derivative_n_times
obj2 = obj._eval_derivative(s)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\Kan\miniconda3\envs\py311_1\Lib\site-packages\sympy\core\function.py", line 600, in _eval_derivative
da = a.diff(s)
^^^^^^
AttributeError: 'BooleanFalse' object has no attribute 'diff'
其实是False) <= 10
在同一行时进行simplify
报错。目前没有好的办法,只能在编码时就回避,不写同一行。
def _code_block_():
cond_1 = cs_rank(-amount, False)
filter = and_(cond_1 <= 10,
True)
这样就不报错了
df = df.sort_values(by=["asset", "date"]).groupby(by=["asset"], group_keys=False).apply(func_0_ts__asset__date)
df = df.groupby(by=["date"], group_keys=False).apply(func_0_cs__date)
df = func_0_cl(df)
df = df.groupby(by=["date"], group_keys=False).apply(func_1_cs__date)
df = func_1_cl(df)
df = df.sort_values(by=["asset", "date"]).groupby(by=["asset"], group_keys=False).apply(func_1_ts__asset__date)
df = func_2_cl(df)
df = df.sort_values(by=["asset", "date"]).groupby(by=["asset"], group_keys=False).apply(func_2_ts__asset__date)
df = df.groupby(by=["date"], group_keys=False).apply(func_2_cs__date)
df = df.groupby(by=["date"], group_keys=False).apply(func_3_cs__date)
df = df.sort_values(by=["asset", "date"]).groupby(by=["asset"], group_keys=False).apply(func_3_ts__asset__date)
func_2_cs__date、func_3_cs__date虽然有前后依赖关系,但完全可以放在同一groupby中计算
func_1_ts__asset__date、func_2_ts__asset__date中间隔了func_2_cl,其实三个可以合并
表达式并行分组使用了有向无环图。graphlib是一个非常简单的dag,但想对部分表达式化简时不方便,所以将替换
即 & | ^ 需要检查一下
< <= > >=等也要再检查一下
欢迎加入
# x_0 = ts_arg_max(signed_power(if_else(RETURNS < 0, ts_std_dev(RETURNS, 20), CLOSE), 2.0), 5)
# x_1 = ts_delta(log(VOLUME), 2)
# x_2 = cs_rank(x_1)
# x_3 = CLOSE - OPEN
# x_4 = cs_rank(x_3/OPEN)
# x_5 = cs_rank(OPEN)
# x_6 = cs_rank(VOLUME)
# x_7 = cs_rank(LOW)
# x_8 = OPEN - ts_sum(VWAP, 10)/10
# x_9 = ts_sum(OPEN, 5)
# x_10 = ts_sum(RETURNS, 5)
# x_11 = x_10*x_9 - ts_delay(x_10*x_9, 10)
# x_12 = ts_delta(CLOSE, 1)
# x_13 = -x_12
# x_14 = if_else(ts_min(x_12, 4) > 0, x_12, if_else(ts_max(x_12, 4) < 0, x_12, x_13))
# x_15 = CLOSE - VWAP
# x_16 = -x_15
# x_17 = ts_max(x_16, 3)
# x_18 = ts_min(x_16, 3)
# x_19 = ts_delta(VOLUME, 3)
# x_20 = cs_rank(CLOSE)
# x_21 = ts_covariance(x_20, x_6, 5)
# x_22 = ts_delta(RETURNS, 3)
# x_23 = cs_rank(x_22)
# x_24 = cs_rank(HIGH)
# x_25 = ts_corr(x_24, x_6, 3)
# x_26 = cs_rank(x_25)
# x_27 = ts_covariance(x_24, x_6, 5)
# x_28 = ts_delta(x_12, 1)
# x_29 = ts_rank(CLOSE, 10)
# x_30 = ts_rank(VOLUME/ADV20, 5)
x_20,x_22,x_29,x_30,明显可以放在第一次出现ts_部分就开始计算,现在放在了比较后的位置,导致groupby的次数变多
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.