Overall Statistics
Total Orders
69
Average Win
14.22%
Average Loss
-10.58%
Compounding Annual Return
45.182%
Drawdown
66.300%
Expectancy
0.233
Net Profit
69.732%
Sharpe Ratio
1.297
Sortino Ratio
2.237
Probabilistic Sharpe Ratio
33.905%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
1.34
Alpha
1.572
Beta
1.2
Annual Standard Deviation
1.378
Annual Variance
1.898
Information Ratio
1.193
Tracking Error
1.348
Treynor Ratio
1.489
Total Fees
$20732.10
Estimated Strategy Capacity
$23000.00
Lowest Capacity Asset
ABP RXBFGHC4AV6T
Portfolio Turnover
19.40%
#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

using QuantConnect.DataSource;

namespace QuantConnect
{
    public class USEnergyDataAlgorithm : QCAlgorithm
    {
        private decimal? previousValue;
        private Symbol tradableSymbol;
        
        public override void Initialize()
        {
            SetStartDate(2020, 1, 1);
            SetEndDate(2021, 6, 1);
            SetCash(100000);
            
            // Requesting data
            tradableSymbol = AddEquity("AXAS", Resolution.Daily).Symbol;
            var USEnergySymbol = AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyNetImportsOfTotalPetroleumProducts).Symbol;

            // Historical data            
            var history = History<USEnergy>(USEnergySymbol, 60, Resolution.Daily);
            Debug($"We got {history.Count()} items from our history request");
            
            // Get latest value for net imports of petroleum products
            previousValue = history.Last().Value;
        }

        
        public override void OnData(Slice slice)
        {
            // Gather the current net imports of petroleum products
            var points = slice.Get<USEnergy>();
            decimal? currentValue = null;
            foreach (var point in points.Values)
            {
                currentValue = point.Value;
            }
            if (currentValue == null)
            {
                return;
            }
            
            // Buy when net imports of petroleum products are increasing
            if (currentValue > previousValue)
            {
                SetHoldings(tradableSymbol, 1);
            }
            
            //  Short sell when net imports of petroleum products are decreasing
            if (currentValue < previousValue)
            {
                SetHoldings(tradableSymbol, -1);
            }
            
            previousValue = currentValue;
        }
    }
}