## Mar 22, 2008

### Learning regular expression

I am learning Regular Expression right now. Here is the example to pull the information on monthly posting activities of Mathematica Discussion Group.

reg = "(?<=month/)\\d+-\\d+\">\\d+";
data = Import[url, "Source"];
ex = StringCases[data, RegularExpression[reg]];
ds = ToExpression[StringSplit[ex, {";", "-", "\">"}]];

Then we can use DataListPlot to produce a nice graph.

## Mar 12, 2008

### Understanding Finanical Market: Arbitrage

From Wikipedia, Arbitrage is the practice of taking advantage of a price differential between two or more markets, the profit being the difference between the markets prices.

Fro example, China Petro & Chem is traded in both US and HK stock markets. The price between these two markets are different, it seems US price follows the movements of HK's in recent several months.

After converting HK share price to US dollars, the price differences can be shown:
DateListPlot[{ussnp, hksnp}, Joined -> True, Filling -> {1 -> {2}}, FillingStyle -> {Green, Red}, DateTicksFormat -> {"Month", "/", "YearShort"}]
The trick is to use Filling -> {1 -> {2}}, FillingStyle -> {Green, Red}, Green indicates HK price is higher than US price, the red means the opposite.

## Mar 3, 2008

### Tip: Orthographic view of 3D graphics

The orthographic view of the 3D plot can be generated by using ViewPoint option. It comes very handy in some situations.

data = RandomReal[1, {20, 3}];
ListPlot3D[data, InterpolationOrder -> 0, ColorFunction -> "Rainbow", Mesh -> None, Boxed -> True, Axes -> None]
Add option ViewPoint->{0,0,Infinity} and draw it again.

Then we can put together a nice bounded Voronoi diagram. It saves the trouble to use BoundedDiagram from Computational Geometry Package.

## Mar 2, 2008

### Min Max problem

There is a discussion in Matlab blog: Should min and max marry?
The question is what the overhead is in calling min and max separately, instead of scanning through the data once, looking for both the lowest and highest values, and is it worth having a combined function for min and max from a speed point of view? It seems worthy it, if you work with large data frequently.

I am not sure about how Mathematica handle Min/Max internally. The one thing I can confirm is that Min/Max operations on large random 1 dimensional array are several times faster than the ones in Matlab in my computer.