New R/MATLAB Package Released: High Frequency Price Estimators & Models

We are happy to announce PortfolioEffectEstim toolbox availability for both R & MATLAB.
It is designed for high frequency market microstructure analysis and contains popular estimators for price variance, quarticity and noise.

For R

https://cran.r-project.org/web/packages/PortfolioEffectEstim/
Or via downloads section:
https://www.portfolioeffect.com/docs/platform/quant/tools/r

For MATLAB

http://www.mathworks.com/matlabcentral/fileexchange/55335-portfolioeffectestim-high-frequency-price-estimators—models-toolbox
Or via downloads section:
https://www.portfolioeffect.com/docs/platform/quant/tools/matlab

Features

Package features key estimators for working with high frequency market data.

Microstructure Noise:

  • Autocovariance Noise Variance
  • Realized Noise Variance
  • Unbiased Realized Noise Variance
  • Noise-to-Signal Ratio

Price Variance:

  • Two Series Realized Variance
  • Multiple Series Realized Variance
  • Modulated Realized Variance
  • Jump Robust Modulated Realized Variance
  • Uncertainty Zones Realized Variance
  • Kernel Realized Variance (Bartlett, Cubic, 5th/6th/7th/8th-order, Epanichnikov, Parzen, Tukey-Hanning kernels)

Price Quarticity:

  • Realized Quarticity
  • Realized Quad-power Quarticity
  • Realized Tri-power Quarticity
  • Modulated Realized Quarticity

Use could provide your own high frequency market data or use our server-side high frequency prices for all major US equities.

Client-side Market Data

To run an estimator using client-side data:

data(goog.data)
estimator<-estimator_create(priceData=goog.data)
rv.data = variance_tsrv(estimator)
util_plot2d(rv.data,title="Realized Variance of GOOG")

Server-side Market Data

To run an estimator using server-side data:

estimator<-estimator_create(asset='GOOG',fromTime="2014-09-01", toTime="2014-09-14")
tsrv.data = variance_tsrv(estimator,K=2)
util_plot2d(tsrv.data,title="Two Series Realized Variance of GOOG")

More details in the package manual:
https://cran.r-project.org/web/packages/PortfolioEffectEstim/vignettes/PortfolioEffectEstim.pdf

API Reference:
https://cran.r-project.org/web/packages/PortfolioEffectEstim/PortfolioEffectEstim.pdf

High Frequency Market Microstructure: Part 1 (Microstructure Noise)

Market Microstructure Noise

Microstructure noise describes price deviation from its fundamental value induced by certain features of the market under consideration. Common sources of microstructure noise are:

  • bid-ask bounce effect
  • order arrival latency
  • asymmetry of information
  • discreteness of price changes

Noise makes high frequency estimates of some parameters (e.g. realized volatility) very unstable. The situation gets even worse for high order moments like kurtosis, which makes tail risk estimation using HF data very problematic. We will investigate how severe could be noise contamination for different stocks as the we move towards transactional frequencies.

Example: Bid-Ask Bounce

Bid-ask bounce occurs when traders buy at ask prices and sell at bid prices. Their trades cause prices to bounce from bid to ask. These price changes reverse when traders arrive on the other side of the market.

Bid-ask Bounce

Read more…

Intraday Strategy Backtesting in R – Part 2 (Rule-based Strategies)

In this post we take intraday backtesting with PortfolioEffectHFT package one step further by adding a simple signal-based rebalancing rule. Using this rule we will create two trading portfolios – a high frequency strategy portfolio and a low frequency portfolio and compare them with each other in terms of their intraday risk and performance.

Both strategies would employ a price moving average signal with a window of different calendar length to simulate position entry and exit with different holding period durations. Our trading portfolio would consist of a single GOOG position to keep matters simple.

Rule-Based Trading Portfolios

First, we define a moving average method that receives a price vector and a window length for averaging.

# Create function of moving average
MA=function(x,order){
  result=x
  x1=c(0,x)
  result[(order):NROW(x)]=(cumsum(x1)[-(1:(order))]-cumsum(x1)[-((NROW(x1)-order+1):NROW(x1))])/order
  result[1:(order-1)]=cumsum(x[1:(order-1)])/(1:(order-1))
  return(result-0.0000000001)
}

The high frequency trading strategy has a window length of 150 seconds, while the low frequency strategy uses 800 second window. When the stock price exceeds the N-second moving average, each strategy would buy 100 shares of the stock. If moving average goes above the current price while we are still in position, the strategy would issue a sell signal. Now that we defined our position holding rules, we can construct our trading portfolio for further analysis.

Read more…

Intraday Strategy Backtesting in R – Part 1 (Buy-and-Hold Strategies)

Great news! PortfolioEffectHFT package was released on CRAN last week and allows all R users to backtest high frequency trading (HFT) strategies, perform intraday portfolio analysis and optimization on PortfolioEffect’s own compute cluster. The service is free to use within the free usage tier and has an optional access to price history for all US Equities – in case you need access to high quality intraday price data. You could even combine server-side and client-side data creating mixed data portfolios.

So, what is PortfolioEffect? It is a platform with an open API that was designed to provide portfolio & strategy metrics at intraday horizons and handle most market microstructure effects found in high frequency price returns in an automated fashion:

  • market microstructure noise
  • price jumps/outliers
  • extreme tail risk (high-order moments)
  • price fractality (long memory)

In other words, it makes working with high frequency data look similar to classic portfolio analysis on EOD prices, but results are available for every price tick (or time bar).

In this introductory post we will show how to construct a portfolio with a few positions and compute key metrics like return volatility and Sharpe Ratio.

Buy-and-hold Portfolio

Here we are creating are simple buy-and-hold strategy with only two positions. For that we will use 1-second price quote history of AAPL & GOOG available in all code examples for demonstrative purposes. By default SPY (S&P 500) would be used as a market index, unless other symbol is specified explicitly in portfolio_create.

Active trading strategy would normally require a vector of holding quantities at corresponding rebalancing times. But for a buy-and-hold strategy we just need to specify fixed position quantities across selected time span.

require(PortfolioEffectHFT)

# Create empty portfolio
portfolio=portfolio_create("2014-10-01 09:30:00","2014-10-02 16:00:00")

# Add position AAPL and GOOG to portfolio
portfolio_addPosition(portfolio,"AAPL",100)
portfolio_addPosition(portfolio,"GOOG",200)

To display major portfolio charts, call plot method on the constructed portfolio object.

plot(portfolio)

Read more…