Overall Statistics
Total Orders
1996
Average Win
0.95%
Average Loss
-1.12%
Compounding Annual Return
10.162%
Drawdown
64.800%
Expectancy
0.085
Start Equity
100000
End Equity
156650.25
Net Profit
56.650%
Sharpe Ratio
0.381
Sortino Ratio
0.37
Probabilistic Sharpe Ratio
5.718%
Loss Rate
41%
Win Rate
59%
Profit-Loss Ratio
0.84
Alpha
0.051
Beta
1.534
Annual Standard Deviation
0.498
Annual Variance
0.248
Information Ratio
0.233
Tracking Error
0.427
Treynor Ratio
0.124
Total Fees
$7087.69
Estimated Strategy Capacity
$2000000.00
Lowest Capacity Asset
FNA XSOQ708JLBHH
Portfolio Turnover
23.65%
# region imports
from AlgorithmImports import *
# endregion


class LeveragedCopyCongressAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self.set_cash(100000)
        self._universe = self.add_universe(
            QuiverQuantCongressUniverse, 
            lambda constituents: [c.symbol for c in constituents if c.transaction == OrderDirection.BUY]
        )
        spy = Symbol.create('SPY', SecurityType.EQUITY, Market.USA)
        self.schedule.on(self.date_rules.week_start(spy), self.time_rules.after_market_open(spy, 30), self._trade)

    def _trade(self):
        if self._universe.selected is None: return
        symbols = [s for s in self._universe.selected if s in self.securities and self.securities[s].price]
        if len(symbols) == 0: return
        inv_volatility_by_symbol = 1 / self.history(symbols, timedelta(6*30), Resolution.DAILY)['close'].unstack(0).pct_change().iloc[1:].std()
        targets = [
            PortfolioTarget(symbol, 1.5 * (inv_volatility_by_symbol[symbol] / inv_volatility_by_symbol.sum())) 
            for symbol in symbols
        ]
        self.set_holdings(targets, True)