Overall Statistics
Total Orders
46
Average Win
2.25%
Average Loss
-2.68%
Compounding Annual Return
2.268%
Drawdown
12.400%
Expectancy
0.200
Start Equity
100000
End Equity
111876.65
Net Profit
11.877%
Sharpe Ratio
0.004
Sortino Ratio
0.001
Probabilistic Sharpe Ratio
3.048%
Loss Rate
35%
Win Rate
65%
Profit-Loss Ratio
0.84
Alpha
-0.005
Beta
0.051
Annual Standard Deviation
0.054
Annual Variance
0.003
Information Ratio
-0.624
Tracking Error
0.158
Treynor Ratio
0.004
Total Fees
$530.53
Estimated Strategy Capacity
$64000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
Portfolio Turnover
2.30%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class CorporateBuybacksDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2016, 1, 1)
        self.set_end_date(2021, 1, 1)
        self.set_cash(100000)
 
        self.aapl = self.add_equity("AAPL", Resolution.MINUTE).symbol
        
        # Requesting data
        self.smart_insider_intention = self.add_data(SmartInsiderIntention, self.aapl).symbol
        self.smart_insider_transaction = self.add_data(SmartInsiderTransaction, self.aapl).symbol
        
        # Historical data
        history = self.history(self.smart_insider_intention, 365, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from our history request for intentions")
        
        history = self.history(self.smart_insider_transaction, 365, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from our history request for transactions")

    def on_data(self, slice: Slice) -> None:
        # Buy Apple whenever we receive a buyback intention or transaction notification
        if slice.contains_key(self.smart_insider_intention) or slice.contains_key(self.smart_insider_transaction):
            self.set_holdings(self.aapl, 1)
            self.entry_time = self.time
        
        # Liquidate holdings 3 days after the latest entry
        if self.portfolio.invested and self.time >= self.entry_time + timedelta(days=3):
            self.liquidate()