kryptos
kryptos copied to clipboard
Quantify Risk
User Stories
As a user, I want to know how risky is one trading strategy, so that I can better decide between two different strategies.
As a user, I want to see "Based on your portfolio in the last X minutes/days/weeks/months, your risk is low/medium/high," so that I can better understand how my strategy has performed over time.
Consider
We can calculate risk based on risk and/or performance metrics of any portfolio.
We can use the following metrics, accessible by quantopian's empyrical library:
1. aggregate_returns - Aggregates returns by week, month, or year
2. alpha - Calculates annualized alpha
3. alpha_aligned - Calculates annualized alpha (aligned on labels)
4. alpha_beta - Calculates annualized alpha and beta
5. alpha_beta_aligned - Calculates annualized alpha and beta (aligned on labels)
6. annual_return - Determines the mean annual growth rate of returns. This is equivilent to the compound annual growth rate.
7. annual_volatility - Determines the annual volatility of a strategy
8. beta - Calculates beta
9. beta_aligned - Calculates beta (aligned on labels)
10. cagr - Compute compound annual growth rate
11. calmar_ratio - Determines the Calmar ratio, or drawdown ratio, of a strategy
12. capture - Compute capture ratio
13. conditional_value_at_risk - Conditional value at risk (CVaR) of a returns stream
14. cum_returns - Compute cumulative returns from simple returns
15. cum_returns_final - Compute total returns from simple returns
16. down_alpha_beta - Computes alpha and beta for periods when the benchmark return is negative
17. down_capture - Compute the capture ratio for periods when the benchmark return is negative
18. downside_risk - Determines the downside deviation below a threshold
19. excess_sharpe - Determines the Excess Sharpe of a strategy
20. max_drawdown - Determines the maximum drawdown of a strategy
21. omega_ratio - Determines the Omega ratio of a strategy
22. roll_alpha - Calculates annualized alpha over a rolling window
23. roll_alpha_aligned - Calculates annualized alpha (aligned on labels) over a rolling window
24. roll_alpha_beta - Calculates annualized alpha and beta over a rolling window
25. roll_alpha_beta_aligned - Calculates annualized alpha and beta (aligned on labels) over a rolling window.
26. roll_annual_volatility - Determines the annual volatility of a strategyover a rolling window
27. roll_beta - Calculates beta over a rolling window
28. roll_beta_aligned - Calculates annualized alpha and beta (aligned on labels) over a rolling window
29. roll_down_capture - Compute the capture ratio for periods when the benchmark return is negative over a rolling window.
30. roll_max_drawdown - Determines the maximum drawdown of a strategy over a rolling window
31. roll_sharpe_ratio - Determines the Sharpe ratio of a strategy over a rolling window
32. roll_sortino_ratio - Determines the Sortino ratio of a strategy over a rolling window
33. roll_up_capture - Computes the up capture measure over a rolling window
34. roll_up_down_capture - Computes the up/down capture measure over a rolling window
35. sharpe_ratio - Determines the Sharpe ratio of a strategy
36. sortino_ratio - Determines the Sortino ratio of a strategy
37. stability_of_timeseries - Determines R-squared of a linear fit to the cumulative log returns. Computes an ordinary least squares linear fit, and returns R-squared.
38. tail_ratio - Determines the ratio between the right (95%) and left tail (5%)
39. up_alpha_beta - Computes alpha and beta for periods when the benchmark return is positive
40. up_capture - Compute the capture ratio for periods when the benchmark return is positive
41. up_down_capture - Computes the ratio of up_capture to down_capture
42. value_at_risk - Value at risk (VaR) of a returns stream
We can also use the following metrics (inspired by Signals Network):
1. Average profit (%)
2. Average loss (%)
3. Average trade (%)
4. Win rate (%)
5. Loss rate (%)
6. Maximum drawdown (%)
We can use the following metrics, accessible by quantopian's pyfolio library:
Simple Statistics
1. cum_returns_final - Compute total returns from simple returns
2. annual_return - Determines the mean annual growth rate of returns. This is equivilent to the compound annual growth rate.
3. annual_volatility - Determines the annual volatility of a strategy
4. sharpe_ratio - Determines the Sharpe ratio of a strategy
5. calmar_ratio - Determines the Calmar ratio, or drawdown ratio, of a strategy
6. stability_of_timeseries - Determines R-squared of a linear fit to the cumulative log returns. Computes an ordinary least squares linear fit, and returns R-squared.
7. max_drawdown - Determines the maximum drawdown of a strategy
8. omega_ratio - Determines the Omega ratio of a strategy
9. sortino_ratio - Determines the Sortino ratio of a strategy
10. tail_ratio - Determines the ratio between the right (95%) and left tail (5%)
11. cagr - Compute compound annual growth rate. Alias function for annual_return.
12. value_at_risk - Value at risk (VaR) of a returns stream
13. conditional_value_at_risk - Conditional value at risk (CVaR) of a returns stream. CVaR measures the expected single-day returns of an asset on that asset's worst performing days, where "worst-performing" is defined as falling below cutoff as a percentile of all daily returns.
14. common_sense_ratio - Common sense ratio is the multiplication of the tail ratio and the Gain-to-Pain-Ratio -- sum(profits) / sum(losses).
15. kurtosis - The sharpness of the peak of a frequency-distribution curve
Factor Analysis
1. excess_sharpe - Determines the Excess Sharpe of a strategy
2. alpha - Calculates annualized alpha
3. beta - Calculates beta
4. capture - Compute capture ratio
5. up_capture - Compute the capture ratio for periods when the benchmark return is positive
6. down_capture - Compute the capture ratio for periods when the benchmark return is negative
We can consider using Quantopian's allocation process for raising capital based on a strategy's risk.
Quantopian allocates capital from external investors to select algorithms written by our community members (hopefully including you!). Starting allocations average approximately $5 million per algorithm and vary by each algorithm's expected trading capacity and performance. We hope to eventually allocate as much as $50 million to a single algorithm. (Quantopian, 2018)
In order to allocate $5 Mil of USD, Quantopian sets a high bar for risk. For example:
We are looking for algorithms that consistently have a Sharpe ratio over 1.0. (Quantopian, 2018)
We can also consider how Quantopian performs Portfolio Analysis.
According to Eurekahedge Crypto-Currency Hedge Fund Index, Risk and Return are calculated using:
- Annualised Standard Deviation (%)
- Downside Deviation (%)
- Upside Deviation (%)
- Maximum Drawdown (%)
- Sharpe Ratio
- Sortino Ratio
- Percentage of Positive Months (%)

