MrMarc

3163 Reputation

18 Badges

17 years, 133 days

MaplePrimes Activity


These are answers submitted by MrMarc

I would save the data as a csv file and then use the Maple command

 

 ImportMatrix("C:\\MetaStock\\! Access Database\\SP-500-Monthly (2003-2009).csv", source = csv)

 

 to import the data into Maple. You need of course change the link so it matches the location of your saved csv fil.

 

all right thanx for the pointer. I will try that :-)

 

Doug,  good news I managed to solved it   :-) 

The solution was so simple that I am a bit ashamed that I have waisted 2-3 days on this. ha ha

Instead of calling the us version of yahoo finance we call the uk version ha ha

 

str := "" :
sid := Sockets:-Open("uk.old.finance.yahoo.com", 80):
Sockets:-Write(sid, cat("GET /d/quotes.csv?s=@^GSPC&f=sn&e=.csv&h=", page, " HTTP/1.0 \n\n")):
b := Sockets:-Read(sid):
while b <> false do
str := cat(str, b):
b := Sockets:-Read(sid)
end do:
Sockets:-Close(sid);
str ;

 

The data can be extracted from the uk version with one call. Done and dusted.

 

I got another question though maybe I should start a new post for this one.

I can display real time data in maple from yahoo finance by using a procedure that calls yahoo finance

every 10 seconds plus a mathcontainer. The problem is that Maple is busy evaluating the procedure

when the real time data is displayed so you cant do anything ells. Is there anyway around this so I can

work in Maple and on the same time dispay real time data in a mathcontainer ?! 

 

all right thanx Doug. Dont worry about it !  I think I can manage to solve it on my own.

I just wanted to see if anyone ells had faced a similar problem :-)    

Hi again Doug,

ok, let me explain what my goal is. My goal is to extract the ticker symbols and names of all the stocks for any specified

index from yahoo finance. For example for ^gspc the link is:  http://finance.yahoo.com/q/cp?s=^GSPC

I have managed to do that with the below code (due to your previous help which was very nice)

for one specific index S&P-500 (^gspc)

 

restart:
with(StringTools):
with(Sockets):
with(ArrayTools):

for page from 0 by 50 to 450 do

str := "" :
sid := Sockets:-Open("download.finance.yahoo.com", 80) :
Sockets:-Write(sid, cat("GET /d/quotes.csv?s=@%5EGSPC&f=sn&e=.csv&h=", page, " HTTP/1.0 \n\n")) :
b := Sockets:-Read(sid) :

while b <> false do
str := cat(str, b) :
b := Sockets:-Read(sid) end do:

Sockets:-Close(sid);
str;
we1 := [SearchAll("\n", str)];
we2 := convert(SubString(convert(str, name), we1[7] .. -1), name);
we3 := map(Split, we2, "\n");
if page = 0 then
Ap[page] := Matrix([seq([parse(we3[i])], i = 2 .. 51)]) else
Ap[page] := Matrix([seq([parse(we3[i])], i = 3 .. 52)]) end if

end do :

App := <seq(Ap[i], i = 0 .. 450, 50)> ;

 

The code works very well for ^gspc but not for any other index because the number of pages is not constant.

The GSPC symbol has 10 pages but the for example ^FTSE has is only 3 pages which means that the procedure

code is not genericIt only works for ^gspc which makes it quite usless. The number of pages is located outside

the imported table (raw html) which makes is difficult to process. Another difficulti is that the number of stocks per page

is 50 unless it is the last page then the number can vary. This has forced me to look at an alternative solution.

This is where the MATLAB code comes in. The MATLAB code solves this problem very elegantly with a smal

amount of code and the code works very well in MATLAB. My problem is that the "Maple Toolbox for MATLAB" 

does not do a very good job in translating the code and my understanding of the original MATLAB code is limited...


 

I got the original MATLAB function from:   http://www.trade-strategy.com/code.php?project=Yahoo&file=yahooTickers

Maple spit out the rest which is not working so I think it is easier to look at the original MATLAB function

and try to figure out how the code is working and try to reproduce it in Maple. My problem is that I dont understand

the MATLAB code at all and how it works ....

Yes, I have already got Mathematica and I was aware of their indeed very nice economic / finance data integration :-)

I have also got MLDownloader so I can download all the data I want from yahoo finance in bulk which I am not

sure mathematica can do.  There is however an big advantage with being able to interact with data directly in

