Say I have a toy package, something like:

plotSomeData::usage = "plotFinancialData[symbol]... some usage language";
plotSomeData[symbol_]:= DateListPlot[FinancialData[symbol, All]]

This should work fine, nothing particularly complicated here.

So now, I'd like to extend the FinancialData[] function embedded in the package to enable it to seamlessly access non-Wolfram curated data stored locally on my computer.

I could rewrite the package and set up some conditional code that would replace FinancialData[] with Import[], something like:

plotSomeData[symbol_] := DateListPlot[
   symbol == "xyz", Import[pathAndFileName],
   symbol != "xyz", FinancialData[symbol, All]

But, in my case, that would mean rewriting a bunch of perfectly good packges, so I'd like another solution. Some of the questions and answers such as:

What is a paclet?

UpValues TagSet and UpSet

have me wondering if another more elegant way exists to do this.

Could, for instance, one extend the paclet information for a set of curated data?

I've used TagSet before to do things like define how to calculate the CDF of a custom distribution, but I don't see a clear way to use it to enable a curated data function to recognize the location of a data symbol it doesn't already know.

SetOptions doesn't seem like the thing either.

UpVales and UpSet might do it, but I don't see it yet.

Ideally, I'd simply like to extend a curated data function to recognize the location of a data symbol it doesn't already know and thereby enable it to get the newly identified data.

Best if I can do this outside of the packages I already have.

Any ideas?

(The tags I have on this question could use some improvement, if anyone has some better ideas.)

  • $\begingroup$ You can't add rules to FinancialData, since it is Locked. As you mentioned yourself, UpValues can help. You can define a given symbol as sym/: FinancialData[sym,...]:=..., where you can insert on the r.h.s. the definition you want. $\endgroup$ Apr 17, 2013 at 0:17
  • $\begingroup$ @LeonidShifrin -- I think I understand. The r.h.s would become my Import[pathAndFileName]. That should enable me to do additional statements for other symbols that would correspond to their own data sets? $\endgroup$
    – Jagra
    Apr 17, 2013 at 2:03
  • $\begingroup$ Yes, that's right. $\endgroup$ Apr 17, 2013 at 11:19
  • $\begingroup$ @LeonidShifrin -- Certainly worthy of an accepted answer in my opinion. If you want to post it, you've got my vote. - Thx. $\endgroup$
    – Jagra
    Apr 17, 2013 at 16:09
  • $\begingroup$ No time for it at the moment, alas. Will do when I get some window, unless someone does that first. Also, feel free to post your own answer based on the hints I gave, and accept that. $\endgroup$ Apr 17, 2013 at 16:16

1 Answer 1


As @Mr.Wizard asked, "...it's time for an answer, don't you think?".

I forgot about this question, but after year it occurred to me to formulate an answer following @LeonidShifin suggestions:

First get some test data:

testData = FinancialData["GE", "Jan. 1, 2000"][[1 ;; 10]];
dataFile = "/Users/jagra/Data.test.csv";
Export[dataFile, testData, "CSV"];

Apply UpValues

sym /: FinancialData[sym] := Last[Import[dataFile]][[2]]
sym /: FinancialData[sym, All] := Import[dataFile]
sym /: FinancialData[sym, date_String] := Module[{data, pos},
  data = Import[dataFile];
  pos = Position[data, date];

FinancialData[sym, All]
FinancialData[sym, "{2000, 1, 4}"]


{{{2000, 1, 3},32.24},{{2000, 1, 4},30.95},{{2000, 1, 5},30.89},{{2000, 1, 6},31.31},{{2000, 1, 7},32.52},{{2000, 1, 10},32.5},{{2000, 1, 11},32.56},{{2000, 1, 12},32.67},{{2000, 1, 13},33.04},{{2000, 1, 14},32.45}}

{{2000, 1, 4},30.95}

This doesn't show all possible configurations for getting data (and even has a shortcut in using "{2000, 1, 4}") , but I think it demonstrates the flexibility of the approach.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.