Message Boards Message Boards

Increase speed in notebook that uses Dynamic[FinancialData]


I want to make a cfd that presents an analysis of the course of stock prices obtained from FinancialData and in which the user can jump from one stock to another. But when I for instance make a notebook with the following commands


Mathematica becomes awfully slow, while other programs at the same time keep running at the usual speed. Is there any remedy for this problem? In the Windows 10 task manager I can see that Mathematica uses only about 1% of the Intel i5 processor and 92 MB of the 8 GB memory while the Mathematica Kernel uses about 5% of the processor, 288 MB of the memory and 1 to 2 Mbps of my 50 Mbps download internet connection speed.

POSTED BY: Laurens Wachters
13 days ago

have the same symptom (plus a lot of time out to the wolfram alpha servers :()

POSTED BY: l van Veen
13 days ago

See below the reply that I got on this from Neil Singer after asking the same question as a sequel in the discussion titled "Choose dates dynamically with a slider?". Both programs turn out to work beautifully.

Laurens, Your posted code did not have matching delimiters but I got the same behavior (once fixing it) because the FinancialData call is time consuming. I fixed it one way (the easy way --- but more limiting) with this code by using a Manipulate.

 ListLinePlot[FinancialData[p, {2017, 10, 1}][[All, 2]]], {p, "ge"}, 
 ControlType -> InputField]

You can use Dynamic directly but you must handle more details this way:

DynamicModule[{p, plotfun, plot}, p = "ge"; 
plotfun[a_, b_] := 
plot = ListLinePlot[FinancialData[a, {2017, 10, 1}][[All, 2]]]; 
plotfun[p, p]; 

Column[{InputField[Dynamic[p, {Automatic, plotfun}], String], 

The way this works is to make the variables p, plotfun (the function for plotting), and the plot itself local . This is so we do not mess with global variables (although you can make them global if you want). I define a function to make the plot called "plotfun" so I can call it two times -- once at initialization so we start with a default plot and once in operation. Note that I used String as the second argument to InputField so we do not need to deal with the quotation marks. I use the optional arguments to Dynamic {fstart,f,fend}. Read about these but I defined them to be {Automatic, plotfun} -- during editing the inputfield MMA automatically updates the variable "p" but at the end (when you hit tab or return) it runs the function "plotfun" (which updates our plot --- only once!!! so we do not bring the machine to its knees repeatedly getting financial data. Regards Neil

POSTED BY: Laurens Wachters
11 days ago

Group Abstract Group Abstract