+ Reply to Thread
Results 1 to 42 of 42

Import historical quotes with specific dates

  1. #1
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Import historical quotes with specific dates

    Hello,

    I first must say that i know nothing about programming and therefore i really need some help.

    I am trying to do a research about historical stock quotes, however, instead of importing complete tables that have date intervals, i wish to importa dpecif historical quotes on specificic dates (ex: 05/01/1981).

    The problem is that my spreadsheet will consist of more than 600 companies and 62 different historical quote dates for each. You can see the amount of work and time that this will consume if i do it all by hand.

    I will attach a file and i hope that someone can help me with this.

    Thank you so much in advance.

    Best regards,
    Paulo Ferreira

    Consumer Discretionary.xls

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paffius,

    Welcome to the Forum!

    To help you with this, I need you to provide a list of stock symbols for the companies you want the historical quotes for. Is there a particular site you wanted to query for these quotes? If yes then please provide the site's web address.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Discretionary.xls

    Hi Leith,

    I posted a new file, with the symbols. Some stocks dont have symbols, so, forget those.
    Usually i use the Yahoo Finance website.
    For the FORD company, for example, the historical quotes link is: http://finance.yahoo.com/q/hp?s=F+Historical+Prices

    One more time, thanks so much for helping. Besides filling the data, i am also very interested in learning how to do it, for the others spreadsheets i will have to make in the near future.

    Best regards,
    Paulo Ferreira

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paffius,

    I downloaded the workbook again but I did not see the ticker symbols, only the company names. I can not use the names for the ticker symbol. For example Ford Motor Company's symbol is "F". Using "Ford" for the ticker symbol will return results for Forward Industries.

    Which values do you want for the dates: Open, High, Low, Close, Volume, or Adj Close? Or will high and low be copied to different sheets?

  5. #5
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hello Leith,

    The symbols are in column B in the last file i sent you.
    All i want is the CLOSE quotes, nothing else.

    Regards,
    Paulo

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paffius,

    I finished the testing the code and it appears to returning the correct data for the historical dates. The attached workbook currently fills in only the first worksheet. I can change this to handle whichever sheets you want. Have a look and let know what you think. There is a new worksheet "Sheet1". I added this to check that the proper URLs were being accessed. I can remove this for the final version.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    HI Leith,

    I have no words, its exactly what i wanted.

    I was just looking at the macro and i even feel bad because it looks so complicated and you must have had lots of work and time spent.

    Just 2 questions:

    - To the spreadsheet you already done, if i add a new row with a new company, must the macro be changed?

    - How can i do to make the second spreadsheet do the same? Just copy the macro or...?

    Apologise these questions, but the programming part for me is like Greek. I am an economist just.

    Once more, really thank you
    Paulo

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    You can add new companies to the worksheets. As long as it has a symbol in column "B" the macro will retrieve the historical prices. The down side is you would have to run the macro on the whole sheet again. That takes a little bit of time. Perhaps I can make some adjustment for that.

    I can modify the "ScrapeData" macro to get prices for whichever sheets you like. Let me know which sheets you want to include and I'll make the change.

  9. #9
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    You say it takes a little of time, i guess thats why whe i pressed the Get Historical quotes button, my excel started thinking and thinking...

    About the companies, i will have to do some research still, because i thought more companies existed in the 80's, and obviously only 2 appeared.
    So i will need some days to research a little, probably next week, because of this short holidays.

    Thanks for the huge help.
    Paulo

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    You're welcome. I will change the macro to run on both sheets and add something to inform you of the progress.

  11. #11
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Thanks once more.

    By the way, is it normal for excel to be much slower or even unresponsive while it gets the data?

    Paulo

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    In this case, yes. The data is being retrieved synchronously. That is Excel requests the data and waits for the server to return the data before continuing on with the code.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    In this case, yes. The data is being retrieved synchronously. That is Excel requests the data and waits for the server to return the data before continuing on with the code.

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    The button will now run the macro on all worksheets except "Copy". The symbol and the current historical prices URL are displayed in Excel Status bar below the worksheet tabs. There is also a button to clear the prices on each sheet. Also, only rows that do not have closing prices in them will be updated. This will allow you to add new companies and not have to wait for the whole page to update.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hello Leith,

    I will have a look at it now.

    On first look i realized that for example, the first quotes of GM and Ford are exactly the same and some specific dates are not returning any quote at all.
    You think it's something not working properly?

    This one was a mistake of mine, but i forgot to switch the date 01-31-1980 to 1-30-1980. I tried to change it and then pressed the Historical Quote button, but it gave me a runtime error.

    Best regards,
    Paulo
    Last edited by Paffius; 12-31-2011 at 07:57 AM.

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    Ano novo feliz!

    This version has the problem you found corrected. Thank you for finding that. I searched the sheets for the date you changed but could not find it. However, simply changing a date before you run the historical prices won't cause a run-time error. Something else must have happened.

    I tested this version thoroughly yesterday. The returned prices are correct and I experienced no errors. If you do find something that is wrong, please let me know. If you experience any more errors, tell me the line that failed and the error code.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hello Leith,

    Happy New Year!

    I will test it and any doubt or error that happens, i will let you know.

    Once again, i have no words to express my gratitude.

    Just thinking of the next sheets i will have to do, with over 700 companies in total, this is a huge headache you take out of my life.

    My best regards,
    Paulo

  18. #18
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    I was checking today the file you sent me and i detected some problems.

    I noticed that some dates are not returning any quotes. I am not talking about dates where a determined company didn't existed (something frequent in the 80's), but some blank spaces in dates of companies that existed in that period. I havent checked all, but its easy to see in Ford, McDonalds for example, in periods like 1-4-1982, 4-16-1982, 9-1-1982 or 10-12-1982, or in other companies even in more recent periods.
    Every blank spot that you see without a quote, and that in the previous dates, for that company, there is a historical quote filled, there must be an error because for that blank spot there also should be a quote.

    Another problem i noticed is that, if i add a row, with a new company and then click on the Get Historical Quotes button, the following error appears:
    "RUN TIME ERROR 457 - This key is already associated with an element of the collection"
    Am i adding rows in a way i shouldn't? Which is the way i should add a new company(ies) to the existent ones that would allow the code to work well?

    One more, thank you in advance.
    Regards,
    Paulo

  19. #19
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I will need to investigate the first problem further. The second problem is telling me that you are using the same stock symbol more than once in column "B". My understanding was there would be no duplication of the stock symbols on the worksheet. If there will be duplicates then the macro will need to be adjusted to handle this situation.

  20. #20
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    No, i am not duplicating stocks and there will be no duplications in the same sheet.

    Try to add a row with IBM for example, or Microsoft (MSFT), just for the sake of an example. And tell me how you added, perhaps it can only be added in the end and not in between existing rows?

    Paulo

  21. #21
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I don't receive the error you do when adding IBM to the bottom of the list. However, I did not copy the formulas and the macro did not add any quotes. I set the macro to look for a count of 17, the number of formulas in the row, to determine if there were any quotes. The lines that need to changed are in the "ScrapeData" macro.
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    Thats a bit of a problem to me, as i told you i really don't understand programming and to be fair, i haven't understood what you meant in the last post.
    Forgive my ignorance in this matter.

    Paulo

  23. #23
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I have attached the updated workbook. IBM was added to the worksheet "Consumer Discretionary - SUB.". The formulas were not copied. Just the stock symbol IBM was added to column "B".
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    So you just written "IBM" on the B column and nothing else? Not even changed format in cells or so?

    Best regards,
    Paulo

  25. #25
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I only added the stock symbol to column "B". No formulas were copied to the new row. If you copy and paste a line as a new line, be sure that the copied formulas are correct and in the correct columns. The macro looks for the symbols added to column "B" that have no data in the row.

  26. #26
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    HI Leith,

    But for example, i just added two new companies, GE (General Electric) and JNJ (Johnson & Johnson), to the lines exactly beneath IBM and, in the case of GE it returned starnge values like 7625 (7-11-1986) or 11300 (6-30-1999), among others, and no values at all before 1985; while in the case of JNJ it didnt return any,

    I then clicked on the Button for a second time, and now, it returned more dates in either, but not all. However the quotes are all wrong, still with number like 5690 or 7050 or so, in the thousands, which is impossible.

    Does this happen with you aswell?

    Regards,
    Paulo

  27. #27
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I don't have any problems with adding new symbols and retrieving the quotes. You have not mentioned if your computer is part of a network or not. Perhaps you data is being corrupted by a firewall setting or an antivirus program. If you are on a company network, you should check with your IT department about what you can and can not do across your network.

  28. #28
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    No, i am using a home computer, with no firewalls. Just a simple PC.

    Regards,
    Paulo

  29. #29
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    In that case, which version of Windows and Internet Explorer are you using?

  30. #30
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    I am currently using IE9 and Windows 7 Ultimate.

    Regards,
    Paulo

  31. #31
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    Try this update. The macro changes the user agent string to be compatible with Internet Explorer 9. This should solve the problems you are having.
    Attached Files Attached Files

  32. #32
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    Now it doesnt even accept any symbol on column B.
    It gives an "Run time error 13 - Type mismatch".

    Regards,
    Paulo

  33. #33
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    Your new and old results seem to point to the user agent string not being correct. Since you Windows 7 Ultimate, do you ever run it in Windows 2003 compatibility mode? I would try running the previous workbook in this mode and see if it works.

  34. #34
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    How do i do that, "run in Windows 2003 compatibility mode"?

    Regards,
    Paulo

  35. #35
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    Sorry, I forgot compatibility mode is automatic. Does the workbook I posted run on your system and return the correct results?

  36. #36
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    This last one you posted "Discretionary IE9 ver 1.xls‎" returns that error i told you, and it doesnt accept any company name (ticker) on column B.

    About the blank dates, have you yet come up with a conclusion?

    Paulo

  37. #37
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    This is a mystery to me. We have tried everything and the results are the same. Something else is causing the problem, but I am out of suggestions for what to check next. Unless someone else has had this problem and knows what is wrong, we are dead in the water.

  38. #38
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    I understand.

    I will fill the blank spaces one to one.

    When i create the other worksheets for the rest of the companies, if i may, can i just send u so u attach the macro. Even if it returns blank spaces, i will fill them individually.

    I really thank you for all the help you gave, believe me, for someone with null programming skills like me, this was a huge help.

    Muito obrigado,
    Paulo

  39. #39
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    If you want to send the workbook to me, I will be happy to run the macro on my machine and send the results back to you. Could you do that?

  40. #40
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Thanks Leith,

    This workbook u sent me is one of nine (well, 18, if you count the SUB and DESC sheets)

    When i get the others ready i will send you. Won't be for now, coz im still doing research for this specific sector (Consumer Discretionary), but when its done, i will, if i may.

    Thank you once more,
    Paulo

  41. #41
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import historical quotes with specific dates

    Hello Paulo,

    I would be happy to help out. If you want you email the workbooks to me. My email is my user name without the space at gmail.

  42. #42
    Registered User
    Join Date
    12-28-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Import historical quotes with specific dates

    Hi Leith,

    I wonder if i could ask you that, instead of using the "closing price" in the last workbook version 1c, you could use the "adjusted price"?

    I have just realized that it must be using adjusted prices.

    Thanks once more.

    Have a great weekend,
    Paulo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1