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:
- The program should ask the user which ticker, start date, end date.
- The program should check if this ticker (inserted by the user) is in a certain text file.
- If this ticker is in the text file, it should scrape the data from yahoo finance.
- 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
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.
add a comment |
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:
- The program should ask the user which ticker, start date, end date.
- The program should check if this ticker (inserted by the user) is in a certain text file.
- If this ticker is in the text file, it should scrape the data from yahoo finance.
- 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
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.
add a comment |
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:
- The program should ask the user which ticker, start date, end date.
- The program should check if this ticker (inserted by the user) is in a certain text file.
- If this ticker is in the text file, it should scrape the data from yahoo finance.
- 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
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:
- The program should ask the user which ticker, start date, end date.
- The program should check if this ticker (inserted by the user) is in a certain text file.
- If this ticker is in the text file, it should scrape the data from yahoo finance.
- 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
python datetime
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.
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.
add a comment |
add a comment |
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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