Message Boards Message Boards

0
|
6812 Views
|
9 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How do you find out the structure of the output of a function

I am using the function FinancialData["stock","OHLCV", {start,end,period}] to get daily stock prices and the function returns a time series. My problem is that I want to visualize what I am getting so that I can extract just the high and low prices for each day. My issue is that I don't know how the returned data is organized. Without that knowledge I can't just extract the highs or the lows as a simple list. Can someone tell me where I can find detailed information on how the results of a function are organized. Things seem easy when asking for just one thing (like the closing price) but when asking for the "OHLCV" (Open, High, Low, Close, and Volume), I don't know where the date and the O,H,L,C,V are and how they are organized.

POSTED BY: Henrick Jeanty
9 Replies
Posted 4 years ago

Thank you Mike and Diego. Both of your answers were interesting and I plan on checking both of them. I find it interesting that Mike had to go look for quite a while before finding out the answer to this question. As someone more familiar and expert with procedural and Object-Oriented languages, I think that in Mathematica's documentation, when documenting a function, they should have a section showing exactly how the output is structured and give examples on how to access any particular member (in Object-Oriented parlance) one wishes to obtain. I still find the information from Mathematica, counter-intuitive. It seems one has to try a lot of things before finally understanding what the output looks like. That would explain why Mike had to "spent a lot of time digging into the docs of TemporalData and TimeSeries". I suspect I will have to do the same, but at least I now know where to look for. Mike's approach seems to require using "Head" and then having to go research whatever that returns, in his case, TemporalData. In Diego's answer, I get that you can get an idea of what is in the returned data (all those fields should, in my opinion, be in the documents. How am I to know that there are all those fields that I could ask about. Again, in my opinion, this is something that should be in the docs. But, I'm new (again) here and will go ahead an try both Mike's and Diego's suggestions. Now, I asked my notebook to go get "data = FinancialData[stock, "OHLCV", dateRange] // AbsoluteTiming;" and that is taking minutes upon minutes. But that is another story.

Thank you Mike and Diego for your replies. Henrick

POSTED BY: Updating Name

Thank you Mike and Diego. Both of your answers were interesting and I plan on checking both of them. I find it interesting that Mike had to go look for quite a while before finding out the answer to this question. As someone more familiar and expert with procedural and Object-Oriented languages, I think that in Mathematica's documentation, when documenting a function, they should have a section showing exactly how the output is structured and give examples on how to access any particular member (in Object-Oriented parlance) one wishes to obtain. I still find the information from Mathematica, counter-intuitive. It seems one has to try a lot of things before finally understanding what the output looks like. That would explain why Mike had to "spent a lot of time digging into the docs of TemporalData and TimeSeries". I suspect I will have to do the same, but at least I now know where to look for. Mike's approach seems to require using "Head" and then having to go research whatever that returns, in his case, TemporalData. In Diego's answer, I get that you can get an idea of what is in the returned data (all those fields should, in my opinion, be in the documents. How am I to know that there are all those fields that I could ask about. Again, in my opinion, this is something that should be in the docs. But, I'm new (again) here and will go ahead an try both Mike's and Diego's suggestions. Now, I asked my notebook to go get "data = FinancialData[stock, "OHLCV", dateRange] // AbsoluteTiming;" and that is taking minutes upon minutes. But that is another story.

Thank you Mike and Diego for your replies. Henrick

POSTED BY: Henrick Jeanty
Posted 4 years ago

Hi Henrick,

With many constructs in WL such as Dataset, TimeSeries, ConditionalExpression, GraphicsComplex... it is often more convenient to work with the Normal representation. Take a look at

(ge = FinancialData["GE", "OHLCV", DayPlus[Today, -10]]) // Normal
POSTED BY: Rohit Namjoshi

Thanks Rohit, I was not aware of Normal. I'll have to check it out. In any case, can you provide an expression to just get the highs as a simple list, not a time series?

POSTED BY: Henrick Jeanty
Posted 4 years ago

Hi Henrick,

If you are just interested in the highs then this is one way

FinancialData["GE", "High", DayPlus[Today, -10]]["Values"] // Normal

Each element in the list is a Quantity with units of "USDollars". To get the raw numbers without the units

FinancialData["GE", "High", DayPlus[Today, -10]]["Values"] // Normal // QuantityMagnitude
POSTED BY: Rohit Namjoshi

Hello Rohit. Thank you very much for your answer. It actually answered another question I had. I was trying to use Position[highs, h_ /; h > highs[[i]]] where highs is obtained by getting the financial data from a stock and was getting an error of "Greater::: Comparison of 1372.5` and $482.95 is invalid." This led me to think that one could not compare currencies. I will use "Values" and "QuantityMagnitude"

POSTED BY: Henrick Jeanty
Posted 3 years ago

Hi Henrick,

Currency quantities can be compared, even for different currencies (current exchange rate is used). e.g.

d1 = Quantity[10, "USDollars"];
d2 = Quantity[100, "USDollars"];
d3 = Quantity[10, "Euros"];

d2 > d1
(* True *)

d3 < d1
(* False *)
POSTED BY: Rohit Namjoshi

It may be useful to convert that data within the Wolfram Data Framework. For that you can use the knowledge representation as entities as follows:

enter image description here

Once you get this, you can extract the desired properties for each entity. For example enter image description here

POSTED BY: Diego Ramos
Posted 4 years ago

As a general answer, just call Head on an interesting value returned from the function.

Let's look at GE...

ge = FinancialData["GE", "OHLCV", DayPlus[Today, -10]];
ge // Head

returns

TemporalData

The documentation for Temporal Data tells us how to pull the data out. For example:

ge["PathComponents"]

returns a list of 5 TimeSeries. Unless things have changed (which they might have, so please verify), I believe that these TimeSeries are the Open, High, Low, Close and Volume data, in that order.

When I was looking into this a few months ago, I spent a lot of time digging into the docs of TemporalData and TimeSeries.

Good luck.

POSTED BY: Mike Besso
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