| Overall Statistics |
|
Total Orders 9 Average Win 15.24% Average Loss -0.94% Compounding Annual Return 8.480% Drawdown 27.100% Expectancy 11.864 Start Equity 100000 End Equity 150248.91 Net Profit 50.249% Sharpe Ratio 0.253 Sortino Ratio 0.274 Probabilistic Sharpe Ratio 12.021% Loss Rate 25% Win Rate 75% Profit-Loss Ratio 16.15 Alpha -0.016 Beta 0.616 Annual Standard Deviation 0.112 Annual Variance 0.012 Information Ratio -0.495 Tracking Error 0.088 Treynor Ratio 0.046 Total Fees $32.46 Estimated Strategy Capacity $200000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 0.49% Drawdown Recovery 793 |
#region imports
from AlgorithmImports import *
#endregion
class PairedSwitching(QCAlgorithm):
def initialize(self):
self.set_start_date(self.end_date - timedelta(5*365))
self.set_cash(100000)
# we select two etfs that are negatively correlated; equity and bond etfs
self._equities = self.add_equity("SPY")
self._bonds = self.add_equity("AGG")
self._equities.roc = self.roc(self._equities, 90, Resolution.DAILY)
self._bonds.roc = self.roc(self._bonds, 90, Resolution.DAILY)
# monthly scheduled event but rebalancing will run on quarterly basis
self._months = -1
self.schedule.on(self.date_rules.month_start("SPY"), self.time_rules.after_market_open("SPY", 1), self._rebalance)
def _rebalance(self):
# Rebalance quarterly.
self._months +=1
if self._months%3 != 0:
return
# buys the fund that has the higher return during the period
target = self._equities if self._equities.roc > self._bonds.roc else self._bonds
if not target.invested:
self.set_holdings([PortfolioTarget(target, 1)], True)