API Docs

Manual, tutorials and complete function reference

Portfolio Metrics


These settings regulate how portfolio returns and return moments are computed:


Portfolio Metrics Mode

One of the two modes for collecting portfolio metrics that could be used:

  • "portfolio" - portfolio metrics are computed using previous history of position rebalancing. Portfolio risk and performance metrics account for the periods with no market exposure (i.e. when no positions are held) depending on the holding periods accounting settings (see holding periods mode below).

    This mode should be used to backtest and compare portfolios and trading strategies of different frequency and style.

  • "price" - at any given point of time, both position and portfolio metrics are computed for a buy-and-hold strategy.

    In this mode, even when position quantities are changing over time, only last quantities will be used and all history of position rebalancing is entirely ignored.

    This mode is a common for classic portfolio theory and is often used in academic literature for portfolio optimization or when computing price statistics.

By default, mode is set to "portfolio".

require(PortfolioEffectHFT)
portfolio<-portfolio_create(fromTime="2014-10-01 09:30:00", toTime="2014-10-02 16:00:00")
portfolio_addPosition(portfolio,c('C','SPY'),c(500,600))

# "price" mode
portfolio_settings(portfolio, portfolioMetricsMode="price")
print(portfolio)

# "portfolio" mode
portfolio_settings(portfolio, portfolioMetricsMode="portfolio")
print(portfolio)
portfolio=portfolio_create('index','SPY','fromTime','2014-10-01 09:30:00','toTime','2014-10-02 16:00:00')
portfolio_addPosition(portfolio,['C';'SPY'],[500;600])

% "price" mode
portfolio_settings(portfolio, 'portfolioMetricsMode', 'price')
portfolio_return(portfolio)

% "portfolio" mode
portfolio_settings(portfolio, 'portfolioMetricsMode', 'portfolio')
portfolio_return(portfolio)

Holding Periods Only

This setting should only be used when portfolio metrics mode is set to "portfolio".

When holdingPeriodsOnly is set to FALSE, trading strategy risk and performance metrics will be annualized to include time intervals when strategy had no market exposure at certain points (i.e. when position quantity were zero). When set to TRUE, trading strategy metrics are annualized only based on actual holding intervals.

require(PortfolioEffectHFT)
portfolio<-portfolio_create(fromTime="2014-10-01 09:30:00", toTime="2014-10-02 16:00:00")
portfolio_addPosition(portfolio,'AAPL',c(300,150,0),time=c("2014-10-01 09:30:00","2014-10-01 10:30:00", "2014-10-01 11:30:00"))

# enable holdingPeriodsOnly
portfolio_settings(portfolio, holdingPeriodsOnly=TRUE)
print(portfolio)

# disable holdingPeriodsOnly
portfolio_settings(portfolio, holdingPeriodsOnly=FALSE)
print(portfolio)
portfolio=portfolio_create('index','SPY','fromTime','2014-10-01 09:30:00','toTime','2014-10-02 16:00:00')
portfolio_addPosition(portfolio,'AAPL', [200;100], ["2014-10-01 09:30:00"; "2014-10-01 10:30:00"; "2014-10-01 11:30:00"])

% enable holdingPeriodsOnly 
portfolio_settings(portfolio, 'holdingPeriodsOnly', true)
portfolio_return(portfolio)

% disable holdingPeriodsOnly
portfolio_settings(portfolio, 'holdingPeriodsOnly', false)
portfolio_return(portfolio)

Short Sales Mode

This setting is used to specify how position weights are computed. Available modes are:

  • "lintner" - the sum of absolute weights is equal to 1 (Lintner assumption)
  • "markowitz" - the sum of weights must equal to 1 (Markowitz assumption)
Defaults to "lintner", which implies that the sum of absolute weights is used to normalize investment weights.

require(PortfolioEffectHFT)
portfolio<-portfolio_create(fromTime="2014-10-01 09:30:00", toTime="2014-10-02 16:00:00")
portfolio_addPosition(portfolio,c('C','SPY'),c(500,600))

# weights are normalized based on a simple sum (Markowitz)
portfolio_settings(portfolio, shortSalesMode="markowitz")
print(portfolio)

# weights are normalized based on a sum of absolute values (Lintner)
portfolio_settings(portfolio, shortSalesMode="lintner")
print(portfolio)
portfolio=portfolio_create('index','SPY','fromTime','2014-10-01 09:30:00','toTime','2014-10-02 16:00:00')
portfolio_addPosition(portfolio,['C';'SPY'],[500;600])

% weights are normalized based on a simple sum (Markowitz)
portfolio_settings(portfolio, 'shortSalesMode', 'markowitz')
portfolio_return(portfolio)

% weights are normalized based on a sum of absolute values (Lintner)
portfolio_settings(portfolio, 'shortSalesMode', 'lintner')
portfolio_return(portfolio)