text: from .context import apiWrapper
  from apiWrapper.fmpApiClient import FmpApiClient
  
  class RuleOne(object):
  
      #TODO: remove ticker from class or from calculateROIC?
      def __init__(self, ticker, apiClient):
          self.ticker = ticker
          self.apiClient = apiClient
  
      #TODO write tests for wrong ticker, existing ticker and wrong formated financial data
      def calculateROIC(self, ticker):
          """Calculate ROIC of a specific ticker.
  
              Return on Investment Capital
              ROIC = NOPAT / (debt + equity) = (EBIT - "Income Tax Expense") / (debt + equity)
          Returns:
              list: List of (ROIC, date) for all the years that data are available.
          """
  
          yearsOfAvailableData = self.apiClient.getYearsOfAvailableData(ticker)
  
          if yearsOfAvailableData != 0:
              roicList =[]
              for year in range(0, yearsOfAvailableData):
                  ebit = float(self.apiClient.get_incomeStatementData(ticker, year, "EBIT"))
                  incomeTaxExpense = float(self.apiClient.get_incomeStatementData(ticker, year, "Income Tax Expense"))
                  totalDebt = float(self.apiClient.get_balanceSheetData(ticker, year, "Total debt"))
                  totalEquity = float(self.apiClient.get_balanceSheetData(ticker, year, "Total shareholders equity"))
                  roic = (ebit - incomeTaxExpense) / (totalDebt + totalEquity)
                  date = self.apiClient.get_incomeStatementData(ticker, year, "date")
                  roicList.append([roic, date])
              return roicList
          else:
              raise NoDataAvailableException
              #TODO: add logging
              print("Financial data not in expected format for "+ticker)
  
          #first item of the list is the ROIC of the latest statement
          # roicListOfLastXyears = [] 
  
          # for year in range(0,(yearsOfAvailableData-1)):
          #     try:
          #         ebit = float(incomeStatement["financials"][year]["EBIT"])
          #         incomeTaxExpense = float(incomeStatement["financials"][year]["Income Tax Expense"])
          #         totalDebt = float(balanceSheet["financials"][year]["Total debt"])
          #         totalEquity = float(balanceSheet["financials"][year]["Total shareholders equity"])
          #         roic = (ebit - incomeTaxExpense) / (totalDebt + totalEquity)
          #         roicListOfLastXyears.append(roic)
          #         print(roic)
          #     except ZeroDivisionError:
          #         print("Data error. Skipping stock "+ticker)
          #     except ValueError:
          #         print("Data error. Skipping stock "+ticker)
  
      #def calculateROICmean(roicListOfLastXyears, period):
      # roicListOfLastXyears is a list of calculated ROIC values for the last X available years
      # period is the amount of years on which we want to calculate the mean ROIC for
  
  class NoDataAvailableException(Exception):
     pass