以箱形图的形式呈现股票数据大家好,
描述股票价格变动的数据是由开盘价/收盘价和最高/最低价创建的。 有没有什么方法可以在 JMP 中创建箱形图(烛台图),其实体来自开盘价和收盘价以及上下影线分别具有最大(高)和最小(低)价格的值,如附图所示或是否有更好的方法吗? 传统的箱形图然而,element 显示离群值或分位数箱线图,并提供值分布的紧凑视图。 我附上了一个示例数据表,其中提供了几个时间戳和价格值(最小值、开盘价、收盘价和最高价)。 我将不胜感激提示和建议。

(来源:维基百科)
此致
分析图形脚本回复:以箱线图的形式呈现股票数据感谢 Jim 的耐心指导。你的代码很棒!
我也学会了。非常感谢!


回复:以箱线图的形式呈现股票数据这是处理消除黑色轮廓的修改

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Stock Prices.jmp" );
dt << New Column( "tip", formula( Format( :Date, "yyyymmdd" ) ) );
dt << delete columns( "Date" );
dt << New Column( "new", set each value( Row() ) );
dt << New Column( "Direction", character, set each value( If( :Open <= :Close, "Increasing", "Decreasing" ) ) );
dt << run formulas;
Column( "tip" ) << deleteFormula;
dt:open << label;
dt:close << label;
gb = dt << Graph Builder(
Size( 1289, 456 ),
Show Control Panel( 0 ),
Variables( X( :new ), Y( :High ), Y( :Low, Position( 1 ) ), Color( :Direction ) ),
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 10 ), Bar Style( "Interval" ) ) ),
SendToReport(
Dispatch( {}, "new", ScaleBox, {Interval( "new" ), Inc( 1 ), Minor Ticks( 0 )} ),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
10,
Properties( 0, {Fill Color( light red )}, Item ID( "Decreasing", 1 ) ),
Properties( 1, {Fill Color( light green )}, Item ID( "Increasing", 1 ) ),
Properties( 0, {Line Color( 19 ), Line Width( 2 )}, Item ID( "High..Low", 1 ) )
)}
)
)
);
// Add the boxes to the chart
Report( gb )[framebox( 1 )] << add graphics script(
//halfDayincr = In Days( 1 ) / 2 * .8;
//days = (Col Max( :Date ) - Col Min( :Date )) / In Days( 1 );
halfDayincr = .4;
days = Col Max( :new ) - Col Min( :new );
Pen Size( 1 );
For( i = 1, i <= N Rows( dt ), i++,
If( :Open[i] <= :close[i],
Pen Color( light green );
Fill Color( light green );
,
Pen Color( light red );
Fill Color( light red );
);
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 1 );
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 0 );
);
);
关于如何手动/交互
- 将高低列拖到Y轴放置区
- 将新列拖到 X 轴放置区域
- 右键单击图表并选择 Smoother=>Remove
- 右键单击图表并选择 Points=>Change=>Bar
- 右键单击图表并选择 Bar=>Bar Style=>Interval
- 将方向列拖动到颜色放置区域
- 在图例中,右键单击“增加”的颜色框并选择“填充颜色”=>选择浅绿色
- 在图例中右键单击要减少的颜色框并选择填充颜色=>选择浅红色
- 现在需要添加每个高和低的框。这是通过向 Graph Builder 添加图形脚本来完成的
- 右键单击图表并选择自定义
- 单击 + 框以添加新脚本
- 在脚本编辑区,添加如下脚本(该脚本为个人用户开发。在这种情况下,我写了脚本)
halfDayincr = 0.4;
days = Col Max( :new ) - Col Min( :new );
Pen Size( 1 );
For( i = 1, i <= N Rows( dt ), i++,
If( :Open[i] <= :Close[i],
Pen Color( light green );
Fill Color( light green );
,
Pen Color( light red );
Fill Color( light red );
);
Rect(
:new[i] - halfDayincr,
Max( :Open[i], :Close[i] ),
:new[i] + halfDayincr,
Min( :Open[i], :Close[i] ),
1
);
Rect(
:new[i] - halfDayincr,
Max( :Open[i], :Close[i] ),
:new[i] + halfDayincr,
Min( :Open[i], :Close[i] ),
0
);
);
点击确定
回复:以箱线图的形式呈现股票数据再次感谢 Jim 创造了如此创新的形象。
我尝试自己手动创建图表,但仍然做不到。
我要再占用 Jim 的时间,问我是否可以解释手动制作此图的过程。非常感谢!
我主要是想给这张图加一条平滑的移动平均线。
另外,能否去掉每张箱形图的黑框?因为我看到其他帖子有没有黑色边框的框。

