Overall Statistics
Total Orders
1066
Average Win
0.32%
Average Loss
-0.34%
Compounding Annual Return
15.753%
Drawdown
9.900%
Expectancy
0.353
Start Equity
100000
End Equity
203252.15
Net Profit
103.252%
Sharpe Ratio
0.93
Sortino Ratio
1.077
Probabilistic Sharpe Ratio
65.645%
Loss Rate
30%
Win Rate
70%
Profit-Loss Ratio
0.92
Alpha
0.082
Beta
0.03
Annual Standard Deviation
0.091
Annual Variance
0.008
Information Ratio
-0.013
Tracking Error
0.194
Treynor Ratio
2.87
Total Fees
$1151.61
Estimated Strategy Capacity
$6400000.00
Lowest Capacity Asset
VXZB WRBPJAJZ2Q91
Portfolio Turnover
0.79%
from AlgorithmImports import *
from scipy.optimize import minimize

class LeverageEtfRiskParity(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self.set_cash(100000)
        self.symbols = [self.add_equity(ticker, data_normalization_mode=DataNormalizationMode.RAW).symbol for ticker in ["TQQQ", "SVXY", "VXZ", "TMF", "EDZ", "UGL"]]
        self.schedule.on(self.date_rules.week_start(), self.time_rules.at(8, 0), self.rebalance)

    def rebalance(self):
        ret = self.history(self.symbols, 253, Resolution.DAILY).close.unstack(0).pct_change().dropna()
        x0 = [1/ret.shape[1]] * ret.shape[1]
        constraints = {"type": "eq", "fun": lambda w: np.sum(w) - 1}
        bounds = [(0, 1)] * ret.shape[1]
        opt = minimize(lambda w: 0.5 * (w.T @ ret.cov() @ w) - x0 @ w, x0=x0, constraints=constraints, bounds=bounds, tol=1e-8, method="SLSQP")
        self.set_holdings([PortfolioTarget(symbol, weight) for symbol, weight in zip(ret.columns, opt.x)])