title: ValueError: timestamp out of range for platform localtime()/gmtime() function
body: <p>I have a class assignment to write a python program to download end-of-day data last 25 years the major global stock market indices from Yahoo Finance:</p>
  
  <ul>
  <li>Dow Jones Index (USA)</li>
  <li>S&amp;P 500 (USA)</li>
  <li>NASDAQ (USA)</li>
  <li>DAX (Germany)</li>
  <li>FTSE (UK)</li>
  <li>HANGSENG (Hong Kong)</li>
  <li>KOSPI (Korea)</li>
  <li>CNX NIFTY (India)</li>
  </ul>
  
  <p>Unfortunately, when I run the program an error occurs. </p>
  
  <blockquote>
    <p>File "C:\ProgramData\Anaconda2\lib\site-packages\yahoofinancials__init__.py", line 91, in format_date
        form_date = datetime.datetime.fromtimestamp(int(in_date)).strftime('%Y-%m-%d')</p>
    
    <p>ValueError: timestamp out of range for platform localtime()/gmtime() function</p>
  </blockquote>
  
  <p>If you see below, you can see the code that I have written. I'm trying to debug my mistakes. Can you help me out please? Thanks</p>
  
  <pre><code>from yahoofinancials import YahooFinancials
  import pandas as pd
  
  # Select Tickers and stock history dates
  index1 = '^DJI'
  index2 = '^GSPC'
  index3 = '^IXIC'
  index4 = '^GDAXI'
  index5 = '^FTSE'
  index6 = '^HSI'
  index7 = '^KS11'
  index8 = '^NSEI'
  freq = 'daily'
  start_date = '1993-06-30'
  end_date = '2018-06-30'
  
  
  # Function to clean data extracts
  def clean_stock_data(stock_data_list):
      new_list = []
      for rec in stock_data_list:
          if 'type' not in rec.keys():
              new_list.append(rec)
      return new_list
  
  # Construct yahoo financials objects for data extraction
  dji_financials = YahooFinancials(index1)
  gspc_financials = YahooFinancials(index2)
  ixic_financials = YahooFinancials(index3)
  gdaxi_financials = YahooFinancials(index4)
  ftse_financials = YahooFinancials(index5)
  hsi_financials = YahooFinancials(index6)
  ks11_financials = YahooFinancials(index7)
  nsei_financials = YahooFinancials(index8)
  
  
  # Clean returned stock history data and remove dividend events from price history
  daily_dji_data = clean_stock_data(dji_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index1]['prices'])
  daily_gspc_data = clean_stock_data(gspc_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index2]['prices'])
  daily_ixic_data = clean_stock_data(ixic_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index3]['prices'])
  daily_gdaxi_data = clean_stock_data(gdaxi_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index4]['prices'])                                   
  daily_ftse_data = clean_stock_data(ftse_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index5]['prices'])                         
  daily_hsi_data = clean_stock_data(hsi_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index6]['prices'])
  daily_ks11_data = clean_stock_data(ks11_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index7]['prices'])
  daily_nsei_data = clean_stock_data(nsei_financials
                                       .get_historical_stock_data(start_date, end_date, freq)[index8]['prices'])
  stock_hist_data_list = [{'^DJI': daily_dji_data}, {'^GSPC': daily_gspc_data}, {'^IXIC': daily_ixic_data},
                          {'^GDAXI': daily_gdaxi_data}, {'^FTSE': daily_ftse_data}, {'^HSI': daily_hsi_data},
                          {'^KS11': daily_ks11_data}, {'^NSEI': daily_nsei_data}]
  
  
  # Function to construct data frame based on a stock and it's market index
  def build_data_frame(data_list1, data_list2, data_list3, data_list4, data_list5, data_list6, data_list7, data_list8):
      data_dict = {}
      i = 0
      for list_item in data_list2:
          if 'type' not in list_item.keys():
              data_dict.update({list_item['formatted_date']: {'^DJI': data_list1[i]['close'], '^GSPC': list_item['close'],
                                                              '^IXIC': data_list3[i]['close'], '^GDAXI': data_list4[i]['close'],
                                                              '^FTSE': data_list5[i]['close'], '^HSI': data_list6[i]['close'],     
                                                              '^KS11': data_list7[i]['close'], '^NSEI': data_list8[i]['close']}})
              i += 1
      tseries = pd.to_datetime(list(data_dict.keys()))
      df = pd.DataFrame(data=list(data_dict.values()), index=tseries,
                        columns=['^DJI', '^GSPC', '^IXIC', '^GDAXI', '^FTSE', '^HSI', '^KS11', '^NSEI']).sort_index()
      return df
  </code></pre>