谢谢吉姆!
回复:以箱线图的形式呈现股票数据谢谢吉姆!
想加强基础功能和语法学习,现在直接上答案。
回复:以箱线图的形式呈现股票数据当您从使用 Date 列(JMP 日期列(自 1904 年 1 月 1 日以来的秒数))更改为 New 列(它只是一个整数,其中每行仅比其先前值多 1)时,您需要更改变量“days”和“halfDayincr”的计算。天数就是行数,halfDayincr,即要绘制的矩形宽度的一半,仅为 0.4。

gb = dt << Graph Builder(
Size( 1289, 456 ),
Show Control Panel( 0 ),
Variables( X( :new ), Y( :High ), Y( :Low, Position( 1 ) ) ),
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 10 ), Bar Style( "Interval" ) ) ),
SendToReport(
Dispatch(
{},
"new",
ScaleBox,
{ Interval( "new" ), Inc( 1 ),
Minor Ticks( 0 )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
10,
Properties( 0, {Line Width( 2 )}, Item ID( "High..Low", 1 ) )
)}
)
)
);
// Add the boxes to the chart
Report( gb )[framebox( 1 )] << add graphics script(
//halfDayincr = In Days( 1 ) / 2 * .8;
//days = (Col Max( :Date ) - Col Min( :Date )) / In Days( 1 );
halfDayincr = .4;
days = Col Max( :new ) - Col Min( :new );
Pen Color( black );
Pen Size( 2 );
For( i = 1, i <= N Rows( dt ), i++,
If( :Open[i] <= :close[i],
Fill Color( light green );
,
Fill Color( light red );
);
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 1 );
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 0 );
);
);
我强烈建议你开始研究社区提供的代码,这样你就不会局限于只能剪切和粘贴它。请花时间阅读脚本指南,并花时间研究社区提供的代码,直到您了解其工作原理。
回复:以箱线图的形式呈现股票数据我尝试不使用日期规范数据,但最终没有修改 JSL。它没有用。
如下面的JSL,如何用新数据绘制箱线图?非常感谢!

dt = Open( "$SAMPLE_DATA/Stock Prices.jmp" );
dt << New Column( "tip", formula( Format( :Date, "yyyymmdd" ) ) );
dt << run formulas;
Column( "tip" ) << deleteFormula;
dt << delete columns( "Date" );
dt << New Column( "new", set each value( Row() ) );
dt:open << label;
dt:close << label;
gb = dt << Graph Builder(
Size( 1289, 456 ),
Show Control Panel( 0 ),
Variables( X( :new ), Y( :High ), Y( :Low, Position( 1 ) ) ),
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 10 ), Bar Style( "Interval" ) ) ),
SendToReport(
Dispatch( {}, "new", ScaleBox, {Interval( "Day" ), Inc( 1 ), Minor Ticks( 0 )} ),
Dispatch( {}, "400", ScaleBox, {Legend Model( 10, Properties( 0, {Line Width( 2 )}, Item ID( "High..Low", 1 ) ) )} )
)
);
Report( gb )[framebox( 1 )] << add graphics script(
halfDayincr = In Days( 1 ) / 2 * .8;
days = (Col Max( :new ) - Col Min( :new )) / In Days( 1 );
Pen Color( black );
Pen Size( 2 );
For( i = 1, i <= N Rows( dt ), i++,
If( :Open[i] <= :close[i],
Fill Color( light green ),
Fill Color( light red )
);
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 1 );
Rect( :new[i] - halfDayincr, Max( :open[i], :close[i] ), :new[i] + halfDayincr, Min( :open[i], :close[i] ), 0 );
);
);回复:以箱线图的形式呈现股票数据单击数据点时显示的列是设置了“标签”列属性的列。在我的原始代码中,打开和关闭列设置了标签值。您所要做的就是为要添加 Label 列属性的每个列添加一行。
回复:以箱线图的形式呈现股票数据
回复:以箱线图的形式呈现股票数据是的,X轴可以显示日期以外的内容。
但是当鼠标指向图表时最好显示原始日期标签。
我就是这么想的。但是我不知道如何更改代码。
谢谢!
回复:以箱线图的形式呈现股票数据您很可能必须将 X 轴更改为标称,然后可能修改图形脚本以适应该更改。
回复:以箱线图的形式呈现股票数据如何去除图表中非交易日的缺口?
- 谢谢吉姆!

