Author Archives: stern

MTA BusTime is a great thing

Usually, in New York, if you want to get someplace more than a few blocks away, you take the subway, or if you need to go crosstown, you brace for misery and take the bus. Busses are typically more pleasant than subways, but they are often slow and come unpredictably. I’d be delighted to take my boys to school on the M60 every morning, but busses can come 20 minutes apart. Of course, when you do get one, two others will often follow close on its heels.

The MTA has finally launched, city-wide, an online service that tells you when busses are coming. It’s called BusTime.

bustime logo

 

As is standard practice for the MTA, they have made the BusTime data feeds publicly available, so that people can integrate them into iPhone apps and the other services. The bus app that I use, unfortunately, seems to have done this incorrectly.

NYC Bus logo

 

It clearly believes it has the correct data but the results it produces are nonsense. A friend at the MTA guesses that it is reporting the busses as scheduled, rather than the their actual locations. The easiest solution is to tap into the MTA’s data feeds at their own mobile website. For example, the URL to check the busses in front of my son’s school is http://bustime.mta.info/m/?q=403119 and it produces results like this:

bus time

 

Totally accurate, and hugely useful as we decide whether to take the bus or the subway each day.

Rando is a newish “anti-social” photo sharing app, available for iOS and Android. You snap a picture (it’s automatically cropped to a round shape), and Rando sends it to somebody far away. You never learn who they are, though Rando will later tell you where in the world they live. (Brazil and Russia are common destinations). The recipient of your photo is similarly told where you are, but nothing else, and has no way to contact you (though they can rate your photo, and some people have been posting “randos” of their e-mail address as a way of establishing contact with strangers.

I found the service charming for a while. The serendipity of it, slices of life from half a world away.

But pretty soon a problem emerged. I would send photos like these:

Broadway and 110th

Broadway and 110th

Boys' Gate, Central Park

Boys’ Gate, Central Park

Citibikes

Citibikes

Battery Place Statue of Liberty

Battery Place Statue of Liberty

 

and I’d get back photos like these:

Fluorescent light, Santa Barbara

Fluorescent light, Santa Barbara

Fluorescent light, South Korea, near the DMZ

Fluorescent light, South Korea, near the DMZ

Shoes, Curitiba Brazil

Blurry shoes, Curitiba Brazil

Who knows? Central U.K.

Who knows? Central U.K.

It’s easier to take a lousy picture than a good one, and absent any kind of reputation system, Rando has no way to encourage people to send anything interesting. The result is a lot of blurry photos of people’s feet and of fluorescent lights.

Bloomberg to Mathematica

Several years ago, my team and I created a tool for importing data via the Bloomberg API directly into Mathematica. It works perfectly and we made both the code and the executable interface available via the Wolfram library. Apparently, Wolfram has removed it, perhaps because it competes with identical functionality in the Wolfram Finance Platform. But the Bloomberg to Mathematica link is free, and a Wolfram Finance Platform license costs $10,000, so people have asked me to put this online somewhere.

So here it is.
[2016 update — I’ve removed the old link as the executables and source code there were outdated. Get the current version at GitHub]

You need to have a Bloomberg Professional license, and as the Bloomberg data API works only on Windows, you need to be running Bloomberg and Mathematica on Windows (I’ve tested this in Windows XP through 8, and with versions of Mathematica through 9.0. Let me know if you run into problems with other setups).

The source code is included here; feel free to make modifications if you like. If you do anything interesting please share it back, it would be nice to see Mathematica used more widely in finance, and free sharing of tools like this would have to help.

Update, 2015:
I have added a new interface notebook for those using Mathematica 10. It fixes some bugs, increases flexibility, and most importantly, takes input and produces output using Mathematica’s new date and temporal data types, and using an Association rather than a list. It’s cleaner and more robust than the old method (though the old notebook will continue to work for those afraid of change.) If you upgrade from the old interface to the new one, note that all the functions have changed names, and their default installation path has as well. It’s all documented in the new notebook in the zip file above.

(Sample use of the old code shown below)

cpi2 = bbg2Mdates[
BBGetNF1["JNCPIYOY Index", "Px_Last", "19820101", "", "monthly"]];

tpxNorm2 =
SternChangeCharNF1[
bbg2Mdates[
SternNormalizeNF1[
BBGetNF1["TPX Index", "Px_Last", "19820101", "", "monthly"]]],
name -> "TPX"];

Show[DateListPlot[cpi2[[2]], Frame -> {True, True, False, False},
Joined -> True, Filling -> 0, FillingStyle -> {Blue, White},
GridLines -> False, PlotRange -> All, PlotStyle -> Purple],
DateListPlot[tpxNorm2[[2]], Frame -> {True, True, False, False},
Joined -> True, GridLines -> False, PlotStyle -> Pink],
PlotLabel -> "日本 inflation has been low since \!\(\*
StyleBox[\"before\",\nFontSlant->\"Italic\"]\) the market crashed",
Axes -> {True, False}, PlotRange -> All,
Epilog -> {(Text[
Style["stock market", FontFamily -> "Times New Roman",
FontSize -> 10, Pink], {AbsoluteTime["6/1/1986"],
4.4(*vertical position*)}, {-.01, 0}(*
how close to the end *)]), (Text[
Style["CPI", FontFamily -> "Times New Roman", FontSize -> 10,
Purple], {AbsoluteTime["1/1/1983"],
3.6(*vertical position*)}, {-.01, 0}(* how close to the end *)])}
]

japan inflation

A demonstration of the new code can be found at http://www.wheels.org/monkeywrench/?p=817

[ Update March 7, 2016: New source code and executables are available on Github, at https://github.com/MichaelSternNYC The Win32 binaries and instructions for use can be found at https://github.com/MichaelSternNYC/bloomberg-to-mathematica

If you want to load Bloomberg data into a version of Mathematica older than 10.0, contact me and I can send you an older release. ]