Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
0.333%
Drawdown
0.800%
Expectancy
0
Net Profit
0.110%
Sharpe Ratio
0.242
Probabilistic Sharpe Ratio
31.677%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.014
Beta
0.033
Annual Standard Deviation
0.012
Annual Variance
0
Information Ratio
-4.646
Tracking Error
0.106
Treynor Ratio
0.085
Total Fees
$23.91
Estimated Strategy Capacity
$10000000.00
from QuantConnect.Data.Custom.SmartInsider import *

class SmartInsiderAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetEndDate(2019, 5, 1)
        self.SetCash(1000000)
        
        self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseUniverse))
        
        
#        # Request underlying equity data.
 #       ibm = self.AddEquity("IBM", Resolution.Minute).Symbol
  #      # Add Smart Insider stock buyback transaction data for the underlying IBM asset
   #     si = self.AddData(SmartInsiderTransaction, ibm).Symbol
    #    # Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol
     #   history = self.History(SmartInsiderTransaction, si, 60, Resolution.Daily)
        
        # Count the number of items we get from our history request
      #  self.Debug(f"We got {len(history)} items from our history request")

                
    def CoarseUniverse(self, coarse):
        symbols = [i.Symbol for i in coarse if i.HasFundamentalData and i.DollarVolume > 50000000][:20]
        
        for symbol in symbols:
            self.AddData(SmartInsiderTransaction, symbol)

        return symbols

    def OnData(self, data): 
        
        # Get all SmartInsider data available
        transactions = data.Get(SmartInsiderTransaction)
        
        # Loop over all the insider transactions 
        for transaction in transactions.Values: 
            if transaction.VolumePercentage is None or transaction.EventType is None:
                continue
            
            # Using the SmartInsider transaction information, buy when company does a stock buyback
            if transaction.EventType == SmartInsiderEventType.Transaction and transaction.BuybackPercentage > 0.01:
               self.SetHoldings(transaction.Symbol.Underlying, transaction.VolumePercentage / 100)
                # self.SetHoldings(transaction.Symbol.Underlying, 0.10)
                
                
    def OnSecuritiesChanged(self, changes):
        for r in [i for i in changes.RemovedSecurities if i.Symbol.SecurityType == SecurityType.Equity]:
            # If removed from the universe, liquidate and remove the custom data from the algorithm
            self.Liquidate(r.Symbol)
            self.RemoveSecurity(Symbol.CreateBase(SmartInsiderTransaction, r.Symbol, Market.USA))