Overall Statistics
Total Trades
27
Average Win
0%
Average Loss
-2.37%
Compounding Annual Return
-73.917%
Drawdown
30.900%
Expectancy
-1
Net Profit
-20.116%
Sharpe Ratio
-1.114
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.795
Beta
0.238
Annual Standard Deviation
0.763
Annual Variance
0.582
Information Ratio
-0.78
Tracking Error
0.79
Treynor Ratio
-3.579
Total Fees
$20.00
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from datetime import timedelta


class BasicTemplateOptionsAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 1, 1)
        self.SetEndDate(2016, 3, 1)
        self.SetCash(100000)

        option = self.AddOption("GOOG")
        self.option_symbol = option.Symbol

        # set our strike/expiry filter for this option chain
        option.SetFilter(-2, +2, timedelta(0), timedelta(180))

        # use the underlying equity as the benchmark
        self.SetBenchmark("GOOG")

    def OnData(self,slice):
        for i in slice.OptionChains:
            chains = i.Value
            if not self.Portfolio.Invested: 
                self.TradeOptions(chains) 
        
 
    
    def TradeOptions(self,chains):
        # filter the call and put contract
        self.call = [i for i in chains if i.Right == 0]
        self.put = [i for i in chains if i.Right == 1]
        
        for c in self.call:
            self.Buy(c.Symbol,1)
        for p in self.put:
            self.Buy(p.Symbol,1)

        
        
    def OnOrderEvent(self, orderEvent):
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
        if order.Type == OrderType.OptionExercise:
            self.Log("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent))