以箱形圖的形式呈現股票數據大家好,
描述股票價格變動的數據是由開盤價/收盤價和最高/最低價創建的。 有沒有什麼方法可以在 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 來創建燭台圖。