The Quantopian research platform is a hosted research environment. Our aim is to make it simple to get started on your research without a lot of setup. Libraries are pre-installed and data is made readily accessible.
The Quantopian research platform is build using IPython, an open source project that provides an interactive notebook with executable cells. Each cell can be executed individually, but they all share the same variables (more technically the same namespace).
shift + enter
.¶We've added the following functions to optimize the platform for researching and developing investment algorithms.
The get_pricing
function provides access to 12 years of US Equity pricing data: the same data used by the Quantopian backtester.
get_pricing
returns a pandas object. This could be a panel, dataframe or series depending on the input values.
get_pricing('AAPL') #returns a pandas dataframe when run for 1 security
By default, get_pricing
returns OHLCV data at daily frequency for all of 2013. You can change the default behavior by passing the following parameters:
start_date
and end_date
. Dates can be passed as python datetime
objects, pandas Timestamp
s, or strings that can be parsed by pandas.fields
. Valid fields are:price
close_price
(an alias of price)open_price
high
low
volume
frequency = daily
or frequency='minute'
.aapl_minute_closes = get_pricing(
'AAPL',
fields='close_price', #modify to price, open_price, high, low or volume to change the field
start_date='2014-01-01', #customize your pricing date range
end_date = '2014-07-01',
frequency='minute', #change to daily for daily pricing
)
# matplotlib is installed for easy plotting
aapl_minute_closes.plot()
By default symbols
returns the security object for a ticker symbol. Specify a ticker symbol, or list of symbols, as a string and get a list of security objects back.
symbol_reference_date
to identify which date you want the symbol back for a particular ticker symbol. handle_missing
symbols('AAPL')
If you want to work with your own data in our environment, you can upload a csv to your data
directory and load the file with local_csv
. By default, local_csv
returns a DataFrame with the data from the loaded file.
You can customize the resulting DataFrame by passing the following parameters:
symbol_column
date_column
timezone
use_date_column_as_index
# Apple_Rev is a CSV from Quandl showing the quarterly revenue for Apple.
# It is pre-loaded in your data folder.
AAPLRev = local_csv('AAPL_Rev.csv', date_column = 'Date', use_date_column_as_index = True)
AAPLRev
# Plot with matplotlib
AAPLRev.plot()
The get_backtest
function provides programmatic access to the results of backtests run on the Quantopian platform. It takes a single parameter, the ID of a backtest for which results are desired.
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>
.
result = get_backtest('536a6d181a4f090716c383b7')
BacktestResult
Object¶The BacktestResult
object returned by get_backtest
contains all the information stored by Quantopian about the performance of a given backtest run, as well as some additional metadata about the backtest.
Get_backtest returns a backtest results object that includes 11 different data sets. If you type results.<tab>
you will see a list of all the things that are available.
result.
Because there are so many fields on BacktestResult
, the class provides helper attributes for easy reference.
scalars
contains a list of all the scalar attributes of BacktestResult
.frames
contains a list of all the DataFrame
attributes of BacktestResult
.attrs
contains a list off all the public attributes of BacktestResult
.print "Scalars:"
print result.scalars
print ""
print "Frames:"
print result.frames
print ""
print "All Attributes:"
print result.attrs
For easy inspection of the contents of frame contents, BacktestResult
provides a preview
method that returns a transposed version of the first few columns of a frame.
result.preview('risk')
View documentation for any callable
python object with the ?
operator.
get_pricing?
import pandas as pd
pd.DataFrame?