Time range selector à la InteractiveTradingChart

11

5

I have time series data and I would like to interactively select a part of it. This problem is beautifully solved in the lower part of the InteractiveTradingChart command:

enter image description here

I would like to be able to do the same for my own data. Before I reinvent the wheel I would like to know if this is already available somewhere. In case I do have to reinvent it, this is what I have already done:

data=Map[{#,RandomChoice[{.75,.15,.05,.04,.01}->{0,1,2,3,5}]}&,DateRange[{2013,1,1},{2013,12,31}]];

g=DateListPlot[data,Joined->True,Filling->Bottom,AspectRatio->1/10,Frame->None,Axes->{True,True},PlotRange->{0,5},ImageSize->640];

Module[{windowSize=QuantityMagnitude@UnitConvert[Quantity[3,"Month"],"Second"]},
  Grid[
    {{Dynamic@Show[g, 
        Epilog->{EdgeForm[Gray], FaceForm[Cyan], Opacity[0.5],
                 Rectangle[{x-windowSize/2, 0},
                           {x+windowSize/2, Max[Last/@data]}], 
                 FaceForm[LightGray], Opacity[1], 
                 Rectangle[{x-1.05windowSize/2, .25Max[Last/@data]}, 
                           {x-0.95windowSize/2, .75Max[Last/@data]}],
                 Rectangle[{x+0.95windowSize/2, .25Max[Last/@data]},
                           {x+1.05windowSize/2, .75Max[Last/@data]}]
                }]},
    {Slider[Dynamic[x], 
            {AbsoluteTime[{2013,1,1}], AbsoluteTime[{2013,12,31}]},
            Appearance->"UpArrow", ImageSize->640]}}]]

Mathematica graphics

Gustavo Delfino

Posted 2013-03-15T13:13:10.277

Reputation: 6 847

I think "Second" needs to become "Seconds" for the UnitConvert to work. – Jagra – 2013-03-15T13:37:24.297

This will take someone sometime to develop a solution. I think any of us will get there faster if we have more specifics about what you want to do. Your supplied code gives a nice window on the data that moves with the slider. It looks like you may want to adjust the size of this window and then link this complex control to the display of another set of data, essentially zooming in and out on the data. I like this idea a lot and have implemented some similar things. Let's make certain about what you want from your question. Please clarify the question before anyone heads down a wrong path. – Jagra – 2013-03-15T13:45:17.240

1

Mike Honeychurch has an interesting blog post about this.

– Leonid Shifrin – 2013-03-15T13:52:43.597

@LeonidShifrin - Mike's blog post looks more than interesting! He nails it. Now if Mr. Wizard took up the challenge he might just render the entire code in 27 characters, but short of that Mike deserves credit for the answer ;-)> – Jagra – 2013-03-15T14:50:03.987

@LeonidShifrin Thank you. This is what I needed. – Gustavo Delfino – 2013-03-15T16:10:43.800

I wonder what would happen if I posted a FullForm of the trading chart output... – amr – 2013-03-18T02:10:47.000

Answers

3

To put Leonids comment into an answer: Please see the blog-post of Mike Honeychurch at ibnhconsulting.blogspot.ru. This should help you.

enter image description here

halirutan

Posted 2013-03-15T13:13:10.277

Reputation: 109 574