api.get_pricing(symbols, start_date='2013-01-03', end_date='2014-01-03', symbol_reference_date=None, frequency='daily', fields=None, handle_missing='raise')

Load a table of historical trade data.

Parameters:
  • symbols (Object (or iterable of objects) convertible to Asset) – Valid input types are Asset, Integral, or basestring. In the case that the passed objects are strings, they are interpreted as ticker symbols and resolved relative to the date specified by symbol_reference_date.
  • start_date (str or pd.Timestamp, optional) – String or Timestamp representing a start date for the returned data. Defaults to ‘2013-01-03’.
  • end_date (str or pd.Timestamp, optional) – String or Timestamp representing an end date for the returned data. Defaults to ‘2014-01-03’.
  • symbol_reference_date (str or pd.Timestamp, optional) – String or Timestamp representing a date used to resolve symbols that have been held by multiple companies. Defaults to the current time.
  • frequency ({‘daily’, ‘minute’}, optional) – Resolution of the data to be returned.
  • fields (str or list drawn from {‘price’, ‘open_price’, ‘high’, ‘low’, ‘close_price’, ‘volume’}, optional) – Default behavior is to return all fields.
  • handle_missing ({‘raise’, ‘log’, ‘ignore’}, optional) – String specifying how to handle unmatched securities. Defaults to ‘raise’.
Returns:

pandas Panel/DataFrame/Series – The pricing data that was requested. See note below.

Notes

If a list of symbols is provided, data is returned in the form of a pandas Panel object with the following indices:

items = fields
major_axis = TimeSeries (start_date -> end_date)
minor_axis = symbols

If a string is passed for the value of symbols and fields is None or a list of strings, data is returned as a DataFrame with a DatetimeIndex and columns given by the passed fields.

If a list of symbols is provided, and fields is a string, data is returned as a DataFrame with a DatetimeIndex and a columns given by the passed symbols.

If both parameters are passed as strings, data is returned as a Series.

api.symbols(symbols, symbol_reference_date=None, handle_missing='log')

Convert a string or a list of strings into Asset objects.

Parameters:
  • symbols (String or iterable of strings.) – Passed strings are interpreted as ticker symbols and resolved relative to the date specified by symbol_reference_date.
  • symbol_reference_date (str or pd.Timestamp, optional) – String or Timestamp representing a date used to resolve symbols that have been held by multiple companies. Defaults to the current time.
  • handle_missing ({‘raise’, ‘log’, ‘ignore’}, optional) – String specifying how to handle unmatched securities. Defaults to ‘log’.
Returns:

list of Asset objects – The symbols that were requested.

api.local_csv(path, symbol_column=None, date_column=None, use_date_column_as_index=True, timezone='UTC', symbol_reference_date=None, **read_csv_kwargs)

Load a CSV from the /data directory.

Parameters:
  • path (str) – Path of file to load, relative to /data.
  • symbol_column (string, optional) – Column containing strings to convert to Asset objects.
  • date_column (str, optional) – Column to parse as Datetime. Ignored if parse_dates is passed as an additional keyword argument.
  • use_date_column_as_index (bool, optional) – If True and date_column is supplied, set it as the frame index.
  • timezone (str or pytz.timezone object, optional) – Interpret date_column as this timezone.
  • read_csv_kwargs (optional) – Extra parameters to forward to pandas.read_csv.
Returns:

pandas.DataFrame – DataFrame with data from the loaded file.

api.get_backtest(backtest_id)

Get the results of a backtest that was run on Quantopian.

Parameters:backtest_id (str) – The id of the backtest for which results should be returned.
Returns:BacktestResult – An object containing all the information stored by Quantopian about the performance of a given backtest run, as well as some additional metadata.

Notes

You can find the ID of a backtest in the URL of its full results page, which will be of the form:

https://www.quantopian.com/algorithms/<algorithm_id>/<backtest_id>
api.get_fundamentals(query, base_date, range_specifier=None, filter_ordered_nulls=None)

Load a table of historical fundamentals data.

Parameters:
  • query (SQLAlchemy Query object) – An SQLAlchemy Query representing the fundamentals data desired. Full documentation of the available fields for use in the query function can be found at http://quantopian.com/help/fundamentals
  • base_date (str in the format “YYYY-MM-DD”) – Represents the date on which data is to be queried.
  • range_specifier (str in the format {number}{One of ‘m’, ‘d’, ‘y’, ‘w’, ‘q’}, optional) – Represents the interval at which to query data. For example, a base_date of “2014-01-01” with a range_specifier of “4y” will return 4 data values at yearly intervals, from 2014-01-01 going backwards.
  • filter_ordered_nulls (bool, optional) – When True, if you are sorting the query results via an order_by method, any row with a NULL value in the sorted column will be filtered out. Setting to False overrides this behavior and provides you with rows with a NULL value for the sorted column.
Returns:

pandas.Panel – A Pandas panel containing the requested fundamentals data.

Notes

Before calling get_fundamentals, you first need to call the fundamentals initializer once with:

fundamentals = init_fundamentals()

This function needs to be called only once, following which get_fundamentals can be used as normal.

Querying of quarterly data is still under development and may sometimes return inaccurate values.