I'm trying to build a portfolio management program, using ystockquote.
I can scrape prices using
ystockquote.get_historical_prices(y, '2013-11-01', '2013-11-11')
where y loops through a list of symbols ie. ('MSFT', 'F', 'MMM') I want the dates to be dynamic, but the following code
print sDate
print eDate
for y in depot_sym:
print ystockquote.get_historical_prices(y, sDate, eDate)
produces the following
2013-09-30
2013-11-19
Traceback (most recent call last):
File "C:\***\deriv4\test.py", line 26, in <module>
print ystockquote.get_historical_prices(y, sDate, eDate)
File "C:\Anaconda\lib\site-packages\ystockquote.py", line 156, in get_historical_prices
'a': int(start_date[5:7]) - 1,
TypeError: 'datetime.date' object has no attribute '__getitem__'
why is this?
ystockquote.get_historical_prices()
expects strings in the format "YYYY-MM-DD", rather than date
objects, as the second and third arguments. Try casting your dates using
sDate.strftime("%Y-%m-%d")