Overall Statistics
Total Orders
13333
Average Win
0.07%
Average Loss
-0.01%
Compounding Annual Return
19.304%
Drawdown
26.200%
Expectancy
0.526
Start Equity
100000
End Equity
128515.15
Net Profit
28.515%
Sharpe Ratio
0.539
Sortino Ratio
0.821
Probabilistic Sharpe Ratio
24.899%
Loss Rate
81%
Win Rate
19%
Profit-Loss Ratio
6.99
Alpha
0.238
Beta
-0.745
Annual Standard Deviation
0.272
Annual Variance
0.074
Information Ratio
0.053
Tracking Error
0.451
Treynor Ratio
-0.197
Total Fees
$13212.00
Estimated Strategy Capacity
$2000000.00
Lowest Capacity Asset
JG WWHT0YOVJBL1
Portfolio Turnover
3.92%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class QuiverWallStreetBetsDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self.universe_settings.resolution = Resolution.DAILY
        self._universe = self.add_universe(QuiverWallStreetBetsUniverse, self.universe_selection)

    def on_data(self, slice: Slice) -> None:
        points = slice.Get(QuiverWallStreetBets)
        for point in points.Values:
            symbol = point.symbol.underlying
            
            # Buy if the stock was mentioned more than 5 times in the WallStreetBets daily discussion
            if point.mentions > 5 and not self.portfolio[symbol].is_long:
                self.market_order(symbol, 1)
                
            # Otherwise, short sell
            elif point.mentions <= 5 and not self.portfolio[symbol].is_short:
                self.market_order(symbol, -1)

    def on_securities_changed(self, changes: SecurityChanges) -> None:
        for added in changes.added_securities:
            # Requesting data
            quiver_w_s_b_symbol = self.add_data(QuiverWallStreetBets, added.symbol).symbol

            # Historical data
            history = self.history(QuiverWallStreetBets, quiver_w_s_b_symbol, 60, Resolution.DAILY)
            self.debug(f"We got {len(history)} items from our history request")

    def universe_selection(self, alt_coarse: List[QuiverWallStreetBetsUniverse]) -> List[Symbol]:
        for datum in alt_coarse:
            self.log(f"{datum.symbol},{datum.mentions},{datum.rank},{datum.sentiment}")
        
        # define our selection criteria

        return [d.symbol for d in alt_coarse \
                    if d.mentions > 10 \
                    and d.rank < 100]