Overall Statistics
Total Orders
1076
Average Win
1.43%
Average Loss
-1.74%
Compounding Annual Return
-17.242%
Drawdown
78.800%
Expectancy
-0.083
Start Equity
100000
End Equity
38805.96
Net Profit
-61.194%
Sharpe Ratio
-0.144
Sortino Ratio
-0.179
Probabilistic Sharpe Ratio
0.214%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.82
Alpha
-0.18
Beta
1.623
Annual Standard Deviation
0.456
Annual Variance
0.208
Information Ratio
-0.337
Tracking Error
0.404
Treynor Ratio
-0.041
Total Fees
$1340.63
Estimated Strategy Capacity
$400000.00
Lowest Capacity Asset
CMA R735QTJ8XC9X
Portfolio Turnover
5.34%
Drawdown Recovery
20
# region imports
from AlgorithmImports import *
# endregion


class WellDressedSkyBlueSardine(QCAlgorithm):

    def initialize(self):
        self.set_start_date(self.end_date - timedelta(5*365))
        self.set_cash(100000)
        self.settings.seed_initial_prices = True
        # Add a universe of US Equities that updates each month.
        self._date_rule = self.date_rules.month_start('SPY')
        self.universe_settings.schedule.on(self._date_rule)
        self.universe_settings.resolution = Resolution.HOUR
        self._universe = self.add_universe(self._select_assets)
        # Add warm-up so the algorithm trades on deployment.
        self.set_warm_up(timedelta(45))
        
    def _select_assets(self, fundamentals):
        # Select stocks above $10 that have fundamental data.
        fundamentals = [f for f in fundamentals if f.price > 10 and f.has_fundamental_data]
        # Select the subset with the most volume.
        sorted_by_dollar_volume = sorted(fundamentals, key=lambda f: f.dollar_volume)
        # Select the subset with the lowest market cap.
        sorted_by_market_cap = sorted(
            [f for f in sorted_by_dollar_volume[-200:] if f.market_cap > 0],
            key=lambda f: f.market_cap
        )
        return [f. symbol for f in sorted_by_market_cap[:10]]

    def on_warmup_finished(self):
        # Add a Scheduled event to rebalance the portfolio monthly.
        time_rule = self.time_rules.at(10, 0)
        self.schedule.on(self._date_rule, time_rule, self._rebalance)
        # Rebalance the portfolio today too.
        if self.live_mode:
            self._rebalance()
        else:
            self.schedule.on(self.date_rules.today, time_rule, self._rebalance)

    def _rebalance(self):
        # Give an equal allocation to each stock in the universe.
        weight = 1 / len(self._universe.selected)
        targets = [PortfolioTarget(symbol, weight) for symbol in self._universe.selected]
        self.set_holdings(targets, True)