API Docs

Manual, tutorials and complete function reference

Model Pipeline


These settings control what components of the HF market model pipeline are enabled:


Window Length

Specifies rolling window length that should be used for computing portfolio and position metrics. When portfolio mode is set to "portfolio", it is also the length of rebalancing history window to be used. Available interval values are:

  • "Xs" - seconds
  • "Xm" - minutes
  • "Xh" - hours
  • "Xd" - trading days (6.5 hours in a trading day)
  • "Xw" - weeks (5 trading days in 1 week)
  • "Xmo" - month (21 trading day in 1 month)
  • "Xy" - years (256 trading days in 1 year)
  • "all" - all observations are used

Default value is "1d" - one trading day.

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))

# 1 hour rolling window
portfolio_settings(portfolio, windowLength="1h")
print(portfolio)

# 1 week rolling window
portfolio_settings(portfolio, windowLength="1w")
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])

% 1 hour rolling window
portfolio_settings(portfolio, 'windowLength', '1h')
portfolio_return(portfolio)

% 1 week rolling window
portfolio_settings(portfolio, 'windowLength', '1w')
portfolio_return(portfolio)

Time Scale

Interval to be used for scaling return distribution statistics and producing metrics forecasts at different horizons. Available interval values are:

  • "Xs" - seconds
  • "Xm" - minutes
  • "Xh" - hours
  • "Xd" - trading days (6.5 hours in a trading day)
  • "Xw" - weeks (5 trading days in 1 week)
  • "Xmo" - month (21 trading day in 1 month)
  • "Xy" - years (256 trading days in 1 year)
  • "all" - actual interval specified during portfolio creation.

Default value is "1d" - one trading day.

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))

# 1 hour time scale 
portfolio_settings(portfolio, timeScale="1h")
print(portfolio)

# 1 week time scale
portfolio_settings(portfolio, timeScale="1w")
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])

% 1 hour time scale 
portfolio_settings(portfolio, 'timeScale', '1h')
portfolio_return(portfolio)

% 1 week time scale
portfolio_settings(portfolio, 'timeScale', '1w')
portfolio_return(portfolio)

Microstructure Noise Model

Enables market mirostructure noise model of distribution returns.

Defaults to TRUE, which means that microstructure effects are modeled and resulting HF noise is removed from metric caluclations. When FALSE, HF microstructure noise is not separated from asset returns, which at high trading frequences could yield noise-contaminated results.

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))

# HF noise model is enabled
portfolio_settings(portfolio, noiseModel=TRUE)
print(portfolio)

# HF noise model is disabled
portfolio_settings(portfolio, noiseModel=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,['C';'SPY'],[500;600])

% HF noise model is enabled
portfolio_settings(portfolio, 'noiseModel', true)
portfolio_return(portfolio)

% HF noise model is disabled
portfolio_settings(portfolio, 'noiseModel', false)
portfolio_return(portfolio)

Jumps/Outliers Model

Used to select jump filtering mode when computing return statistics. Available modes are:

  • "none" - price jumps are not filtered anywhere
  • "moments" - price jumps are filtered only when computing return moments (i.e. for expected return, variance, skewness, kurtosis and derived metrics)
  • "all" - price jumps are filtered from computed returns, prices and all return metrics.

Defaults to "moments", which implies that only return moments and related metrics would be using jump-filtered returns in their calculations.

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 jumps detection is enabled for returns and moments
portfolio_settings(portfolio, jumpsModel="all")
print(portfolio)

# Price jumps detection is disabled
portfolio_settings(portfolio, jumpsModel="none")
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 jumps detection is enabled for returns and moments
portfolio_settings(portfolio, 'jumpsModel', 'all')
portfolio_return(portfolio)

% Price jumps detection is disabled
portfolio_settings(portfolio, 'jumpsModel', 'none')
portfolio_return(portfolio)

Density Model

Used to select density approximation model of return distribution. Available models are:

  • "GLD" - Generalized Lambda Distribution
  • "CORNER_FISHER" - Corner-Fisher approximation
  • "NORMAL" - Gaussian distribution

Defaults to "GLD", which would fit a very broad range of distribution shapes.

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))

# Using normal density
portfolio_settings(portfolio, denistyModel="NORMAL")
print(portfolio)

# Using Generalized Lambda density
portfolio_settings(portfolio, denistyModel="GLD")
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])

% Non-normal return density is disabled
portfolio_settings(portfolio, 'denistyModel', 'NORMAL')
portfolio_return(portfolio)

% Non-normal return density is enabled
portfolio_settings(portfolio, 'denistyModel', 'GLD')
portfolio_return(portfolio)

Factor Model

Factor model to be used when computing portfolio metrics. Available models are:

  • "sim" - portfolio metrics are computed using the Single Index Model
  • "direct" - portfolio metrics are computed using portfolio value itself (experimental)

Defaults to "sim", which implies that the Single Index Model is used to compute portfolio metrics.

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))

# Single Index Model is used
portfolio_settings(portfolio, factorModel="sim")
print(portfolio)

# Direct model is used
portfolio_settings(portfolio, factorModel="direct")
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])

% Single Index Model is used
portfolio_settings(portfolio, 'factorModel', 'sim')
portfolio_return(portfolio)

% Direct model is used
portfolio_settings(portfolio, 'factorModel', 'direct')
portfolio_return(portfolio)

Drift Term

Used to enable drift term (expected return) when computing probability density approximation and related metrics (e.g. CVaR, Omega Ratio, etc.).

Defaults to TRUE, which implies that distribution is centered around expected return.

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))

# Drift term is enabled
portfolio_settings(portfolio, driftTerm=TRUE)
print(portfolio)

# Drift term is disabled
portfolio_settings(portfolio, dirftTerm=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,['C';'SPY'],[500;600])

% Drift term is enabled
portfolio_settings(portfolio, 'driftTerm', true)
portfolio_return(portfolio)

% Drift term is disabled
portfolio_settings(portfolio, 'driftTerm', false)
portfolio_return(portfolio)