Overall Statistics
Total Orders
1960
Average Win
0.39%
Average Loss
-0.35%
Compounding Annual Return
21.979%
Drawdown
18.700%
Expectancy
0.281
Start Equity
100000
End Equity
251424.38
Net Profit
151.424%
Sharpe Ratio
0.937
Sortino Ratio
1.062
Probabilistic Sharpe Ratio
53.188%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
1.13
Alpha
0.093
Beta
0.458
Annual Standard Deviation
0.143
Annual Variance
0.02
Information Ratio
0.291
Tracking Error
0.152
Treynor Ratio
0.293
Total Fees
$4286.65
Estimated Strategy Capacity
$2500000.00
Lowest Capacity Asset
FNA XSOQ708JLBHH
Portfolio Turnover
7.80%
# 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, min(0.1, 1.5 * (inv_volatility_by_symbol[symbol] / inv_volatility_by_symbol.sum())) )
            for symbol in symbols
        ]
        self.set_holdings(targets, True)