Overall Statistics |
Total Orders 19 Average Win 0.02% Average Loss -0.03% Compounding Annual Return -0.075% Drawdown 0.100% Expectancy -0.642 Start Equity 10000000 End Equity 9999344 Net Profit -0.007% Sharpe Ratio -0.641 Sortino Ratio -0.767 Probabilistic Sharpe Ratio 35.096% Loss Rate 78% Win Rate 22% Profit-Loss Ratio 0.61 Alpha -0.005 Beta 0.025 Annual Standard Deviation 0.005 Annual Variance 0 Information Ratio -0.464 Tracking Error 0.135 Treynor Ratio -0.121 Total Fees $19.00 Estimated Strategy Capacity $13000.00 Lowest Capacity Asset GOOCV 31K516AN36IVA|GOOCV VP83T1ZUHROL Portfolio Turnover 0.20% |
#region imports using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Drawing; using QuantConnect; using QuantConnect.Algorithm.Framework; using QuantConnect.Algorithm.Framework.Selection; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Algorithm.Framework.Portfolio; using QuantConnect.Algorithm.Framework.Portfolio.SignalExports; using QuantConnect.Algorithm.Framework.Execution; using QuantConnect.Algorithm.Framework.Risk; using QuantConnect.Algorithm.Selection; using QuantConnect.Api; using QuantConnect.Parameters; using QuantConnect.Benchmarks; using QuantConnect.Brokerages; using QuantConnect.Configuration; using QuantConnect.Util; using QuantConnect.Interfaces; using QuantConnect.Algorithm; using QuantConnect.Indicators; using QuantConnect.Data; using QuantConnect.Data.Auxiliary; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Custom; using QuantConnect.Data.Custom.IconicTypes; using QuantConnect.DataSource; using QuantConnect.Data.Fundamental; using QuantConnect.Data.Market; using QuantConnect.Data.Shortable; using QuantConnect.Data.UniverseSelection; using QuantConnect.Notifications; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.OptionExercise; using QuantConnect.Orders.Slippage; using QuantConnect.Orders.TimeInForces; using QuantConnect.Python; using QuantConnect.Scheduling; using QuantConnect.Securities; using QuantConnect.Securities.Equity; using QuantConnect.Securities.Future; using QuantConnect.Securities.Option; using QuantConnect.Securities.Positions; using QuantConnect.Securities.Forex; using QuantConnect.Securities.Crypto; using QuantConnect.Securities.CryptoFuture; using QuantConnect.Securities.Interfaces; using QuantConnect.Securities.Volatility; using QuantConnect.Storage; using QuantConnect.Statistics; using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm; using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm; #endregion namespace QuantConnect { public class USEquityOptionsUniverseAlgorithm : QCAlgorithm { private Symbol _equity, _optionSymbol, _hedge; public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 2, 1); SetCash(10000000); // Asynchronous can use computational resources efficiently UniverseSettings.Asynchronous = true; // Subscribe to the underlying for the underlying position // Set the data normalization mode to raw for strike price comparability _equity = AddEquity("GOOG", dataNormalizationMode: DataNormalizationMode.Raw).Symbol; // Requesting option data and filter for the hedge candidates var option = AddOption(_equity); _optionSymbol = option.Symbol; option.SetFilter(OptionFilter); // Set scheduled event to buy a hedge option contract at market open to eliminate the intra-day movement Schedule.On( DateRules.EveryDay(_equity), TimeRules.AfterMarketOpen(_equity, 1), BuyHedgeContract ); // Set a scheduled event to sell the hedge contract before market close, since we want to earn from inter-day movement // Leave 2 minutes contingency to fill Schedule.On( DateRules.EveryDay(_equity), TimeRules.BeforeMarketClose(_equity, 2), SellHedgeContract ); } private OptionFilterUniverse OptionFilter(OptionFilterUniverse universe) { // Select the contracts with delta very close to -1 and high open interest // This can effectively hedge most of the price change of the underlying and ensure the liquidity // Make sure the contract is expiring at least 30 days later for its tradbility and minimize time decay return universe .IncludeWeeklys() .PutsOnly() .Expiration(2, 7) .Delta(-1m, -0.95m) .OpenInterest(10, 1000); } private void BuyHedgeContract() { if (CurrentSlice.OptionChains.TryGetValue(_optionSymbol, out var chain)) { // Order the underlying if not hold, the order size should match the option contract // Order only if option chain data ready for hedging if (!Portfolio[_equity].Invested) { MarketOrder(_equity, Securities[_optionSymbol].SymbolProperties.ContractMultiplier); } // Get the contract with delta closest to -1 (lowest possible delta) var contract = chain.MinBy(x => x.Greeks.Delta); _hedge = contract.Symbol; // Buy 1 deep ITM put with delta close to -1 to eliminate the intraday movement MarketOrder(_hedge, 1); } } private void SellHedgeContract() { // Check if any hedge contract position, if so, liquidate before market close to expose to underlying overnight movement if (_hedge != null) { Liquidate(_hedge); _hedge = null; } } } }