Manual, tutorials and complete function reference
Quick Introduction to
Intraday Portfolio Metrics
In this tutorial we will construct a portfolio with a few positions and will compute some key risk and performance metrics for it.R Code Matlab Code
Here we are creating are simple portfolio with only two positions. By default SPY would be used for internal Single Index Model, unless other market index is selected. As it is a simple buy-and-hold strategy without rebalancing, we specify constant position quantity across all 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 positionAAPL=position_add(portfolio,"AAPL",100) positionGOOG=position_add(portfolio,"GOOG",200) # Display general information about the portfolio at the end of the period print(portfolio) plot(portfolio)
% Create empty portfolio dateStart = '2014-10-01 09:30:00'; dateEnd = '2014-10-02 16:00:00'; portfolio=portfolio_create('fromTime',dateStart,'toTime',dateEnd); % Add position AAPL and GOOG to portfolio portfolio_addPosition(portfolio,'AAPL',100); portfolio_addPosition(portfolio,'GOOG',200); % Display general information about the portfolio at the end of the period display(portfolio); plot(portfolio)
Let's first plot evolution of portfolio value over our data sample.
# Plot portfolio value changes over time print(plot(value(portfolio),title="Portfolio value, in USD"))
Portfolio Expected Return
Portfolio and position expected return is a statistical measure and estimates mean value of return distribution.
# Compute portfolio and position expected return (daily) print(plot(expected_return(positionAAPL),expected_return(positionGOOG),expected_return(portfolio), title="Expected Return, daily",legend=c("AAPL","GOOG","Portfolio")))
Below are the charts of portfolio and position daily variance of price returns. Return variance is higher at the beginning of a trading day.
# Compute portfolio and position variance (daily) print(plot(variance(positionAAPL),variance(positionGOOG),variance(portfolio), title="Variance, daily",legend=c("AAPL","GOOG","Portfolio")))
Portfolio and position Value-at-Risk expresses an average loss in the N% of worst cases. In this example, we use 95% confidence interval over a daily horizon. Note that in PortfolioEffect, both return variance and higher order moments (like skewness and kurtosis) are used to compute resulting VaR figure.
# Compute portfolio and position VaR (daily, 95% c.i.) print(plot(value_at_risk(positionAAPL,0.95),value_at_risk(positionGOOG,0.95),value_at_risk(portfolio,0.95), title="Value at Risk in %, daily (95% c.i.)",legend=c("AAPL","GOOG","Portfolio")))
Portfolio Sharpe Ratio
Now let's compute Sharpe Ratio (expressed in daily terms) for our positions and portfolio. Sharpe Ratio of our portfolio is somewhere in-between the Sharpe Ratios of individual positions.
# Compute portfolio and position Sharpe Ratio (daily) print(plot(sharpe_ratio(positionAAPL),sharpe_ratio(positionGOOG),sharpe_ratio(portfolio), title="Sharpe Ratio, daily",legend=c("AAPL","GOOG","Portfolio")))