Overall Statistics
Total Trades
253
Average Win
0.85%
Average Loss
-0.24%
Compounding Annual Return
25.313%
Drawdown
8.700%
Expectancy
0.493
Net Profit
16.903%
Sharpe Ratio
2.215
Probabilistic Sharpe Ratio
83.866%
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
3.48
Alpha
0.258
Beta
0.017
Annual Standard Deviation
0.118
Annual Variance
0.014
Information Ratio
0.183
Tracking Error
0.406
Treynor Ratio
15.584
Total Fees
$1597.57
import pandas as pd
import numpy as np
from io import StringIO

class RedditStockSentiment(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.tickers = ["SPCE", "LULU", "CCL", "SDC"]
        for stock in self.tickers:
            self.AddEquity(stock, Resolution.Hour)
        
        self.AddRiskManagement(TrailingStopRiskManagementModel(0.04))
        
        self.lastday = -1
        
        csv = self.Download("https://www.dropbox.com/s/qydhy62v08tw4em/Reddit_Sentiment_Equity.csv?dl=1")
        self.df = pd.read_csv(StringIO(csv))


    def OnData(self, data):
        
        algYear = self.Time.year
        algMonth = self.Time.month
        algDay = self.Time.day
        
        if algDay == self.lastday:
            return
        self.lastday = algDay
        
        for row in self.df.itertuples():
            date = row[-1]
            year = date[0:4]
            month = date[5:7]
            day = date[8:10]
            
            if (int(year) != algYear) or (int(month) != algMonth) or (int(day) != algDay):
                continue
            stock = str(row[1])
            averageSentiment = float(row[3])
            numberOfComments = int(row[2])
            score = int(row[5])
        
            if(averageSentiment >= 0.1) and not self.Portfolio[stock].IsLong:
                self.SetHoldings(stock, 0.25, True)
            if(averageSentiment <= -0.1) and not self.Portfolio[stock].IsShort:
                self.SetHoldings(stock, -0.07, True)
            if (-0.1 < averageSentiment < 0.1):
                self.Liquidate(stock)