| Overall Statistics |
|
Total Orders 6 Average Win 0.59% Average Loss -2.87% Compounding Annual Return -24.373% Drawdown 6.900% Expectancy -0.397 Start Equity 100000 End Equity 95463 Net Profit -4.537% Sharpe Ratio -2.13 Sortino Ratio -1.796 Probabilistic Sharpe Ratio 5.538% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 0.21 Alpha -0.196 Beta 0.051 Annual Standard Deviation 0.083 Annual Variance 0.007 Information Ratio -2.758 Tracking Error 0.197 Treynor Ratio -3.48 Total Fees $4.00 Estimated Strategy Capacity $6000.00 Lowest Capacity Asset GOOCV XG8PSNPNECFA|GOOCV VP83T1ZUHROL Portfolio Turnover 10.07% |
from AlgorithmImports import *
from QuantConnect.DataSource import *
class USEquityOptionsDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2020, 6, 1)
self.set_end_date(2020, 8, 1)
self.set_cash(100000)
self.universe_settings.asynchronous = True
# Requesting data
self.underlying = self.add_equity("GOOG").symbol
option = self.add_option("GOOG")
self.option_symbol = option.symbol
# Set our strike/expiry filter for this option chain
option.set_filter(-2, +2, 0, 7)
self.contract = None
def on_data(self, slice: Slice) -> None:
if self.portfolio[self.underlying].invested:
self.liquidate(self.underlying)
if self.contract is not None and self.portfolio[self.contract.symbol].invested:
return
chain = slice.option_chains.get(self.option_symbol)
if chain:
# Select call contracts
calls = [contract for contract in chain if contract.right == OptionRight.CALL]
if len(calls) == 0:
return
# Select the call contracts with the furthest expiration
furthest_expiry = sorted(calls, key = lambda x: x.expiry, reverse=True)[0].expiry
furthest_expiry_calls = [contract for contract in calls if contract.expiry == furthest_expiry]
# From the remaining contracts, select the one with its strike closest to the underlying price
self.contract = sorted(furthest_expiry_calls, key = lambda x: abs(chain.underlying.price - x.strike))[0]
self.market_order(self.contract.symbol, 1)
def on_securities_changed(self, changes: SecurityChanges) -> None:
for security in changes.added_securities:
# Historical data
history = self.history(security.symbol, 10, Resolution.MINUTE)
self.debug(f"We got {len(history)} from our history request for {security.symbol}")