请用中文回答: (K线图: 主图:"二"淡红,"六"紫红,"候"绿,"叁"暗红,"八"深红(如果有其...

Creato il: 13 luglio 2025

Risposto usando O3 da Chat01

Domanda

2025-07-13_09-53-07.png2025-07-13_09-53-07.png

请用中文回答:
(K线图:
主图:"二"淡红,"六"紫红,"候"绿,"叁"暗红,"八"深红(如果有其它均线应是M17浅蓝色、M20淡绿色)
副图:两条水平参考线:-50及50、"知"蓝色,"物"洋红,"悟"暗的紫红,而"庄1","庄2"就没有画线了,"叉庄"的信号等其它在副图的信号不用理会
)
你阅读下面的内容写代码
重点解读:在1处:股价连续上升后开始调整、到2处调整结束
关键:从1到2:"二","六","候"相对粘合、代码要体现、
另外在1处知、物相对高位、到2处知下降接近-50、关键的要代码期间知是有多次-50至50间波动、
你写出2处的选股公式
一、将此内容写出python代码选股公式,请用中文回答:设定直接用代码读取本地数据C:\3\原始.CSV、它的数据结构如下、它是已经编码、日期排序的、所以你不要再排序(如果是分钟数据、在"日期"列会有时分的数据;编码、日期列都是数字格式。但你切勿进行日期列的转换):它已经计算好"知","物","庄1","庄2","叉庄","悟","二","六","候","叁","八"、"ATR"。
编码 日期 量 开 高 低 收
603501 20230222 454733216 88.86 89.42 88.11 88.41
603501 20230223 593604864 88.2 89.29 87.8 88.04
603501 20230224 536806528 88.9 89.35 87.01 87.06
它的指标说明:
"知","物"相当于DMI的周期为14、56的ADX指标、但我取消了原来的取绝对值abs()、
"ATR"是DMI的周期为14。(说明代码中的其他指标、"悟"相当于周期为36的KDJ的(K-50)*1.5、"庄1"相当于MACD的DIFF、"庄2"相当于MACD的DEA。"叉庄"为0相当于MACD的金叉。(由于修改后的ADX值应是-100——100的范围、所以悟由常规的(K-50)*1.5、庄1与庄2也作了类似的调整;保持数值分布的一致)
均线:"二","六","候","叁","八"相当于M24,M60,M135,M300,M480);

如果需要计算技术指标请直接用代码计算。所以你不要再导入技术指标库了(如果要用到EMA指标、你还是先用接近周期的"二","六","候","叁","八"代替、以使代码简洁些、实际应用我会修改)。
另外你将代码的列名变量用中文。

二、当你用你最熟悉的打开CSV的python代码完成后
按直接打开C:\3\原始.JMP的方式来重新写一份python代码:它的原始文件数据结构完全相同 、计算的要求也一致
直接读取JMP表格参考语法是这样的:

import jmp
import numpy as np
import pandas as pd

creating a Pandas dataframe from a JMP DataTable directly

dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")

create pandas DataFrame from Big Class

df = pd.DataFrame()
for idx in range( len(dt) ):
df[ dt[idx].name ] = np.array( dt[idx] )

结果直接输出到JMP表格不用存盘。语法参考
dt = jmp.DataTable("JMP", df.shape[0])
for col in df.columns:
col_type = jmp.DataType.Numeric
dt.new_column(col, col_type)
dt[col] = list(df[col])

Pensiero

Writing code in Chinese

The user wants the code and column names in Chinese, along with comments in Chinese. I should avoid importing any technical indicator library, using only the existing columns and simple operations. I will rely on precomputed indicators, and for moving averages, I’ll utilize the existing MA lines. Since the user only wants the code with possible explanations, I can provide this as markdown directly. No need to execute or call any special functions; just output the code.

Designing selection formula

I need to create a formula based on the described criteria: During the period, "知", "物", and "候" must be close together, and "知" should fluctuate between -50 and 50 multiple times. For the threshold calculation, I’ll assume a 1% or small absolute difference between the moving averages. We also need to check when "知" drops near -50 and confirm multiple oscillations within a lookback period, like 20 bars.

Next, I’ll read the data into a pandas DataFrame, compute the differences between everything, and define the conditions with Chinese variable names.

Thought for 20 seconds

Risposta

下面给出两段完整、可直接复制运行的 Python 示例脚本。第一段脚本直接读取 CSV 文件,第二段脚本演示如何读取 JMP 文件并把筛选结果写回到一个新的 JMP 数据表。
代码里变量、注释尽量使用中文,方便您后续修改。


一、读取 C:\3\原始.CSV 的选股脚本

python
import pandas as pd import numpy as np # ① 读入数据(原始文件已按日期排好序,无需再排序) 文件路径 = r"C:\3\原始.CSV" 数据 = pd.read_csv(文件路径) # ② 计算“粘合”程度:三条均线「二」「六」「候」的最大-最小差值/收盘价 # 粘合阈值可自行调整(下面用 2% 作为示例) 粘合阈值 = 0.02 均线列 = ["二", "六", "候"] 数据["均线差"] = 数据[均线列].max(axis=1) - 数据[均线列].min(axis=1) 数据["均线粘合"] = 数据["均线差"] / 数据["收"] <= 粘合阈值 # ③ 判断「知」接近 -50(此处用区间 -55 ~ -45,可自行调整) 数据["知接近-50"] = 数据["知"].between(-55, -45) # ④ 统计最近 N 根(默认 20 根)里「知」在 -50~50 区间内穿越 0 的次数 # 视为“多次波动”——这里要求至少两次 窗口大小 = 20 最少波动次数 = 2 def 计算波动次数(序列): # 相邻两天「知」正负号不同 => 穿越 0 # 排除 NaN 并统计 序列 = 序列.dropna() if len(序列) < 2: return 0 符号 = np.sign(序列) 穿越次数 = np.sum(符号.iloc[1:].values * 符号.iloc[:-1].values < 0) return 穿越次数 数据["波动次数"] = ( 数据["知"] .rolling(window=窗口大小, min_periods=窗口大小) .apply(计算波动次数, raw=False) ) 数据["知多次波动"] = 数据["波动次数"] >= 最少波动次数 # ⑤ 组合选股条件(对应图中“2”点) 数据["选股信号"] = 数据["均线粘合"] & 数据["知接近-50"] & 数据["知多次波动"] # ⑥ 输出满足条件的行(可按需保存或进一步处理) 信号数据 = 数据[数据["选股信号"]].copy() print("符合条件的记录:") print(信号数据[["编码", "日期", "收", "知", "物", *均线列]])

二、读取 C:\3\原始.JMP 并把结果写回 JMP 表格

python
import jmp # 需先安装并配置 JMP Python API import numpy as np import pandas as pd # ① 打开现有 JMP 数据表并转为 pandas DataFrame 原始表路径 = r"C:\3\原始.JMP" dt = jmp.open(原始表路径) df = pd.DataFrame() for idx in range(len(dt)): 列名 = dt[idx].name df[列名] = np.array(dt[idx]) # ② 与 CSV 版本完全相同的选股逻辑 ----------------------- 均线列 = ["二", "六", "候"] 粘合阈值 = 0.02 窗口大小 = 20 最少波动次数 = 2 df["均线差"] = df[均线列].max(axis=1) - df[均线列].min(axis=1) df["均线粘合"] = df["均线差"] / df["收"] <= 粘合阈值 df["知接近-50"] = df["知"].between(-55, -45) def 计算波动次数(序列): 序列 = 序列.dropna() if len(序列) < 2: return 0 符号 = np.sign(序列) return np.sum(符号.iloc[1:].values * 符号.iloc[:-1].values < 0) df["波动次数"] = ( df["知"] .rolling(window=窗口大小, min_periods=窗口大小) .apply(计算波动次数, raw=False) ) df["知多次波动"] = df["波动次数"] >= 最少波动次数 df["选股信号"] = df["均线粘合"] & df["知接近-50"] & df["知多次波动"] # ③ 生成新的 JMP 数据表并回写结果 结果表 = jmp.DataTable("选股结果", df.shape[0]) for col in df.columns: 结果表.new_column(col, jmp.DataType.Numeric) 结果表[col] = list(df[col]) print("已将筛选后的结果写入 JMP 数据表『选股结果』。")

参数说明与可调节部分

变量作用默认值调整建议
粘合阈值判断「二」「六」「候」三线粘合程度0.02 (2%)根据个股波动性改成 0.015~0.03
窗口大小统计「知」波动的回溯长度20可改成 15~30
最少波动次数回溯区间内「知」穿越 0 的最小次数2若需更严格,可设 3

注意:脚本假设文件中已包含列「知」「物」「庄1」「庄2」「叉庄」「悟」「二」「六」「候」「叁」「八」「ATR」。若列名不同,请相应修改代码。

Domanda

修改为JMP软件的JSL(非javascript)代码不要任何任何注释。请用中文回答:在代码框给出完整修改后的代码:给了代码就不用后面的说明了
请用中文回答:用JMP软件的JSL编写将里面内容写出选股公式:设定直接用代码读取本地数据C:\3\原始.jmp、它的数据结构如下、它是已经编码、日期排序的、所以你不要再排序(如果是分钟数据、在"日期"列会有时分的数据):注意计算指标过程是不用处理"日期"列的(所以不要对日期进行转换之类的处理)
编码 日期 量 开 高 低 收 知 物 庄1 庄2 叉庄 悟 二 六 候 叁 八 ATR
603501 20230222 454733216 88.86 89.42 88.11 88.41……
603501 20230223 593604864 88.2 89.29 87.8 88.04……
603501 20230224 536806528 88.9 89.35 87.01 87.06……

dt=Open("C:\3\原始.jmp",Add to Recent Files(0));Include("I:\E\0\备份\0\单码知物庄有均.jsl");这样它就有上述指标了
[说明:"知","物"相当于DMI的周期为14、56的ADX指标、但我取消了原来的取绝对值abs()、
"ATR"是DMI的周期为14。(说明代码中的其他指标、"悟"相当于周期为36的KDJ的(K-50)*1.5、"庄1"相当于MACD的DIFF、"庄2"相当于MACD的DEA。"叉庄"为0相当于MACD的金叉。(由于修改后的ADX值应是-100——100的范围、所以悟由常规的(K-50)*1.5、庄1与庄2也作了类似的调整;保持数值分布的一致)
均线:"二","六","候","叁","八"相当于M24,M60,M135,M300,M480];
如果需要计算技术指标请直接用代码计算、保留中间的辅助列计算结果。另外你将代码的列名变量用中文。注意列名不应以数字开头、
用这样的形式来编写列公式:
ca="";New Column(ca);Column(ca)<<Formula( );dt<<run formulas;Column(ca)<<deleteFormula;
如果是选股、也要用列公式的来选股例如:ca="选股";New Column(ca);Column(ca)<<Formula( );dt<<run formulas;Column(ca)<<deleteFormula;
有结果提取子集即可:dt<<Select Where(选股>0);d3=dt<<Subset(Output Table("选股结果"),Selected Rows(1),selected columns(0));try(d3<<Delete Table Property("Source"));

附:简单的JSL语法:
以"收"列的计算:
上一时序:lag(收,1)、
10天均值:round(mean(收[Index(Row()-9,Row())]),3)
10天最大"收":max(收[Index(Row()-9,Row())])
注意这个是JMP软件的JSL(非javascript)它对"的转义符是以下三个字符!"

Pensiero

Rewriting as JSL code

The user asked for JSL (JMP Scripting Language) code that works with their local data on their specified file path "C:\3\原始.jmp". They want no comments, and it involves selecting stock formulas with columns built for intermediate processing and selection. I'll do things like opening the table dt, adding columns with formulas, and filtering/selecting data based on the formulas.

Here’s the direct translation of that requirement into JSL:

JSL
dt = Open("C:\3\原始.jmp", Add to Recent Files(0)); ca=""; New Column(ca); Column(ca) << Formula(); dt << run formulas; Column(ca) << deleteFormula; ca="选股"; New Column(ca); Column(ca) << Formula(); dt << run formulas; Column(ca) << deleteFormula; dt << Select Where(选股>0); d3 = dt << Subset(Output Table("选股结果"), Selected Rows(1), selected columns(0)); try(d3 << Delete Table Property("Source"));

Computing additional columns

I need to calculate several new columns. First, “均线差” is the difference between the maximum and minimum of three variables (二, 六, 候). The next column, “均线粘合,” is an indicator of whether the difference is within a threshold when divided by "收." Then, “知接近-50” simply checks whether “知” is between -55 and -45. Finally, for “波动次数,” I need to count sign changes across the last 20 rows, which might be tricky due to JSL's dynamic loops. Ideally, I’ll use scripting loops for calculating “波动次数.”

Crafting the JSL Code

The user wants the script to calculate several columns based on their provided logic. First, I'll open the data table and include necessary files. Then, I'll write the formulas for "均线差" (difference between the max and min columns), "均线粘合" (Boolean for threshold condition), and "知接近负五十" (check if within range). After that, "波动次数" will be calculated with a script loop, which is more complex, followed by the formula for "知多次波动" and the final "选股" (selection). The table will be filtered based on this selection.

Thought for 34 seconds

Risposta

JSL
dt=Open("C:\3\原始.jmp",Add to Recent Files(0)); Include("I:\E\0\备份\0\单码知物庄有均.jsl"); ca="均线差";New Column(ca);Column(ca)<<Formula(Col Maximum(:二,:六,:候)-Col Minimum(:二,:六,:候));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="均线粘合";New Column(ca);Column(ca)<<Formula(If((:均线差/:收)<=0.02,1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="知接近负五十";New Column(ca);Column(ca)<<Formula(If((:知>=-55)&(:知<=-45),1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; New Column("波动次数",Numeric,Continuous); n=N Rows(dt); for(r=1,r<=n,r++, if(r<20, Column("波动次数")[r]=.; , cnt=0; for(i=0,i<19,i++, v1=Column("知")[r-i]; v2=Column("知")[r-i-1]; if(!(Is Missing(v1)|Is Missing(v2)), if(Sign(v1)*Sign(v2)<0, cnt=cnt+1; ); ); ); Column("波动次数")[r]=cnt; ); ); ca="知多次波动";New Column(ca);Column(ca)<<Formula(If(:波动次数>=2,1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="选股";New Column(ca);Column(ca)<<Formula(If((:均线粘合==1)&(:知接近负五十==1)&(:知多次波动==1),1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; dt<<Select Where(:选股>0); d3=dt<<Subset(Output Table("选股结果"),Selected Rows(1),Selected Columns(0)); try(d3<<Delete Table Property("Source"));

Domanda

JSL可以这样
波动次数可以这样
sum(知[Index(Row()-19,Row())]>=50&知[Index(Row()-20,Row()-1)]<50)
原来的出错
访问或对“Sign”, Sign( v1 ) /###/ 求值时出现“未解析名称: Sign”

在“D:\脚本 2.jsl”中的第 17 行

Pensiero

The user is working with JSL and wants to replace a Sign function with a sum condition. The error they’re mentioning is due to the Sign function being unrecognized. Based on their update, they're working to track a crossing between values (earlier crossing -50 to 50, now focusing on crossing above 50 and below 50). I need to modify the code using a sum expression that checks for conditions based on their updated logic, particularly looking at thresholds of 50 for counting the fluctuations. I'll provide the corrected formula now.

The user is working with JSL and wants to compute a fluctuation count (波动次数) using a formula that checks for crossings of thresholds. They're facing issues with the sign() function and want to replace it with a sum condition. The formula they propose checks when the current value crosses 50, and the previous value is less than 50 (upward). I need to adjust the logic to count both upward and downward crossings across 50 and -50, using the sum function and bitwise OR, and ensure it follows their requirements for threshold crossings.

Thought for 36 seconds

Risposta

JSL
dt=Open("C:\3\原始.jmp",Add to Recent Files(0)); Include("I:\E\0\备份\0\单码知物庄有均.jsl"); ca="均线差";New Column(ca);Column(ca)<<Formula(Col Maximum(:二,:六,:候)-Col Minimum(:二,:六,:候));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="均线粘合";New Column(ca);Column(ca)<<Formula(If((:均线差/:收)<=0.02,1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="知接近负五十";New Column(ca);Column(ca)<<Formula(If((:知>=-55)&(:知<=-45),1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="波动次数";New Column(ca);Column(ca)<<Formula( If(Row()<20, ., Sum( (:知[Index(Row()-19,Row())]>=50 & :知[Index(Row()-20,Row()-1)]<50) | (:知[Index(Row()-19,Row())]<=-50 & :知[Index(Row()-20,Row()-1)]>-50) ) ) );dt<<Run Formulas;Column(ca)<<Delete Formula; ca="知多次波动";New Column(ca);Column(ca)<<Formula(If(:波动次数>=2,1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; ca="选股";New Column(ca);Column(ca)<<Formula(If((:均线粘合==1)&(:知接近负五十==1)&(:知多次波动==1),1,0));dt<<Run Formulas;Column(ca)<<Delete Formula; dt<<Select Where(:选股>0); d3=dt<<Subset(Output Table("选股结果"),Selected Rows(1),Selected Columns(0)); try(d3<<Delete Table Property("Source"));

Condividi questa Q&A