Message Boards Message Boards

0
|
12770 Views
|
14 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Simulating a real-time ticker

POSTED BY: Henrick Jeanty
14 Replies

POSTED BY: Henrick Jeanty

The answer to your query is already contained in the use of the function InteractiveTradingChart. At the bottom of its display, just under the date boxes and above the chart type menu, there is a timeline for the entire history chosen in the command, with a slider control. That slider can be moved to any point in the financial history and its edges can be moved in or out so that the displayed data can be concentrated on as few points or as many points as you wish.

POSTED BY: Michael Kelly
POSTED BY: Michael Kelly
Posted 4 years ago

Henrick:

I'd be interested in collaborating with you on this sort of thing. But, I won't have any availability for a couple of weeks.

If you want a collaborator, just let me know.

POSTED BY: Mike Besso

Hello Mike, Collaboration is always good in my book. Pease realize that though proficient in C#, I am not so with Mathematica. I started with Mathematica about 6 years ago and it has been in fits and starts. I would get discouraged by how different Mathematica was from your other languages and would go back to C# where I felt I was more productive and really knew what I was doing. I even had a period where I used NetLink to have Mathematica call libraries I had written in C#. I also understand that I could have worked the other way around, using Mathematica from C#. But this time, I decided to dedicate myself to rewriting my whole application in Mathematica. My day job is as an instructor in the department of Computer Science at the University Of South Florida, in Tampa. Though I have taught in the Computer Science Department for the past 15 years, my Ph,D, is in Electrical Engineering with a specialization in Signal Processing and Pattern Recognition. I have worked in handwriting recognition and image processing at IBM's TJ Watson Research Lab, face recognition, stock pattern recognition. Because of those areas of interest, I have spent most of my time coding solutions to problems in the aforementioned fields. I have been interested in the stock market since I worked for a startup that wanted to recognize stock patterns to give advice about buying, selling or holding stocks. I have been working on my hobby for the last 20 years and my ideas on how to solve the problem of finding patterns in stock charts have evolved, particularly in terms of implementing algorithms to detect patterns and more importantly, see if there are any patterns, and if so, if they have any predictive capability. Knowing one way or another would be important. Perhaps you can tell me about yourself, your interests, why this interests you, your experience in this area, etc...

Regards, Henrick Jeanty

POSTED BY: Henrick Jeanty
POSTED BY: Henrick Jeanty
POSTED BY: Henrick Jeanty
Posted 4 years ago

Henrick,

I also noticed that the animation is sluggish / erratic when it starts, but tends to smooth out if it is left running for a full cycle. Did not see any error display in the expression though. One way to improve performance is to rasterize the frames. Takes longer up-front but the animation works better.

rasterFrames = Rasterize[#, "Image"] & /@ frames;
ListAnimate[rasterFrames, DefaultDuration -> Length@data]
POSTED BY: Rohit Namjoshi

Hello Rohit, This is much better. I will try it. Thanks.

POSTED BY: Henrick Jeanty

enter image description here

enter image description here

To add a variant of @Rohit's nice example I'd mention possibility of creating a GIF where you can define time each frame duration with option "DisplayDurations" in seconds (in the images above it is 0.1 and o.5 seconds to see the difference). You also can speed up and control appearance with some options (ParallelTable, PerformanceGoal, etc). It would go something like this:

data = FinancialData["GE", "OHLCV", {{2020, 01, 01}, Today, "Week"}]["DatePath"];

frames = ParallelTable[
TradingChart[data[[1 ;; n]],
AspectRatio->1/4,PerformanceGoal->"Speed",ImageSize->800], 
{n, 2, Length@data}];

Export["itcanim.gif",frames,"DisplayDurations"->.5]
POSTED BY: Vitaliy Kaurov

Hello Vitaly, Wow! This looks great. Let me first say this. This Wolfram Community is absolutely wonderful. You ask a question and very quickly you get replies from knowledgeable people. I love it !

However, I have another problem which has to do with my previous way (meaning C# in Windows) to do things. I really love how you even provide code AND the resulting animation. Thank you so much. I would have an event that would say that I have a new candlestick. Upon receiving the event, I would then have code execute to update the effect of the new candlestick on the data we had so far. My question becomes, how can I use the new animation to call my code (basically, analyzeNewBar[newBar] where I would pass the new bar to my algorithm. Perhaps you can send me some code where you could show me where I would: 1) Know what the latest candle (newCandle) is. 2) call analyzeNewBar[newCandle]

I have a new question, but I will be starting a new discussion with it.

POSTED BY: Henrick Jeanty
Posted 4 years ago

Henrick,

Is there a reason for wanting to couple the analysis with the animation? All of the data that is going to be animated is already available in data so you can pre-compute. Here is a trivial example that precomputes the change in volume between samples and adds it to the chart as a label during the frame generation.

analyzeData[data_] := data[[All, 2, 5]] // Differences
volumeChange = analyzeData[data];

frames = ParallelTable[TradingChart[data[[1 ;; n]],
    PlotLabel -> 
     "Volume Change: " <> ToString[DecimalForm[volumeChange[[n - 1]], DigitBlock -> 3]],
    AspectRatio -> 1/4,
    PerformanceGoal -> "Speed",
    ImageSize -> 800],
   {n, 2, Length@data}];

Export["tcanim.gif", frames, "DisplayDurations" -> 1]

enter image description here

POSTED BY: Rohit Namjoshi

Rohit, I've been looking at your solution a bit more in order to try to understand what it does. You get the data through FinancialData[...] You then make a table of individual frames, with one frame for each new bar. The frame contains as many bars as the index of the frame (i.e. Frame # 20 would show 20 bars) and the defaultDuration is the number of frames/second. What I really want to do is draw my own graphics (mostly lines) on individual frames. Is that even possible to do ?

POSTED BY: Henrick Jeanty
Posted 4 years ago

Hi Henrick,

I could not find a way to programmatically change the date range in InteractiveTradingChart. You could try something like this.

data = FinancialData["GE", "OHLCV", {{2020, 01, 01}, Today, "Week"}]["DatePath"];
frames = Table[TradingChart[data[[1 ;; n]]], {n, 2, Length@data}];

(* Update every second, scale DefaultDuration to reduce update frequency *)
ListAnimate[frames, DefaultDuration -> Length@data]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract