How it works...

In Steps 1 to 4, we followed the already established approach—imported the libraries, set up the parameters, downloaded stock prices of four US tech companies (Apple, IBM, Microsoft, and Twitter) over the years 2017-2018, and calculated simple returns, using the adjusted close prices.

In Step 5, we created a list of weights, each one equal to 1 / n_assets, where n_assets is the number of assets we want to have in our portfolio. Next, we calculated the portfolio returns as a matrix multiplication (also known as the dot product—np.dot) of the portfolio weights and a transposed matrix of asset returns. To transpose the matrix, we used the T method of a pandas DataFrame. Then, we stored the portfolio returns as a pandas Series object, because that is the input for the ensuing step.

Lastly, we created a tear sheet using pf.create_simple_tear_sheet. We decided to use a simple variant, containing the most relevant portfolio metrics and plots.

The most important metrics that we saw in the preceding table are:

  • Sharpe ratio: One of the most popular performance evaluation metrics, it measures the excess return (over the risk-free rate) per unit of standard deviation. When no risk-free rate is provided, the default assumption is that it is equal to 0%. The greater the Sharpe ratio, the better the portfolio's risk-adjusted performance.
  • Max drawdown: A metric of the downside risk of a portfolio, it measures the largest peak-to-valley loss (expressed as a percentage) during the course of the investment. The lower the maximum drawdown, the better.
  • Calmar ratio: The ratio is defined as the average annual compounded rate of return divided by the maximum drawdown for that same time period. The higher the ratio, the better.
  • Stability: Measured as the R-squared of a linear fit to the cumulative log returns. In practice, this means regressing a range of integers (serving as the time index) on cumulative log returns.
  • Omega ratio: The probability-weighted ratio of gains over losses for a determined return target threshold (default set to 0). Its main advantage over the Sharpe ratio is that the Omega ratio—by construction—considers all moments of the returns distribution, while the former only considers the first two (mean and variance).
  • Sortino ratio: A modified version of the Sharpe ratio, where the standard deviation in the denominator is replaced with downside deviation.
  • Skew: Skewness measures the degree of asymmetry, that is, how much is the given distribution (here, of portfolio returns) more skewed than the Normal distribution. Negative skewness (left-skewed distributions) means  that large negative returns occur more frequently than large positive ones.
  • Kurtosis: Measures extreme values in either of the tails. Distributions with large kurtosis exhibit tail data exceeding the tails of the Gaussian distribution, meaning that large and small returns occur more frequently.
  • Tail ratio: The ratio (absolute) between the 95th and 5th percentile of the daily returns. A tail ratio of ~0.8 means that losses are ~1.25 times as bad as profits.
  • Daily value at risk: Calculated as μ - 2σ, where μ is the average portfolio return over the period, and σ the corresponding standard deviation.
Downside deviation is similar to standard deviation; however, it only considers negative returns—it discards all positive changes from the series. It also allows us to define different levels of minimum acceptable returns (dependent on the investor), and returns below that threshold are used to calculate the downside deviation.

The tear sheet also contains the following plots:

  • Cumulative returns plot: It presents the evolution of the portfolio's worth over time:

  • Rolling Sharpe ratio: Instead of reporting one number over time, it is also interesting to see how stable the Sharpe ratio was. That is why the following plot presents this metric calculated on a rolling basis, using 6 months' worth of data:

  • Underwater plot (also known as the underwater equity curve): This plot presents the investment from a pessimistic point of view, as it focuses on losses. It plots all the drawdown periods and how long they lasted—until the value rebounded to a new high. One of the insights we can draw from this is how long the periods of losses lasted:

To obtain all the plots, we used the pf.create_simple_tear_sheet function. However, we can also obtain only the selected plots from the tear sheets. For example, to create the rolling Sharpe ratio plot seen previously, we can use the pf.plot_rolling_sharpe function. By calling the specific functions directly, we can make the plots more tailored to our needs. In this case, one of the parameters of the function corresponds to the rolling window's length.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.141.118