# Access curated or locally stored data with curated data functions?

Say I have a toy package, something like:

BeginPackage["myPackage"]
plotSomeData::usage = "plotFinancialData[symbol]... some usage language";
Begin["Private"]
plotSomeData[symbol_]:= DateListPlot[FinancialData[symbol, All]]
End[]
EndPackage[]


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[
Which[
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.)

-
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. –  Leonid Shifrin Apr 17 '13 at 0:17
@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? –  Jagra Apr 17 '13 at 2:03
Yes, that's right. –  Leonid Shifrin Apr 17 '13 at 11:19
@LeonidShifrin -- Certainly worthy of an accepted answer in my opinion. If you want to post it, you've got my vote. - Thx. –  Jagra Apr 17 '13 at 16:09
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. –  Leonid Shifrin Apr 17 '13 at 16:16

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];
data[[Flatten[pos][[1]]]]]

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

32.45

{{{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.

-