Overall Statistics
Total Trades
343
Average Win
0.00%
Average Loss
-0.22%
Compounding Annual Return
0.358%
Drawdown
0.200%
Expectancy
0.007
Net Profit
0.224%
Sharpe Ratio
1.511
Loss Rate
1%
Win Rate
99%
Profit-Loss Ratio
0.01
Alpha
0.006
Beta
-0.176
Annual Standard Deviation
0.002
Annual Variance
0
Information Ratio
-6.696
Tracking Error
0.002
Treynor Ratio
-0.017
Total Fees
$43.75
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;

namespace QuantConnect 
{
    public partial class ShortStrangle : QCAlgorithm 
    {
		string iSymbol = "SPY";

		DateTime iTime;

        public override void Initialize()
        {
        	SetCash(100000);
            SetStartDate(2018, 1, 1);
            SetEndDate(DateTime.Now.Date); 
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage);
			AddEquity(iSymbol, Resolution.Minute);
       }
        
        public void OnData(TradeBars data) 
        {
        	if (IsMarketOpen(iSymbol) == false)
        	{
        		return;
        	}
        	
        	if (IsNewBar(TimeSpan.FromHours(1)) == false)
        	{
        		return;
        	}
        	
        	var price = Securities[iSymbol].Price;
        	
			if (Portfolio[iSymbol].Invested)
			{
				Liquidate();
			}
			
			if (Portfolio.Invested == false)
			{
				var contracts = OptionChainProvider.GetOptionContractList(iSymbol, Time);
				
				var longPut = contracts
					.Where(c => c.ID.OptionRight == OptionRight.Put)
					.Where(c => price - c.ID.StrikePrice >= 0 && price - c.ID.StrikePrice <= 5)
                	.OrderBy(c => c.ID.Date)
                	.ThenBy(c => c.ID.StrikePrice)
                	.FirstOrDefault();
				
				var longCall = contracts
					.Where(c => c.ID.OptionRight == OptionRight.Call)
					.Where(c => c.ID.StrikePrice - price >= 0 && c.ID.StrikePrice - price <= 5)
                	.OrderBy(c => c.ID.Date)
					.ThenByDescending(c => c.ID.StrikePrice)
					.FirstOrDefault();
				
				var shortPut = contracts
					.Where(c => c.ID.OptionRight == OptionRight.Put)
					.Where(c => price - c.ID.StrikePrice > 5 && price - c.ID.StrikePrice <= 10)
                	.OrderBy(c => c.ID.Date)
					.ThenBy(c => c.ID.StrikePrice)
                	.FirstOrDefault();

				var shortCall = contracts
					.Where(c => c.ID.OptionRight == OptionRight.Call)
					.Where(c => c.ID.StrikePrice - price > 5 && c.ID.StrikePrice - price <= 10)
                	.OrderBy(c => c.ID.Date)
					.ThenByDescending(c => c.ID.StrikePrice)
                	.FirstOrDefault();
				
				if (longCall != null && longPut != null && shortCall != null && shortPut != null)
				{
	                AddOptionContract(longPut, Resolution.Minute);
	                AddOptionContract(longCall, Resolution.Minute);
	                AddOptionContract(shortPut, Resolution.Minute);
	                AddOptionContract(shortCall, Resolution.Minute);
	                MarketOrder(longPut, -1);
	                MarketOrder(longCall, -1);
	                MarketOrder(shortPut, -1);
	                MarketOrder(shortCall, -1);
				}
			}
        }

		public bool IsNewBar(TimeSpan interval, int points = 1)
		{
			var date = Securities[iSymbol].LocalTime;

			if ((date - iTime).TotalSeconds > interval.TotalSeconds * points)
			{
				iTime = new DateTime(date.Ticks - date.Ticks % interval.Ticks, date.Kind);
				return true;
			}

			return false;
		}
    }
}