Hi,
from quantrautil import get_data
is not working
The error is - Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
from quantrautil import get_data
ModuleNotFoundError: No module named 'quantrautil'
How do I install the 'quantrautil'?
P.S. I am using Python IDLE
You can refer to the below community post to resolve the issue you are facing.
https://quantra.quantinsti.com/questionDetails/67/quantrautil-library
Thanks!
I tried the entire code mentioned in that post. However, after that when I tried to fetch data for ‘AAPL’ or ‘SBIN’, the output was ‘Please try again’. Can it be due to the fact that I am trying to use it in IDLE, not ANACONDA?
I have added the code to print the exception or cause for failure. Replace the below code in quantrautil.py file. There can be multiple reasons for that
- fix_yahoo_finance is not installed
- The Quandl API key at line no 12 is missing.
# if fix_yahoo_finance or quandl is not installed
then run the below two lines of code
!pip install fix_yahoo_finance
!pip install quandl
import fix_yahoo_finance as yf
import quandl
import traceback
API key to access quandl data
def get_quantinsti_api_key():
#To get your API key, sign up for a free Quandl account
#Then, you can find your API key on Quandl account settings page
return '<<YOUR_API_KEY>>'
def get_data(ticker, start_date='2016-01-01', end_date='2017-01-01', progress=False):
try:
data = yf.download(ticker, start_date, end_date)
return data
except:
try:
d = quandl.get('WIKI/'+ticker, start_date=start_date, end_date=end_date, api_key=get_quantinsti_api_key())
return d
except:
try:
d = quandl.get('NSE/'+ticker, start_date=start_date, end_date=end_date, api_key=get_quantinsti_api_key())
return d
except Exception as e:
print("Please try again", traceback.print_exc())
print(get_data('AAPL'))
I got the data after using the code that you sent. However, even before fix_yahoo_finance and quandl both are installed and i also mentioned the quandl api key. I didn’t receive any error while importing fix_yahoo_finance or quandl in the file. Can you pls explain the changes you made in this code like what exactly was not working in the earlier code?
I had added quandl NSE dataset as a backup since you were fetching data for SBIN. But fetching the data for AAPL should have worked fine as the main logic is the same. To understand the reason for error in the previous version of the code, you can import traceback and replace the print statement with print(“Please try again”, traceback.print_exc()) .
Thanks a lot… it was sincerely great help. One last thing: In the new code you shared, there is ‘WIKI’ instead of ‘EOD’ in this line - d = quandl.get(‘WIKI/’+ticker, start_date=start_date, end_date=end_date, api_key=get_quantinsti_api_key()). Can you please tell the difference?
EOD is the professional-grade end of the day stock prices premium data and wiki is also end of the day stock prices data but it is a free data. More about this can be found at Financial, Economic and Alternative Data | Nasdaq Data Link
Hi team, i have saved the code you have given in the sitepackages and saved it as quantrautil.py…however i still face an issue while running this command “from quantrautil import get_data” and the error is as follows:ModuleNotFoundError Traceback (most recent call last) in () ----> 1 from quantrautil import get_data ModuleNotFoundError: No module named ‘quantrautil’ please help
I have installed yahoo finance and quandl packages
It seems like the default path for site-packages might be different. You can place the quantrautil.py in your current working folder from where you are trying to access or can check the default location from import sys print(sys.path). From the multiple paths you get you can select the path of the site-package. Thanks
Thanks for your help. I have saved the quantrautil.py file in correct site package folder only. I’m trying to import it from jupyter notebook. I checked using sys.path and the path where i saved the quantrautil file is correct. Still i’m facing the same issue
Doubt 2 :- I have copied the code and pasted in the jupyter cell dirtectly instead of importing from quantrautil.py. I am able to get the data for ‘AAPL’ but not for ‘SBIN’. Is this because of the free API that i have got? The following error is occuring: Traceback (most recent call last): File “”, line 16, in get_data d = quandl.get(‘WIKI/’+ticker, start_date=start_date, end_date=end_date, api_key=get_quantinsti_api_key()) File "<ipython-input-8-d7942c46ace
It’s strange. We will connect with you to help resolve the issue you are facing. Thanks!
To get the data for SBIN you can replace Wiki with NSE in "quandl.get(‘NSE/’+ticker, start_date=start_date,…
Ok thanks a lot for your support. Appreciate it.