*! version 1.0.0 23jun2016

Title

backtest -- performs a backtest of a financial portfolio.

Syntax

backtest varlist [if] [in]
, weights(matrix_name)

weights(matrix_name) matrix_name is the name of a Stata matrix (Nx1) where the weights of the portfolio are stored.
This must be a vertical matrix with dimensions (N x 1), where N is the number of price variables.

Description

backtest calculates the holding period return of a financial portfolio composed of the price variables specified in varlist. The portfolio weights must be
located in a (Nx1) Stata matrix, which must be specified in the weights option.

Remarks

Check the "Also See" Menu for related commands.

Examples

Collects online daily stock data from Yahoo Finance for 2014 and 2015.

. returnsyh AAPL MSFT GE, fm(1) fd(1) fy(2014) lm(12) ld(31) ly(2015) frequency(d) price(adjclose)

Defines a portfolio weight matrix indicating 30% for Apple, Inc, 20% for Microsoft Corp, and 50% for General Electric Co.:

. matrix WPORT1=(0.3\0.2\0.5)

Labels the row names for the matrix with the company/ticker names:

. matrix rownames WPORT1=APPLE MICROSOFT GENERAL_ELECTRIC

Performs the backtest for the whole period. The holding period return of the portfolio for the whole period is calculated:

. backtest p_adjclose_AAPL p_adjclose_MSFT p_adjclose_GE, weights(WPORT1)

Performs the backtest for a specified period. The holding period return of the portfolio for 2015 is calculated:

. backtest p_adjclose_AAPL p_adjclose_MSFT p_adjclose_GE if period>=td(01jan2015) & period<=td(31dec2015), weights(WPORT1)

Stored results

backtest stores results in r() in the following scalars:

Scalars

r(N): Number of observations used for the calculations

r(retport): Holding period return of the portfolio

Author

Carlos Alberto Dorantes, Tecnológico de Monterrey, Querétaro Campus, Querétaro, México.
Email: cdorante@itesm.mx