Let's use Sharpe Ratio to evaluate portfolio based on a time (last X minutes/days/weeks/months)
What is a Sharpe Ratio?
The basic purpose of the Sharpe ratio is to allow an investor to analyze how much greater a return he or she is obtaining in relation to the level of additional risk taken to generate that return. (Investopedia, 2018)
What is a "good" Sharpe Ratio?
Any Sharpe ratio greater than 1 is considered acceptable to good by investors. A ratio higher than 2 is rated as very good, and a ratio of 3 or higher is considered excellent. (Investopedia, 2018)
According to Marcos Lopez de Prado (Advances in Financial Machine Learning, 2018), strategy risk is best calculated as:
- Sharpe Ratio (SR): The purpose of SR is to evaluate the skills of a particular strategy or investor. Since 𝜇, 𝜎 are usually unknown, the true SR value cannot be known for certain. The inevitable consequence is that Sharpe ratio calculations may be the subject of substantial estimation errors.
- Probabilistic Sharpe Ratio (PSR): PSR corrects SR for inflationary effects caused by non-Normal returns or track record length.
- Deflated Sharpe Ratio (DSR): DSR corrects SR for inflationary effects caused by non-Normal returns, track record length, and multiple testing/selection bias.
- Annualized Sharpe Ratio: This is the SR value, annualized by a factor √a, where a is the average number of returns observed per year. This common annualization method relies on the assumption that returns are IID.
- Information Ratio: This is the SR equivalent of a portfolio that measures its performance relative to a benchmark. It is the annualized ratio between the average excess return and the tracking error. The excess return is measured as the portfolio’s return in excess of the benchmark’s return. The tracking error is estimated as the standard deviation of the excess returns.
Marcos recommends the following:
- PSR should exceed 0.95, for the standard significance level of 5%. It can be computed on absolute or relative returns.
- DSR should exceed 0.95, for the standard significance level of 5%. It can be computed on absolute or relative returns.