回复:以箱线图的形式呈现股票数据你好@卢卡斯
关于使用“.”的小数点或“,”也许您可以从偏好设置中解决这个问题,如下图所示。 然而,我会假设您正在使用的所有其他数据集都会因错误而改变......

在这种情况下,为了仅修改一个文件中特定列的格式,您可以使用以下命令:
Format( x, "Currency", 20, <<Use Locale(0) );
此链接中的完整说明:
https://www.jmp.com/support/help/zh-cn/15.2/index.shtml#page/jmp/formatting-numbers.shtml
让我们知道它是否有效。
罗恩
回复:以箱线图的形式呈现股票数据好的,谢谢,我会注意的。 此致
回复:以箱线图的形式呈现股票数据您从 Yahoo Finance 数据返回的数据中发现的内容必须特定于国家/地区设置。 在美国返回给我的数据不必转换。回复:以箱线图的形式呈现股票数据非常感谢! 我试图在雅虎金融网站的数据上使用你的代码,但是,那里的数据被保存为带有“。”的字符。不允许将值转换为正确数值的小数点。 下面的代码片段转换列中的值并允许正确绘制它们。 感谢你并致以真诚的问候。
//open data
dt = open( "https://query1.finance.yahoo.com/v7/finance/download/URA?period1=1571303176&period2=1602925576&interval=1d&events=history&includeAdjustedClose=true" );
//change decimal point from "." to ",", otherwise later conversion to numeric format produces wrong results
nr = nrows(dt);
for (k = 1, k <= nr, k++,
dt:Open[k] = substitute(dt:Open[k], ".", ",");
dt:Close[k] = substitute(dt:Close[k], ".", ",");
dt:High[k] = substitute(dt:High[k], ".", ",");
dt:Low[k] = substitute(dt:Low[k], ".", ",");
dt:name("Adj Close")[k] = substitute(dt:name("Adj Close")[k], ".", ",");
);
//change format to numeric
dt:Open << Data Type( numeric ) << Modeling Type( continuous );
dt:Close << Data Type( numeric ) << Modeling Type( continuous );
dt:High << Data Type( numeric ) << Modeling Type( continuous );
dt:Low << Data Type( numeric ) << Modeling Type( continuous );
dt:name("Adj Close") << Data Type( numeric ) << Modeling Type( continuous );回复:以箱线图的形式呈现股票数据我有更多的时间来研究这个问题,我认为下面的简单解决方案可能对您来说是一个可行的解决方案。

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Stock Prices.jmp" );
dt:open << label;
dt:close << label;
gb = dt << Graph Builder(
Size( 1289, 456 ),
Show Control Panel( 0 ),
Variables( X( :Date ), Y( :High ), Y( :Low, Position( 1 ) ) ),
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 10 ), Bar Style( "Interval" ) ) ),
SendToReport(
Dispatch(
{},
"Date",
ScaleBox,
{ Interval( "Day" ), Inc( 1 ),
Minor Ticks( 0 )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
10,
Properties( 0, {Line Width( 2 )}, Item ID( "High..Low", 1 ) )
)}
)
)
);
// Add the boxes to the chart
Report( gb )[framebox( 1 )] << add graphics script(
halfDayincr = In Days( 1 ) / 2 * .8;
days = (Col Max( :Date ) - Col Min( :Date )) / In Days( 1 );
Pen Color( black );
Pen Size( 2 );
For( i = 1, i <= N Rows( dt ), i++,
If( :Open[i] <= :close[i],
Fill Color( light green );
,
Fill Color( light red );
);
Rect( :date[i] - halfDayincr, Max( :open[i], :close[i] ), :date[i] + halfDayincr, Min( :open[i], :close[i] ), 1 );
Rect( :date[i] - halfDayincr, Max( :open[i], :close[i] ), :date[i] + halfDayincr, Min( :open[i], :close[i] ), 0 );
);
);
回复:以箱线图的形式呈现股票数据是的,正如 Jim 指出的那样,Graph Builder 可以轻松做到这一点。 但是,当您获得更多数据时,您可能需要考虑 IR(个别移动极差图),因为这些将提供对指标随时间的一致性/稳定性的洞察力。
inkRe:以箱形图的形式呈现股票数据我认为这是 JMP 在不编写脚本的情况下所能做的最好的事情

但是只要稍加努力,就可以轻松编写一些 JSL 来创建烛台图。