I have designed a cute little thing in Maple where you first click on the button to download all the stock names
( takes 5-8 second). Then you can select in the listbox the index name which will give you all the corresponding
stock in the ComboBox which is very fast since all downloads are done in the button.
View 8342_AAmmAA.mw on MapleNet or Download 8342_AAmmAA.mw
View file details
Now everything would be perfect if I could access the data as quickly as well which unfortunately is not the case.
I wrote this StockImport procedure
StockImport := proc (ticker, Start, End, Step) local Data, toMatrix;
Data := proc () local startYear, startMonth, startDay, endYear,
endMonth, endDay, timeStep, sid, str, b, Ap;
startYear := parse(Start[1 .. 4]); startMonth := parse(Start[5 .. 6]);
startDay := parse(Start[7 .. 8]); endYear := parse(End[1 .. 4]);
endMonth := parse(End[5 .. 6]); endDay := parse(End[7 .. 8]);
timeStep := Step; sid := Sockets:-Open("ichart.yahoo.com", 80);
Sockets:-Write(sid, cat("GET /table.csv?s=", ticker, "&a=", startMonth-1, "&b=",
startDay, "&c=", startYear, "&d=", endMonth-1, "&e=", endDay, "&f=",
endYear, "&g=", timeStep, "&ignore=.csv HTTP/1.0 \n\n"));
str := ""; b := Sockets:-Read(sid); while b <> false do str := cat(str, b);
b := Sockets:-Read(sid) end do;
Sockets:-Close(sid); return str end proc;
toMatrix := proc (S::string) local s, m, hdr, id, body;
s := StringTools:-SubString(S, StringTools:-SearchAll("Date", S) .. -2);
s := StringTools:-Split(s, "\n\f");
s := map(StringTools:-Split, s, ",");
m := Matrix(s); hdr := map(convert, m[1, () .. ()], name);
id := map(convert, m[2 .. (), 1], name);
body := map(parse, m[2 .. (), 2 .. ()]);
return `<,>`(hdr, `<|>`(id, body)) end proc;
toMatrix(Data(ticker, Start, End, Step))
StockImport("AA", "20050101", "20090825", "m");
Which works very well when we have a small number of stocks.
Now the thing is that some of these indexes have over 1000 stock in them. So I would like to find
a very efficient and fast way that I can download closing prices in one call for 1000 + stocks and
store such a data in Maple / MySQL database / or maybe in text file on the hard drive for quick access.
Then when you click on a button the data is updated only with the newest observations etc.
I could simply load the data in Maple as a csv file but it is boring. It would be much cooler if I could download and
access the data directly in Maple because it would open up many nice applications. I have tried creating many
separate threads as seen below but it is still extremly slow. Any suggestions ?
Create(StockImport("AA", "20050101", "20090825", "m"));
Create(StockImport("AAPL", "20050101", "20090825", "m"));