def balance_on(date, options = {})
      date = Date.parse(date) if date.is_a?(String)
      return_value = Value.new(0)

      if options[:recursive]
        # Get all child accounts from this account and accumulate the balances of them.
        @book.accounts.reject { |account| account.parent != self }.each do |child_account|
          return_value += child_account.balance_on(date, recursive: true)
        end
      end

      return return_value unless @balances.size > 0
      return return_value if @balances.first[:date] > date
      return @balances.last[:value] if date >= @balances.last[:date]
      imin = 0
      imax = @balances.size - 2
      idx = imax / 2
      until @balances[idx][:date] <= date and @balances[idx + 1][:date] > date
        if @balances[idx][:date] <= date
          imin = idx + 1
        else
          imax = idx
        end
        idx = (imin + imax) / 2
      end
      @balances[idx][:value]
    end
def balance_on(date, options = {})
      date = Date.parse(date) if date.is_a?(String)
      return_value = Value.new(0)

      if options[:recursive]
        # Get all child accounts from this account and accumulate the balances of them.
        @book.accounts.reject { |account| account.parent != self }.each do |child_account|
          return_value += child_account.balance_on(date, recursive: true)
        end
      end

      return return_value unless @balances.size > 0
      return return_value if @balances.first[:date] > date
      return @balances.last[:value] if date >= @balances.last[:date]
      imin = 0
      imax = @balances.size - 2
      idx = imax / 2
      until @balances[idx][:date] <= date and @balances[idx + 1][:date] > date
        if @balances[idx][:date] <= date
          imin = idx + 1
        else
          imax = idx
        end
        idx = (imin + imax) / 2
      end
      @balances[idx][:value]
    end
Return the balance of the account as of the date given as a {Value}.
 Transactions that occur on the given date are included in the returned
 balance.

 @param date [String, Date]
   Date on which to query the balance.
 @param options [Hash]
   Optional parameters.
 @option options [Boolean] :recursive
   Whether to include children account balances.

 @return [Value]
   Balance of the account as of the date given.