Overall Statistics
Total Trades
26
Average Win
0.90%
Average Loss
0.00%
Compounding Annual Return
26.658%
Drawdown
4.700%
Expectancy
255.054
Net Profit
10.315%
Sharpe Ratio
2.733
Probabilistic Sharpe Ratio
92.250%
Loss Rate
31%
Win Rate
69%
Profit-Loss Ratio
371.44
Alpha
0.105
Beta
0.331
Annual Standard Deviation
0.066
Annual Variance
0.004
Information Ratio
-0.495
Tracking Error
0.095
Treynor Ratio
0.546
Total Fees
$33.21
Estimated Strategy Capacity
$99000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    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.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 QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

namespace QuantConnect.Algorithm.CSharp
{
    public class DemoAlgorithm : QCAlgorithm
    {
        private Symbol _symbol;
        private RollingWindow<decimal> _window = new(24);

        public override void Initialize()
        {
            SetStartDate(2021, 1, 1);
            SetEndDate(2021, 6, 1);
            SetCash(100000);

            _symbol = AddEquity("SPY", Resolution.Hour).Symbol;

            // warm up the rolling window
            var history = History<TradeBar>(_symbol, 24, Resolution.Hour);
            foreach (var bar in history)
            {
                _window.Add(bar.Volume);
            }
        }

        public override void OnData(Slice slice)
        {
            // volume is only available in trade bar
            if (slice.Bars.ContainsKey(_symbol))
            {
                _window.Add(slice.Bars[_symbol].Volume);

                if (_window.Sum() >= 300000000)
                {
                    SetHoldings(_symbol, 1);
                }
                else
                {
                    Liquidate(_symbol);
                }
            }
        }
    }
}