Overall Statistics
Total Orders
3
Average Win
0%
Average Loss
-21.97%
Compounding Annual Return
6.753%
Drawdown
33.900%
Expectancy
-1
Start Equity
100000
End Equity
110439.72
Net Profit
10.440%
Sharpe Ratio
0.31
Sortino Ratio
0.246
Probabilistic Sharpe Ratio
16.155%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.078
Beta
0.776
Annual Standard Deviation
0.206
Annual Variance
0.042
Information Ratio
-1.079
Tracking Error
0.11
Treynor Ratio
0.082
Total Fees
$4.64
Estimated Strategy Capacity
$58000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
0.54%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class IndexDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2020, 1, 1)
        self.set_end_date(2021, 7, 8)
        self.set_cash(100000)

        # Trade on SPY
        self.spy = self.add_equity("SPY").symbol

        # Use indicator for signal; but it cannot be traded
        spx = self.add_index("SPX").symbol
        self.ema_fast = self.EMA(spx, 80, Resolution.DAILY)
        self.ema_slow = self.EMA(spx, 200, Resolution.DAILY)
        self.set_warm_up(200, Resolution.DAILY)

        history = self.history(spx, 60, Resolution.DAILY)
        self.debug(f'We got {len(history.index)} items from our history request')

    def on_data(self, slice: Slice) -> None:
        # Warm up indicators
        if self.is_warming_up or not self.ema_slow.is_ready:
            return

        if not self.portfolio.invested and self.ema_fast > self.ema_slow:
            self.set_holdings(self.spy, 1)
        elif self.ema_fast < self.ema_slow:
            self.liquidate()