Overall Statistics
Total Orders
69
Average Win
14.22%
Average Loss
-10.58%
Compounding Annual Return
45.182%
Drawdown
66.300%
Expectancy
0.233
Start Equity
100000
End Equity
169732.29
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%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class USEnergyDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2020, 1, 1)
        self.set_end_date(2021, 6, 1)
        self.set_cash(100000)
        
        # Requesting data
        self.axas = self.add_equity("AXAS", Resolution.DAILY).symbol
        us_energy_symbol = self.add_data(USEnergy, USEnergy.Petroleum.UnitedStates.WeeklyNetImportsOfTotalPetroleumProducts).symbol

        # Historical data
        history = self.history(USEnergy, us_energy_symbol, 60, Resolution.DAILY)
        self.log(f"We got {len(history)} items from our history request")

        # Get latest value for net imports of petroleum products
        self.previous_value = history.loc[us_energy_symbol].values[-1, -1]
        
    def on_data(self, slice: Slice) -> None:
        # Gather the current net imports of petroleum products
        points = slice.Get(USEnergy)
        current_value = None
        for point in points.Values:
            current_value = point.Value
        if current_value is None:
            return
        
        # Buy when net imports of petroleum products are increasing
        if current_value > self.previous_value:
            self.set_holdings(self.axas, 1)
        
        # Short sell when net imports of petroleum products are decreasing
        elif current_value < self.previous_value:
            self.set_holdings(self.axas, -1)
        
        self.previous_value = current_value