Overall Statistics
Total Orders
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
1687224.131%
Drawdown
2.600%
Expectancy
0
Start Equity
100000
End Equity
107400
Net Profit
7.400%
Sharpe Ratio
21293.56
Sortino Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
16442.571
Beta
-3.647
Annual Standard Deviation
0.772
Annual Variance
0.597
Information Ratio
16712.132
Tracking Error
0.984
Treynor Ratio
-4509.618
Total Fees
$0.00
Estimated Strategy Capacity
$110000.00
Lowest Capacity Asset
SPXW XUXKECCC3AJ2|SPX 31
Portfolio Turnover
4.98%
#region imports
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Util;
using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Orders.Fees;
using QuantConnect.Orders.Fills;
using QuantConnect.Securities;
using QuantConnect.Securities.Option;
#endregion
namespace QuantConnect.Algorithm.CSharp
{
    public class LogicalBlueLemur : QCAlgorithm
    {
        private Symbol _spxw;

        private bool _done;

        private bool _doSpread1 = true;

        private bool _doSpread2 = true;

        public override void Initialize()
        {            
            SetStartDate(2022, 1, 3);
            SetEndDate(2022, 1, 5);

            SetCash(100000);

            var index = AddIndex("SPX", Resolution.Minute).Symbol;

            var option = AddIndexOption(index, "SPXW", Resolution.Minute);

            option.SetFilter(x => x.IncludeWeeklys().Strikes(-20, 20).Expiration(1, 4));

            _spxw = option.Symbol;
        }

        public override void OnData(Slice slice)
        {
            if (Time.Date == new DateTime(2022, 1, 3) && _doSpread1)
            {
                if (!slice.OptionChains.TryGetValue(_spxw, out var chain)) return;

                Debug($"{Time}: remaining margin before spread 1: {Portfolio.MarginRemaining}");

                var spread = OptionStrategies.BearCallSpread(_spxw, 4730, 4780, new DateTime(2022, 1, 5));

                Buy(spread, 1);

                Debug($"{Time}: remaining margin after spread 1: {Portfolio.MarginRemaining}");

                _doSpread1 = false;
            }

            if (Time.Date == new DateTime(2022, 1, 4) && _doSpread2)
            {
                if (!slice.OptionChains.TryGetValue(_spxw, out var chain)) return;

                Debug($"{Time}: remaining margin before spread 2: {Portfolio.MarginRemaining}");

                var spread = OptionStrategies.BearCallSpread(_spxw, 4760, 4810, new DateTime(2022, 1, 5));

                Buy(spread, 1);

                Debug($"{Time}: remaining margin after spread 2: {Portfolio.MarginRemaining}");

                _doSpread2 = false;
            }
        }

        public override void OnEndOfAlgorithm()
        {
            Debug($"{Time}: remaining margin final: {Portfolio.MarginRemaining}");
        }
    }
}
<table>
    <tr>
        <td>_doSpread1</td>
        <td>_doSpread2</td>
        <td>Final remaining margin</td>
    </tr>
    <tr>
        <td>True</td>
        <td>False</td>
        <td>98,690</td>
    </tr>
    <tr>
        <td>False</td>
        <td>True</td>
        <td>98,710</td>
    </tr>
    <tr>
        <td>True</td>
        <td>True</td>
        <td>16,649.25</td>
    </tr>
</table>