‹›画像処理と信号処理動的時間伸縮法を使って株価を比べる
WarpingCorrespondenceを使って,ヒューレット・パッカード(HPQ)の2016年第1四半期の株価と2010年から2015年にかけての過去のデータを比べる.
recent = FinancialData["HPQ", {{2016, 1, 1}, {2016, 3, 31}},
"Value"];
{histDates, hist} =
Transpose[
FinancialData["HPQ", {{2010, 1, 1}, {2015, 1, 31}}, "DateValue"]];
過去のデータの中で最もよくマッチする部分配列を求める.
{corrHist, corrRecent} =
WarpingCorrespondence[hist, recent,
Method -> {"MatchingInterval" -> "Flexible"}];
2016年第1四半期のデータに最もよく似た過去のデータを検出する.
{m, n} = corrHist[[{1, -1}]];
histDates[[{m, n}]]
最近のデータと過去の一番よくマッチしているデータとを視覚的に比べる.
完全なWolfram言語入力を表示する
DateListPlot[{AssociationThread[
Take[histDates[[m ;; n]], Length[recent]], recent],
AssociationThread[histDates[[m ;; n]], hist[[m ;; n]]]},
PlotTheme -> "Business",
PlotLegends -> {"2016 data", "Best historical match"},
DateTicksFormat -> {"MonthNameShort", " ", "YearShort"},
ImageSize -> Medium]
過去のデータから次の30日間の株価を予測する.
完全なWolfram言語入力を表示する
l = Length[recent];
colDat = ColorData["Atoms"];
offset = Last[recent] - hist[[n]];
hist30d = hist[[n ;; n + 30]];
ListLinePlot[{recent, {l + Range[31], hist30d + offset}\[Transpose],
hist[[m ;; n]], {n - m + Range[31], hist30d}\[Transpose]},
PlotStyle -> {colDat["Rh"], {colDat["Mo"], Dotted},
colDat["Yb"], {colDat["Tb"], Dotted}},
PlotLegends ->
Placed[{"2016 data", "30 days prediction", "Best historical match",
"Next 30 days of historical data"}, Below], ImageSize -> Medium,
Axes -> {False, True},
Epilog -> {Dashed, {Arrow[{{n - m, hist[[n]]}, {l + 1,
Last[recent]}}],
Arrow[{{n - m + 30, hist[[n + 30]]}, {l + 31,
hist[[n + 30]] + offset}}]}}]