You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
alpha_tools/alpha-forge/test_code_002.py

20 lines
608 B

import re
expression = "last_diff_value(ts_sum(subtract(implied_volatility_call_120, implied_volatility_put_90), 20), 5)"
# 提取算子
operators = set()
for match in re.finditer(r'\b([a-z_][a-z0-9_]*)\s*\(', expression):
op = match.group(1)
operators.add(op)
print(f"匹配到算子: {op}")
print(f"\n所有算子: {operators}")
# 提取字段
candidates = set(re.findall(r'\b([a-z][a-z0-9_]*)\b', expression))
print(f"\n所有候选词: {candidates}")
# 过滤掉算子
fields = [c for c in candidates if c not in operators and not c.isdigit() and len(c) > 2]
print(f"\n字段: {fields}")