Overall Statistics
Total Trades
10
Average Win
0.84%
Average Loss
-1.01%
Compounding Annual Return
-16.138%
Drawdown
0.800%
Expectancy
-0.084
Net Profit
-0.385%
Sharpe Ratio
-3.561
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.83
Alpha
0.01
Beta
0.068
Annual Standard Deviation
0.039
Annual Variance
0.002
Information Ratio
13.738
Tracking Error
0.148
Treynor Ratio
-2.019
Total Fees
$2.50
using QuantConnect.Securities.Option;

namespace QuantConnect
{
    public class StraddleFundamentalAlgorithm : QCAlgorithm
    {
    	private List<Symbol> _symbols = new List<Symbol>();
    	
        public override void Initialize()
        {
            UniverseSettings.Resolution = Resolution.Daily;

            SetStartDate(2016, 01, 01);
            SetEndDate(2016, 01, 09);
            SetCash(10000);

            AddUniverse(CoarseSelectionFunction, FineSelectionFunction);
        }

        public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse) {
            return coarse
                .Where(x => x.HasFundamentalData)
                .OrderByDescending(x => x.DollarVolume)
                .Select(x => x.Symbol).Take(5);
        }

        public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine) {
            return fine
            	.Where(x => 
        
		        	// More than 7 days after earnings report
		        	Time >= x.EarningReports.FileDate.AddDays(-7) && 
	    	    	Time >= x.EarningReports.FileDate.AddDays(0) && 
	        
	        		// Invalid FileDate
	        		x.EarningReports.FileDate != new DateTime())

	        	.Select(x => x.Symbol).Take(3);
        }

        public override void OnData(Slice data) {
            
            foreach (var kvp in data.OptionChains) {
            	var chain = kvp.Value;
            	var symbol = kvp.Key;
            	
            	if (_symbols.Contains(symbol.Underlying)) return;
            	
            	var atmStraddle = chain
                    .OrderBy(x => Math.Abs(chain.Underlying.Price - x.Strike))
                    .ThenByDescending(x => x.Expiry)
                    .FirstOrDefault();

                if (atmStraddle != null)
                {
                	_symbols.Add(symbol.Underlying);
                	Buy(OptionStrategies.Straddle(symbol, atmStraddle.Strike, atmStraddle.Expiry), 1);
                    Debug(string.Format("{0} straddle orders submitted", symbol.Underlying));
                }
            }
		}

        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            foreach (var security in changes.RemovedSecurities)
            {
            	if (security.Invested)
                {
                    Liquidate(security.Symbol);
                    Debug("Sold back: " + security.Symbol);
                }
            	
            }
            
            // Add option for every added security
            foreach (var security in changes.AddedSecurities)
            {
            	if (security is Option) continue;
            	//if (security.Symbol.Equals("SPY")) continue;
            	
                Debug("Bought: " + security.Symbol);
            	var option = AddOption(security.Symbol.Value);
            	option.SetFilter(-2, 2, TimeSpan.FromDays(30), TimeSpan.FromDays(45));
            }
        }
    }
}