Overall Statistics
Total Orders
46
Average Win
2.25%
Average Loss
-2.68%
Compounding Annual Return
2.268%
Drawdown
12.400%
Expectancy
0.200
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%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using System.Text.RegularExpressions;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

namespace QuantConnect.Algorithm.CSharp.AltData
{
    public class CorporateBuybacksDataAlgorithm : QCAlgorithm
    {
        private Symbol _aapl;
        private Symbol _smartInsiderIntention;
        private Symbol _smartInsiderTransaction;
        private DateTime _entryTime;
        
        public override void Initialize()
        {
            SetStartDate(2016, 1, 1);
            SetEndDate(2021, 1, 1);
            SetCash(100000);
            
            _aapl = AddEquity("AAPL", Resolution.Minute).Symbol;
            
            // Requesting data
            _smartInsiderIntention = AddData<SmartInsiderIntention>(_aapl).Symbol;
            _smartInsiderTransaction = AddData<SmartInsiderTransaction>(_aapl).Symbol;
            
            // Historical data
            var intentionHistory = History<SmartInsiderIntention>(_smartInsiderIntention, 365, Resolution.Daily);
            Debug($"We got {intentionHistory.Count()} items from our history request for intentions");
            
            var transactionHistory = History<SmartInsiderTransaction>(_smartInsiderTransaction, 365, Resolution.Daily);
            Debug($"We got {transactionHistory.Count()} items from our history request for transactions");
        }

        public override void OnData(Slice slice)
        {
            // Buy Apple whenever we receive a buyback intention or transaction notification
            if (slice.ContainsKey(_smartInsiderIntention) || slice.ContainsKey(_smartInsiderTransaction))
            {
                SetHoldings(_aapl, 1);
                _entryTime = Time;
            }
 
            // Liquidate holdings 3 days after the latest entry
            if (Portfolio.Invested && Time >= _entryTime + TimeSpan.FromDays(3))
            {
                Liquidate();
            }
        }
    }
}