Maple (not simply importing pivot tabled organized csv data stored on your c-drive ) for example putting data calls in loops

(getting a huge amount of data) , real time backtesting etc etc . The opportunities are endless :-)  

 

Yeahaaaaaaa  power to the people ha ha   :-)    :-)   nice  !  sweet  !    perfect !

This adds a completely new dimension to Maple....

Again thanx for sharing that with us  ( I think I speak for quite a lot of people )

 

nice :-)  many thanx Samir....  I dont mean to be ungrateful but is it possible to inlude the name as well ?

now it is only ticker symbol plus close etc

 

 

All right thanx for your help Doug !  I will try to figure it out :-)  

I sincerely wish that I would have had you as my supervisor then I would have

been Albert Einstein in time for my PhD viva, ha ha :-)  

 

thanx Doug very nice :-)  As always I appreciate your effort, input and expertise  :-)

Now I got loads of information and good code (with different approaches) to look at and learn from. 

Doug, how would you go about extracting the names and ticker symbols for all stocks the S&P-500

which can be found here :   http://finance.yahoo.com/q/cp?s=^GSPC

I think the procedure should be very similar to the one above, or ?!

 

ohhh that is beautiful man :-)   ha ha.  thanx :-)

I removed my procedure and it worked like a charm. I am going to rewrite the procedure so it works with your data saving code :-)

 

Hey Samir what do you think about my second question ?

Wouldnt it be nice to be able to extract all the ticker symbols and names of all stocks on for example the S&P-500

or what ever exchange etc that you specify in Maple?  I think this link will do that :  http://finance.yahoo.com/q/cp?s=^GSPC

Now I only have to figure out how to extract that information and save it in a matrix ?!

 

Some very powerful Maple applications can be developed around this yahoo finance website.

For example real time quotes (20 min delay) that can be updated in a MathContainer in Maple.

http://streamerapi.finance.yahoo.com  .    The opportunities are endless .....:-)

 

 

thanx Doug :-)

all right the finished "time series plot Maplet from csv file" code is presented below. I am quite pleased with it :-)

 

restart:
with(Statistics):
with(plots):
with(LinearAlgebra):
with(Maplets):
with(Maplets[Elements]):
with(Maplets[Tools]):
with(ArrayTools):

X1 := proc () global pap, mam, L, Nr, Nc, LL, xaxis ;

pap := Maplet(FileDialog['FD1']('filefilter' = "csv", 'filterdescription' = "csv", 'onapprove' = Shutdown(['FD1']), 'oncancel' = Shutdown(['FD1'])));

mam := Display(pap)[1];

L := ImportMatrix(mam, source = csv);

Nr, Nc := Size(L);

LL := table(Equate([seq(L[1, i], i = 2 .. Nc)], [seq(Column(L, i)[2 .. Nr], i = 2 .. Nc)]));

xaxis := [seq(i-1 = Column(L, 1)[i], i = 2 .. Nr, 18)]

end proc :


X2 := proc ()

if assigned(L) then

Set(('DD')(itemlist) = sort([seq(Row(L, 1)[i], i = 2 .. Nc)], lexorder))

end if

end proc :


X3 := proc () local T;

T := convert(Get('DD'), string);

LineChart(LL[T], title = T, labels = ["Time", "Time Series Values"], labelfont = [times, roman, 16], labeldirections = [horizontal, vertical], titlefont = [times, bold, 18], color = red, thickness = 2, tickmarks = [xaxis, default], gridlines = true)

end proc :


tool := "Select a CSV file with time series data organized in columns where the first column contains the dates/years etc and \n and the first row contains the names. Such data most likely would have been organized with a pivot table in Excel " :

maplet2 := Maplet(Window(title = "Time Series Plot Maplet", width = 800, height = 600, [[], [Button['B1']("Select a csv file with data", tooltip = tool, onclick = Action(Evaluate('B1' = 'X1()'), Evaluate('DD' = 'X2()'))), DropDownBox[DD](["Time Series"], width = 200, onchange = Evaluate(P = 'X3()')), Button['PP']("Close Window", onclick = Shutdown())], [], [Plotter[P](width = 650)], []])) :

Display(maplet2) ;

 

 

nice!  :-)   I am going to include that one in my "how do I do with Maple" bank account

First 10 11 12 13 14 15 16 Last Page 12 of 24