Overall Statistics
Total Orders
1960
Average Win
0.39%
Average Loss
-0.35%
Compounding Annual Return
21.903%
Drawdown
18.700%
Expectancy
0.280
Start Equity
100000
End Equity
250696.91
Net Profit
150.697%
Sharpe Ratio
0.934
Sortino Ratio
1.058
Probabilistic Sharpe Ratio
52.879%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
1.13
Alpha
0.092
Beta
0.458
Annual Standard Deviation
0.143
Annual Variance
0.02
Information Ratio
0.288
Tracking Error
0.152
Treynor Ratio
0.292
Total Fees
$4278.71
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):
        symbols = list(self._universe.selected)
        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 
            if symbol in inv_volatility_by_symbol
        ]
        self.set_holdings(targets, True)