Message Boards Message Boards

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

Saving Financial Data for faster access.

I am interested in reading financial data and I use the following statement: originalData = FinancialData[stock, "OHLCV", dateRange] // Normal // QuantityMagnitude;

However, this always requires getting the data through the Internet (at least in my understanding). I would like to be able to read the data for a number of stocks (perhaps all of the S&P 500) over a certain period (and I don't care if it takes all night), but I would like to be able to store the data in a set of files (each file would be named after the stock whose data it has) so that in the future, when I want to read the data for a stock during a period of time included in the data, I can read it directly from the file on my computer. This would make it: 1) Faster 2) No longer dependent on me being connected to the Internet (since I use a Satellite connection (one of the disadvantages of living in a rural area is that a Satellite connection might be all you have) Could someone tell me how I could do that? I understand that perhaps using paclets might be the way to do it. Is it possible for me to do that?

POSTED BY: Henrick Jeanty
3 Replies
Posted 3 years ago

Here is one way to do it.

Get stock data:

ticker = "AAPL";
dateRange = {{2020, 1, 1}, Today};
originalData = FinancialData[ticker, "OHLCV", dateRange] // Normal // QuantityMagnitude;

Create a file name:

fileName = StringJoin[ticker, "_", DateString[Today, {"Year", "Month", "Day"}]]

Put in file:

Put[originalData, fileName]

Read in and check:

newData = Get[fileName];
newData == originalData

You can gather up the code in a function to create files for all the stocks and date ranges you'd like to store.

POSTED BY: Lee Godfrey
Posted 3 years ago

Hi Henrick,

All thats been said above works fine. But I want to point out another method, using the function Iconize, which is new since 11.3.

  • While connected to internet, in a notebook, evaluate Iconize[some data from the Wolfram servers, your name of the data]. The downloaded data will then reside within the notebook.
  • Save the notebook. Close Mathematica. Disconnect internet.
  • Restart Mathematica. Keep internet off. Open the saved notebook. Evaluate the icon: Click, Shift+Enter. The data is shown.

Example:

Iconize[PlanetData[PlanetData[], {"Name", "Radius"}], "Radiuses of planets"]

enter image description here

The data saved in this way does not have to come from the web. It could also be the result from a time consuming computation within Mathematica.

POSTED BY: Hans Milton

Thank You Lee! What else can I say? Again, thank you!

POSTED BY: Henrick Jeanty
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