Python get stock prices from yahoo, ticker from user input











up vote
-1
down vote

favorite












I want to scrape data from yahoo finance with a python program and based on that scrape the data from yahoo finance.



More precisely:




  1. The program should ask the user which ticker, start date, end date.

  2. The program should check if this ticker (inserted by the user) is in a certain text file.

  3. If this ticker is in the text file, it should scrape the data from yahoo finance.

  4. If not, it should print some string


The relevant lines in my code are the following:
(I am quite new to python so my code might not be pretty)



Importing stuff (some of it will be necessary later)



import pandas as pd
import datetime as dt
import pandas_datareader.data as web
from datetime import datetime


In the companies.txt file is a list with all NASDAQ listed companies



companies = 'companies.txt'

with open(companies) as c_obj:
usernames = c_obj.read()

symbol = input("Stock symbol: ");

print("Please enter the Start date of your database")
start_date_str = input("Start date (mm/dd/yyyy): ");

print("Please enter the End date of your database")
end_date_str = input("End date (mm/dd/yyyy): ");

start_date = datetime.strptime(start_date_str,"%m/%d/%Y");
end_date = datetime.strptime(end_date_str,"%m/%d/%Y");


I want my program to look if the, from the user inserted ticker is in the file companies.txt. If yes, it should scrape the data of this company from yahoo finance, if not, it should print the line at the bottom.



if symbol in usernames:
df = web.DataReader(symbol, 'yahoo', start_date, end_date);
else:
print("Company name incorrect or company not listed on NASDAQ. To brows all NSADAQ listed companies please visit: https://www.nasdaq.com/screening/company-list.aspx")









share|improve this question









New contributor




MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    -1
    down vote

    favorite












    I want to scrape data from yahoo finance with a python program and based on that scrape the data from yahoo finance.



    More precisely:




    1. The program should ask the user which ticker, start date, end date.

    2. The program should check if this ticker (inserted by the user) is in a certain text file.

    3. If this ticker is in the text file, it should scrape the data from yahoo finance.

    4. If not, it should print some string


    The relevant lines in my code are the following:
    (I am quite new to python so my code might not be pretty)



    Importing stuff (some of it will be necessary later)



    import pandas as pd
    import datetime as dt
    import pandas_datareader.data as web
    from datetime import datetime


    In the companies.txt file is a list with all NASDAQ listed companies



    companies = 'companies.txt'

    with open(companies) as c_obj:
    usernames = c_obj.read()

    symbol = input("Stock symbol: ");

    print("Please enter the Start date of your database")
    start_date_str = input("Start date (mm/dd/yyyy): ");

    print("Please enter the End date of your database")
    end_date_str = input("End date (mm/dd/yyyy): ");

    start_date = datetime.strptime(start_date_str,"%m/%d/%Y");
    end_date = datetime.strptime(end_date_str,"%m/%d/%Y");


    I want my program to look if the, from the user inserted ticker is in the file companies.txt. If yes, it should scrape the data of this company from yahoo finance, if not, it should print the line at the bottom.



    if symbol in usernames:
    df = web.DataReader(symbol, 'yahoo', start_date, end_date);
    else:
    print("Company name incorrect or company not listed on NASDAQ. To brows all NSADAQ listed companies please visit: https://www.nasdaq.com/screening/company-list.aspx")









    share|improve this question









    New contributor




    MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I want to scrape data from yahoo finance with a python program and based on that scrape the data from yahoo finance.



      More precisely:




      1. The program should ask the user which ticker, start date, end date.

      2. The program should check if this ticker (inserted by the user) is in a certain text file.

      3. If this ticker is in the text file, it should scrape the data from yahoo finance.

      4. If not, it should print some string


      The relevant lines in my code are the following:
      (I am quite new to python so my code might not be pretty)



      Importing stuff (some of it will be necessary later)



      import pandas as pd
      import datetime as dt
      import pandas_datareader.data as web
      from datetime import datetime


      In the companies.txt file is a list with all NASDAQ listed companies



      companies = 'companies.txt'

      with open(companies) as c_obj:
      usernames = c_obj.read()

      symbol = input("Stock symbol: ");

      print("Please enter the Start date of your database")
      start_date_str = input("Start date (mm/dd/yyyy): ");

      print("Please enter the End date of your database")
      end_date_str = input("End date (mm/dd/yyyy): ");

      start_date = datetime.strptime(start_date_str,"%m/%d/%Y");
      end_date = datetime.strptime(end_date_str,"%m/%d/%Y");


      I want my program to look if the, from the user inserted ticker is in the file companies.txt. If yes, it should scrape the data of this company from yahoo finance, if not, it should print the line at the bottom.



      if symbol in usernames:
      df = web.DataReader(symbol, 'yahoo', start_date, end_date);
      else:
      print("Company name incorrect or company not listed on NASDAQ. To brows all NSADAQ listed companies please visit: https://www.nasdaq.com/screening/company-list.aspx")









      share|improve this question









      New contributor




      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I want to scrape data from yahoo finance with a python program and based on that scrape the data from yahoo finance.



      More precisely:




      1. The program should ask the user which ticker, start date, end date.

      2. The program should check if this ticker (inserted by the user) is in a certain text file.

      3. If this ticker is in the text file, it should scrape the data from yahoo finance.

      4. If not, it should print some string


      The relevant lines in my code are the following:
      (I am quite new to python so my code might not be pretty)



      Importing stuff (some of it will be necessary later)



      import pandas as pd
      import datetime as dt
      import pandas_datareader.data as web
      from datetime import datetime


      In the companies.txt file is a list with all NASDAQ listed companies



      companies = 'companies.txt'

      with open(companies) as c_obj:
      usernames = c_obj.read()

      symbol = input("Stock symbol: ");

      print("Please enter the Start date of your database")
      start_date_str = input("Start date (mm/dd/yyyy): ");

      print("Please enter the End date of your database")
      end_date_str = input("End date (mm/dd/yyyy): ");

      start_date = datetime.strptime(start_date_str,"%m/%d/%Y");
      end_date = datetime.strptime(end_date_str,"%m/%d/%Y");


      I want my program to look if the, from the user inserted ticker is in the file companies.txt. If yes, it should scrape the data of this company from yahoo finance, if not, it should print the line at the bottom.



      if symbol in usernames:
      df = web.DataReader(symbol, 'yahoo', start_date, end_date);
      else:
      print("Company name incorrect or company not listed on NASDAQ. To brows all NSADAQ listed companies please visit: https://www.nasdaq.com/screening/company-list.aspx")






      python datetime






      share|improve this question









      New contributor




      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 21 at 13:04









      Suraj Rao

      22.1k75468




      22.1k75468






      New contributor




      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 21 at 12:28









      MLU

      1




      1




      New contributor




      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      MLU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          MLU is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412048%2fpython-get-stock-prices-from-yahoo-ticker-from-user-input%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          MLU is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          MLU is a new contributor. Be nice, and check out our Code of Conduct.













          MLU is a new contributor. Be nice, and check out our Code of Conduct.












          MLU is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412048%2fpython-get-stock-prices-from-yahoo-ticker-from-user-input%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Futebolista

          Lallio

          Jornalista