jamlamberti / Py4FinOpt

Python for Financial Optimization
GNU General Public License v3.0
1 stars 3 forks source link

Encoding issue when interfacing with Yahoo Finance #5

Open jamlamberti opened 8 years ago

jamlamberti commented 8 years ago

Need to do some type of decoding in the cache wrapper or some strange things might start happing.

If I want to look up the historical data for S&P 500, I search for ^GSPC. This returns

[{
    "Volume": "3934010000",
    "Symbol": "%5eGSPC",
    "Adj_Close": "2062.139893",
    "High": "2064.080078",
    "Low": "2030.609985",
    "Date": "2015-01-08",
    "Close": "2062.139893",
    "Open": "2030.609985"
}, {
    "Volume": "3805480000",
    "Symbol": "%5eGSPC",
    "Adj_Close": "2025.900024",
    "High": "2029.609985",
    "Low": "2005.550049",
    "Date": "2015-01-07",
    "Close": "2025.900024",
    "Open": "2005.550049"
}]

The Symbol entry does not match the original query if we do not decode. This seems to fix it:

import urllib
print urllib.unquote('%5eGSPC')
jamlamberti commented 8 years ago

Another weird YF issue:

import yahoo_finance as yf
share = yf.Share('asdf') # some symbol
print len(share.get_historical('2015-01-01', '2016-01-01'))

If the symbol isn't valid, the expected result is []. However it rarely returns the contents of Yahoo's 404 page as a string.