Group Abstract Group Abstract

Message Boards Message Boards

1
|
8.7K Views
|
9 Replies
|
7 Total Likes
View groups...
Share
Share this post:

[?] Choose dates dynamically with a Slider?

Posted 8 years ago
POSTED BY: Laurens Wachters
9 Replies

Laurens,

I can't help you with CDF reader -- I've never used it. I would talk to Wolfram Tech support and ask why it does not work in CDF but works in WMA. From the documentation it does say that CDF has some limitations -- maybe entering data is one of them??

Maybe CloudDeployment or some other approach is better? I really do not know but they should be able to help you with this. Or a Wolfram employee on this forum?

As to the posted code -- I suggest we have a call to discuss the details -- email me at "neils" at the domain in my profile and we can discuss the code.

Regards

POSTED BY: Neil Singer
Posted 8 years ago

Dear Neil, Thanks a lot for your quick reply, and for your nice words. Unfortunately, the problem has not been solved yet. The CDF derived from your code will also not allow a change of stock. Anyway, I don't quite understand in what respect the code you added/changed could improve things. The only change in behavior that I found is that with my original code after changing the name of stock 1 or stock 2 all radio buttons are turned off, and with your code sometimes they stay on. Even the annoying blue bar accross the next text field that is shown after changing the name of one of the two stocks remained with your code.

It might be good for the sake of clarity to give you here the concepts behind my code: 1. Using FinancialData I fetch for all dates between Januari 1 2016 and yesterday the price data of two chosen stocks and put them in list1 and list2. 2. From list1 I get a list of all the dates and put them in listt. Using this I make the interval slider, and using this I define start and end. 3. With any of the radiobuttons I derive from list1 and/or list2 an appropiate list y. In the very basic example that I sent you only price 1 price 2 and price 1 / price 2 are shown, but I have developed some other possible lists. 4. Using start and end I derive from list y the partial list ypart, and also a list xpart. 5. After riffling xpart and ypart and partitioning the result I make the final plot. 6. In the plot I also show a whole lot of additional lines. I did not show these in my basic example. Their definitions depend on xpart, ypart, start and end. But it all works well. The only problem I am left wth is that in the CDF the Input fields of of the stock names refuse to work. But this is also the case with the code you suggested. I hope this explanation is clear enough.

As I wrote you yesterday I still feel myself a nitwit as to the use of Mathematica. It is therefore that I am looking for a real good systematic book on it. I have studied "The elementary introduction to the Wolfram Language". It is certainly useful, but it is not enough for me. For instance, I still don't understand completely the reasoning behind the code that you suggested. And also Dynamic remains sometimes an enigma for me. I thought maybe the Mathematica Cookbook might be useful, but I have read that it is kind of outdated by now. Is there anything else you can recommend?

To be more specific, I give you here a few examples of questions about your code proposals that I am stuck with: a. Why does the following combination work

listfun1 [a_,b_] := list1 = FinancialData [a,"OHLCV",{2016,1,1}];
listfun1[p1,p1];
listfun1 [c_,d_] := list2 = FinancialData [c,"OHLCV",{2016,1,1}];
listfun2[p2,p2];

and not

listfun1[a_] := list1 = FinancialData [a,"OHLCV",{2016,1,1}];
listfun1[p1]; 
listfun2[b_] := list2 = FinancialData [b,"OHLCV",{2016,1,1}];
listfun2[p2];

b. How should I interpret the following code of yours:

listfun1[a_]:= Module[ {} , list1 = FinancialData[a,"OHLCV",{2016,1,1}];
listt = list1[[All,1]];
y[[2]] = Switch[y[[1]],
" price of stock 1 ",list1[[All,2,4]],
" price of stock 2",list2[[All,2,4]],
"quotient stock prices 1 and 2",list1[[All,2,4]]/list2[[All,2,4]]];
start = Round[Length[listt]*0.25];
end = Round[Length[listt]*0.75]] ; 

What is for instance the purpose of the empty list in the begin of the module, and why do you need the Switch together with the radiobuttons? You may conclude that I hate to use code that I don't really understand.

I realize that I may bother you too much with my questions. I am sorry, but maybe you can help me to become a bit more proficient in writing Mathematica code. Anyway, thanks a lot for all the help you gave me sofar. Best regards, Laurens

POSTED BY: Updating Name
POSTED BY: Neil Singer
POSTED BY: Laurens Wachters
POSTED BY: Neil Singer

Thanks a lot for your advice. I have learnt a bit on Dynamic by now. But I am now stuck with Dynamic applied on FinancialData. I have made the following small program that should become a part of a cdf for analyzing the course of stock prices in which the user would be able to switch from stock to stock

p="ge";
Column[{DynamicModule[InputField[Dynamic[p]], 
Dynamic[ListLinePlot[FinancialData[p,{2017,10,1}][[All,2]]]]}]

This program does work, but after its evaluation my PC becomes awfully slow. Why is this, and would there be a remedy for it? I have a PC with an Intel i5 processor and 8 MB memory. Mathematica and its kernel don't seem to use very much of them, according to the windows 10 task manager. Another question is why in the result the input field and the plot are shown in a row and not in a column.

POSTED BY: Laurens Wachters

Dynamic then should be an outer wrapper not the inner:

list={
    {2000,1,3},{2000,1,4},{2000,1,5},{2000,1,6},{2000,1,7},
    {2000,1,10},{2000,1,11},{2000,1,12},{2000,1,13},{2000,1,14}};

Method 1 - indexed variable

Column[{
    Slider[Dynamic[m],{1,10,1}],
    Dynamic[DateString[DateObject[list[[m]]]]]}]

enter image description here

Method 2 - list of variables

Column[{
    Slider[Dynamic[m],{DateString[DateObject[#]]&/@list}],
    Dynamic[m]}]

Method 3 - localized variable

Manipulate[DateString[DateObject[m]], {m, list, Slider}]
POSTED BY: Vitaliy Kaurov
POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard