Question: yahoo finance: download data


I had a look at the Maple application "An Interactive Stock Quote Importer"

which is quite nice :-)  I did not really understand how the author (Samir Khan Maplesoft ) managed to download

yahoo finance data directly inside Maple so I sent him an email asking. He sent me some quite nice code (which I

simply put in a procedure ) that downloads data for any specified ticker symbol from yahoo finance:



StockImport := proc (ticker, Start, End, Step)

local startYear, startMonth, startDay, endYear, endMonth, endDay, timeStep, sid, str, b, Ap;  uses Sockets ;

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("", 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); str

end proc:


StockImport("^gspc", "20080101", "20090821", "m") ;



I basically have two questions :


1) How can I remove the first couple of lines in the output and save the Date,Open,High,Low,Close,Volume,Adj Close 

output in a Matrix in Maple  ?!


2) There exist another link on yahoo finance:^GSPC

where you can download all the ticker symbols and names for all the stocks currently included in the S&P-500 Index

How can I design a similar procedure as above which downloads and saves all the names and ticker symbols

for all stocks in the SP-500 Index in a Matrix in Maple ??


Please Wait...