4

As I am trying to plot a few financial time series in Mathematica, I just ran into a problem illustrated in the figure below :

It seems the data are no longer dealt with after Year 2000

Is there a way to fix that ?

What would be the best format to export time series from Bloomberg or Excel to use them in Mathematic (Using version 8).

I do know about the FinancialData function. However, not knowing the exact symbols, it makes it extremely difficult to use Mathematica directly for this.

enter image description here

500
  • 6,509
  • 8
  • 46
  • 80
  • 1
    It is interesting to note that `DateList[{"Nov 2011", {"MonthName", " ", "Year"}}]` doesn't work (try it), even though `StringMatchQ["Nov 2011", DatePattern[{"MonthName", " ", "Year"}]]` gives `True`. I suspect a bug. – Szabolcs Jan 17 '12 at 15:24
  • Related (but not an answer): http://stackoverflow.com/questions/8719842/import-data-from-url – Szabolcs Jan 17 '12 at 15:36

3 Answers3

6

Why not to use WolframAlpha[...] function - it imports native to Mathematica format and goes up to current dates:

    timeseries = WolframAlpha["msft close Jan 1, 2010 to Jan 21 2011",
{{"DateRangeSpecified:Close:FinancialData", 1}, "TimeSeriesData"}];
DateListPlot[timeseries]

enter image description here

That was just an example of input. I am not sure what kind of data you need exactly, but you can get a lot of them via WolframAlpha function. Read this:

1) WolframAlpha 2) Data Formats in Wolfram|Alpha

Vitaliy Kaurov
  • 1,298
  • 7
  • 21
  • @Vitaly, Thank you very much for your answer. I shall try this as soon as I am back to work ! – 500 Jan 20 '12 at 20:05
5

Use the DateFunction option to tell DateListPlot how to convert dates:

DateFunction -> (DateList[{#, {"MonthNameShort", "YearShort"}}] &)

(The parentheses are important.)

Brett Champion
  • 8,497
  • 1
  • 27
  • 44
  • I was doing precisely the same but `DateList[{"Nov-11", {"MonthNameShort", "YearShort"}}]` gives me `DateString::str`! – Szabolcs Jan 17 '12 at 15:30
  • This doesn't seem to work with a non-English locale on Windows (tried with Hungarian and US English, and it only worked with English) – Szabolcs Jan 17 '12 at 20:10
  • These dates most likely reflect monthly closing prices. It would be good it you could specify that the `DateList` was for the close of the month rather than for the start. You can obviously make the changes to the `DateList` post conversion but would be nice if the options existed ...or maybe it does but I don't know it?? – Mike Honeychurch Jan 17 '12 at 22:01
  • @MikeHoneychurch You could use `DatePlus` to move to the end of the month (perhaps with +1 month, -1 day). – Brett Champion Jan 17 '12 at 22:04
  • @Brett that is what I currently do but was just making the observation that it would be nice if this could be done via some sort of option. – Mike Honeychurch Jan 17 '12 at 22:34
  • @Brett, note also the continued frustration with the slowness of date and time functions: http://www.wheels.org/monkeywrench/?p=453 – Mike Honeychurch Jan 17 '12 at 22:35
3

Here's a function to convert those date strings to a format Mathematica can handle better:

dateConv = With[{s = StringSplit[#, "-"]}, {DateList[{s[[2]], "YearShort"}][[1]],
     DateList[s[[1]]][[2]]}] &

You can try

DateListPlot[data, DateFunction -> dateConv]

EDIT: Originally I tried DateList[{"Nov-11", {"MonthNameShort", "YearShort"}}] but this tells me String "Nov- 11" cannot be interpreted as a date in format {"MonthNameShort", "YearShort"}.. Perhaps a bug?

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
  • It works for me as it is, but I normally use DateList[{"Nov-11", {"MonthNameShort", "-", "YearShort"}}] and it always works. – b.gatessucks Jan 17 '12 at 15:55
  • @b.gatessucks It does not work here in Mma 8.0.4 (Windows), separator specified or not. I did try the separator form as well before I decided to make the workaround-function from my answer. – Szabolcs Jan 17 '12 at 16:00
  • I confirm it works with Mma 8.0.4 both on Windows 7 and Linux 64 bit. – b.gatessucks Jan 17 '12 at 19:06
  • @b.gatessucks Thanks! It must either be XP specific or my Mma installation is broken then – Szabolcs Jan 17 '12 at 19:14
  • 1
    @b.gatessucks I figured it out: on Windows it only works if I set the locale to US English. – Szabolcs Jan 17 '12 at 20:09