Plotting a general ZigZag curve with possible threshold value

I want to use zigzag curve to describe the trend of simple data. here is a list as


and I give new definition of FindPeaks and the related.

JFindPeaks[list_?ListQ] := MapAt[Round, FindPeaks[list] // N, {All, 1}]
JFindValleys[list_?ListQ] := Module[{x, y}, Map[({x, y} = #; {x, -y}) &, JFindPeaks[-list]]]
JFindExtremes[list_?ListQ] := Sort[JFindPeaks[list]~Join~JFindValleys[list]]

then some lists are computed as

peaks = JFindPeaks[lstPrices];
valls = JFindValleys[lstPrices];
extrs = JFindExtremes[lstPrices];

and two plots too,

p1 = ListLinePlot[lstPrices,
   Epilog -> {
     {Red, PointSize[0.015], Point[peaks]},
     {Blue, PointSize[0.015], Point[valls]}},
   PlotStyle -> Directive[Black, Dotted]
p2 = Graphics@Line@extrs;

finnally, the target plot comes out.

Show[p1, p2,
 AspectRatio -> 1/GoldenRatio,
 Frame -> True,
 GridLines -> Automatic,
 GridLinesStyle -> Directive[Gray, Dotted],
 ImageSize -> Large

It’s like this,

dNBIQ Plotting a general ZigZag curve with possible threshold value

but the most I want to get could be like the following one or the other similarly, or these sub-peaks-valleys should be ellminated on the plot.

JVeZN Plotting a general ZigZag curve with possible threshold value

so how to realize it? Maybe a threshold value is necessary. Thanks!

1 Answer

Let’s block ads! (Why?)

Recent Questions – Mathematica Stack Exchange