Overall Statistics
Total Orders
5
Average Win
0%
Average Loss
-0.34%
Compounding Annual Return
-0.822%
Drawdown
0.900%
Expectancy
-0.5
Start Equity
100000
End Equity
99867.5
Net Profit
-0.132%
Sharpe Ratio
-0.854
Sortino Ratio
-0.753
Probabilistic Sharpe Ratio
25.191%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0
Alpha
-0.01
Beta
0.096
Annual Standard Deviation
0.015
Annual Variance
0
Information Ratio
0.138
Tracking Error
0.123
Treynor Ratio
-0.137
Total Fees
$4.00
Estimated Strategy Capacity
$130000000.00
Lowest Capacity Asset
IBM 2ZN0UI19JRV52|IBM R735QTJ8XC9X
Portfolio Turnover
0.95%
#region imports
    using System;
    using System.Linq;
    using QuantConnect.Util;
    using QuantConnect.Data;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Option;
#endregion

namespace QuantConnect.Algorithm.CSharp
{
    public class ProtectivePutAlgorithm : QCAlgorithm
    {
        private Symbol _put, _symbol;
        
        public override void Initialize()
        {
            SetStartDate(2014, 1, 1);
            SetEndDate(2014, 3, 1);
            SetCash(100000);

            var option = AddOption("IBM");
            _symbol = option.Symbol;
            option.SetFilter(universe => universe.IncludeWeeklys().NakedPut(30, 0));

            // use the underlying equity as the benchmark
            SetBenchmark(_symbol.Underlying);
        }

        public override void OnData(Slice slice)
        {
            if (_put != null && Portfolio[_put].Invested) return;

            if (!slice.OptionChains.TryGetValue(_symbol, out var chain)) return;

            // Find ATM put with the farthest expiry
            var expiry = chain.Max(x => x.Expiry);
            var atmPut = chain
                .Where(x=> x.Right == OptionRight.Put && x.Expiry == expiry)
                .OrderBy(x => Math.Abs(x.Strike - chain.Underlying.Price))
                .FirstOrDefault();

            if (atmPut == null) return;

            var protectivePut = OptionStrategies.ProtectivePut(_symbol, atmPut.Strike, expiry);
            Buy(protectivePut, 1);

            _put = atmPut.Symbol;
        }
    }
}