I am using Python 2.7 and trying to execute a fairly straight forward code. I'm not sure why I am getting an error. The code fails when downloading the date from yahoo.
from matplotlib.finance import quotes_historical_yahoo
from datetime import datetime
from dateutil.relativedelta import relativedelta
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import norm
if __name__ == '__main__':
n_shares=200
confidence_level=0.99
nunDays=15
z=norm.ppf(confidence_level)
ticker= 'IBM'
begdate = (2014, 11, 1)
enddate = (2014, 11, 30)
x =quotes_historical_yahoo(ticker,begdate,enddate,asobject=True,adjusted=True)
ret = (x.aclose[1:]-x.aclose[:-1])/x.aclose[:-1]
netPosition=n_shares*x.close[-1]
VaR=netPosition*z*np.std(ret)*np.sqrt(nunDays)
print "Net Value of Holding=",netPosition
print "Value at Risk (VaR)=", round(VaR,4), "over the next",nunDays, "Days"
I get the following error
Traceback (most recent call last):
line 17, in <module> x = quotes_historical_yahoo(ticker,begdate,enddate,asobject=True,adjusted=True)
line 236, in quotes_historical_yahoo fh = fetch_historical_yahoo(ticker, date1, date2, cachename)
line 197, in fetch_historical_yahoo
with contextlib.closing(urlopen(url)) as urlfh:
line 154, in urlopen
return opener.open(url, data, timeout)
line 437, in open
response = meth(req, response)
line 550, in http_response
'http', request, response, code, msg, hdrs)
line 469, in error
result = self._call_chain(*args)
line 409, in _call_chain
result = func(*args)
line 656, in http_error_302
return self.parent.open(new, timeout=req.timeout)
line 437, in open
response = meth(req, response)
line 550, in http_response
'http', request, response, code, msg, hdrs)
line 475, in error
return self._call_chain(*args)
line 409, in _call_chain
result = func(*args)
line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Process finished with exit code 1
Any help is most appreciated. Thanks