Search code examples
yahooyqlyahoo-finance

How to get historical data from yahoo finance with base currency


I am trying to get historical data from yahoo finance but it gives me only for current date how can i get data with base currency on a specific date.

http://query.yahooapis.com/v1/public/yql?q=select+*+from+yahoo.finance.xchange+where+pair+in%28%22PKRUSD%22%2C%22PKRGBP%22%2C%22PKRKWD%22%2C%22PKRSAR%22%29&format=json&env=store://datatables.org/alltableswithkeys

Solution

  • There seems to be no way to get historical exchange rates of two currencies of your choice, however, you can get historical exchange rates from USD to any currency in the world. Here is how you get that:

    SELECT * FROM yahoo.finance.historicaldata WHERE symbol = "CCC=X" AND startDate = "YYYY-MM-DD" AND endDate = "YYY-MM-DD"
    

    There you choose your currency(CCC) and dates in YYYY-MM-DD format. Example, this will give you the exchange rates from USD to SEK for 2014-10-01 until 2014-10-03:

    SELECT * FROM yahoo.finance.historicaldata WHERE symbol = "SEK=X" AND startDate = "2014-10-02" AND endDate = "2014-10-03"
    

    This query will produce the following response:

    {
     query: {
     count: 3,
     created: "2016-09-10T12:53:42Z",
     lang: "sv-SE",
      results: {
       quote: [
        {
         Symbol: "SEK%3dX",
         Date: "2014-10-03",
         Open: "7.182",
         High: "7.29607",
         Low: "7.182",
         Close: "7.1817",
         Volume: "000",
         Adj_Close: "7.1817"
        },
        {
         Symbol: "SEK%3dX",
         Date: "2014-10-02",
         Open: "7.2151",
         High: "7.2174",
         Low: "7.1723",
         Close: "7.217",
         Volume: "000",
         Adj_Close: "7.217"
        }
       ]
      }
     }
    }
    

    You can always make this twice for two currencies and divide them to get the exhange rates between the two. Example:

    USD/SEK: 8.5
    USD/EUR: 0.85
    SEK/EUR = 8.5/0.85 = 10.
    

    Hope this answer will be to help.