Serving the Quantitative Finance Community

 
User avatar
opmtrader
Topic Author
Posts: 4
Joined: September 25th, 2002, 6:10 pm

Real Time Plot in Matlab

January 9th, 2004, 2:48 pm

I was wondering if someone could guide me. I am trying to plot data from a .dat file that is being constantly updated. I would like to display a real time chart of this data from Matlab. Can this be accomplished easily? Of course I can plot static data. I am just new to linking to an updating database. I have yet to find anything in the Matlab help files addressing this but I am sure it must be possible. Any light you could shine on my problem would be greatly appreciated. Thank you for your help.
 
User avatar
thefullmoby
Posts: 0
Joined: December 18th, 2003, 4:25 pm

Real Time Plot in Matlab

January 9th, 2004, 8:16 pm

can't help with matlab, but i've done this with R a while back ...
 
User avatar
opmtrader
Topic Author
Posts: 4
Joined: September 25th, 2002, 6:10 pm

Real Time Plot in Matlab

January 9th, 2004, 9:11 pm

Are there any structural issues you could give me advice on? How quickly was R able to update its chart? My data is streaming in at roughly 4 times per second. Can it handle this?
 
User avatar
robertral
Posts: 0
Joined: March 6th, 2003, 7:12 am

Real Time Plot in Matlab

January 12th, 2004, 9:11 pm

I don’t think matlab has a real time plotting facility. If you are adamant in using matlab as your backend then try compiling your matlab code into C++ and go from there. Just an idea.Best of luck.
 
User avatar
matthewcroberts
Posts: 1
Joined: October 18th, 2001, 7:52 pm

Real Time Plot in Matlab

January 12th, 2004, 11:22 pm

opmtrader,What exactly are you trying to do? Do you just want a plot on your desk that is updated every ~4 seconds, but otherwise doesn't take any user input? If so, I can easily see how you'd accomplish this:while 1>0a=load('data.dat');plot(a);pause(5);endif you want actual interaction b/t user and data, then you'd have problems. You might also run into problems if the file were being updated while Matlab read it, but you should be able to handle that using try...catchIf you want more details, or have a large expense account burning a hole in your pocket, let me know & I can copy/paste that into an m-file for 'ya.HTH,matt.
Last edited by matthewcroberts on January 12th, 2004, 11:00 pm, edited 1 time in total.
 
User avatar
opmtrader
Topic Author
Posts: 4
Joined: September 25th, 2002, 6:10 pm

Real Time Plot in Matlab

January 13th, 2004, 3:52 am

Thanks for your help guys. I have a set of proprietary indicators for high frequency data which I have developed on static databases. I would like to add these indicators to my discretionary trading. To do so I need to see them building on a chart. I may be able to accomplish this the way Matthew suggested. However I am concerned that I may not be able to load the complete data set, do all the computations, and spit out a chart, in an effective time frame (i.e. 3 seconds). Hmmm... I have an idea how I can simply load and do computations on the most recent data. Thanks for getting my gears turning guys. Matt, if you'd really like to help me by showing me that code I would greatly appreciate it. Unfortunately for both of us I do not have an overflowing expense account to lavish on either one of us. I'm a private trader. Thanks.
 
User avatar
nono
Posts: 0
Joined: July 14th, 2002, 3:00 am

Real Time Plot in Matlab

January 14th, 2004, 9:34 am

thefullmoby,Would you be able to share what you've done?I'll be interested to know the way you did that in R.Thanks
 
User avatar
thefullmoby
Posts: 0
Joined: December 18th, 2003, 4:25 pm

Real Time Plot in Matlab

January 22nd, 2004, 3:41 am

hey folks,had a few pm-s asking about my "R solution."not too different from matt's post - though the trick is to get only the incremental data in the load and also to incrementally plot it ... which can take a bit of work. if the data is being written to a file you can try tail-ing it and checking for complete lines, though for high frequency stuff it starts to lag. i ended up writing some c++ and using R's .so loader to go straight to the data source at set periods to get the most recent data, which ended up working out pretty well. though if you need to have an R loop sleep be sure to use Sys.sleep(x) - can't remember what the other version of sleep available was, but it tended to do bad things ...
 
User avatar
ffyring
Posts: 0
Joined: July 14th, 2002, 3:00 am

Real Time Plot in Matlab

January 22nd, 2004, 12:33 pm

An idea is something like the following. The code plots the spread between to values.SZ = 1000;z = cumsum(randn(SZ,2)*chol([1 0.7;0.7 1]));t = 300;subplot(2,1,1)plot(1:t,z(1:t,1),1:t,z(1:t,2));subplot(2,1,2);hold onplot(z(1:t,1),z(1:t,2))point = plot(z(t,1),z(t,2));while(1) if t> SZ, break, end t = t + 1; subplot(2,1,1) hold off plot(1:t,z(1:t,1),1:t,z(1:t,2)); %remove old cross subplot(2,1,2) hold on delete(point); point = plot(z(t,1),z(t,2),'xr'); plot(z(t-1:t,1),z(t-1:t,2)) pause(1/5)end
 
User avatar
nikol
Posts: 5
Joined: January 29th, 2002, 9:14 pm

Real Time Plot in Matlab

January 27th, 2004, 1:42 pm

look some nice demo (Help window/Demos tab) called "Game of Life" or "Cool lines", then find their example codes and you are done...