Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-0.076
Tracking Error
0.167
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
#region imports
    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.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect {
    
    // houses all data pertaining to a given symbol
    // this includes Indicators, Variables, etc.
    public class SymbolData {
        public Symbol symbol;
        public Option option;
        public ExponentialMovingAverage ema;
    }

    public class AlgorithmAlpha {

        private readonly QCAlgorithm algorithm;

        public AlgorithmAlpha(QCAlgorithm algorithm) {
            this.algorithm = algorithm;
        }
    }
}
#region imports
    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.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect {
    
    public class AlgorithmExecution {

        private readonly QCAlgorithm algorithm;

        public AlgorithmExecution(QCAlgorithm algorithm) {
            this.algorithm = algorithm;
        }

        public void HandleOrders(Slice data) {
            // perform orders calculations here
            
            // to sell an options contract do as follows:
            /*
            for(i in slice.OptionChains):
                chain = i.Value

            # retireves put contracts based on original filter:
            # note right == 1 means put
            position = [x for x in chain if x.Right == 1]
            
            # sort contracts based on their expiration dates and find the ATM options (underlying-strike) 
            contracts = sorted(sorted(position, key = lambda x: x.Expiry, reverse=True), 
                            key = lambda x: abs(chain.Underlying.Price - x.Strike))

            # if no contracts available then len(contracts) == 0

            # get the desired contract
            contract = contracts[0]

            # sell the contract
            # note this requires using the QCAlgorithm variable
            # not sure how to call it in Python but it'd probably be similar to
            algorithm.Sell(contract, 1)
            */

            // reference: https://www.quantconnect.com/forum/discussion/9225/help-needed-for-selling-put-options/p1
        }

        public void SampleCreditSpread() {
            /*
            # retireves put contracts based on original filter:
            # note right == 1 means put
            position = [x for x in chain if x.Right == 1]
            
            # sort contracts based on their expiration dates and find the ATM options (underlying-strike) 
            contracts = sorted(sorted(position, key = lambda x: x.Expiry, reverse=True), 
                            key = lambda x: x.Strike)

            # retrieve contract 1 with lowest strike
            buy_contract = contract[0]

            # loop through and find your sell contract with desired expiry
            sell_contract = contract[i] # not implemented just example

            # place buy and sell
            algorithm.Buy(buy_contract, 1)
            algorithm.Sell(sell_contract, 1)
            */

            // references:
            // - https://www.schwab.com/learn/story/reducing-risk-with-credit-spread-options-strategy
        }

        public void SampleCallSpread() {
            /*
            NOTE IN C# but can be translated to Python.

            // Return if open position exists
            if (_tickets.Any(x => Portfolio[x.Symbol].Invested)) return;

            // Get the OptionChain
            if (!slice.OptionChains.TryGetValue(<SYMBOL>, out var chain)) return;

            // Get the nearest expiry date of the contracts
            var expiry = chain.Min(x => x.Expiry);
            
            // Select the put Option contracts with the nearest expiry and sort by strike price
            var puts = chain.Where(x => x.Expiry == expiry && x.Right == OptionRight.Put)
                .OrderBy(x => x.Strike).ToArray();
            if (puts.Length < 2) return;

            // Buy the bull put spread
            var bullCallSpread = OptionStrategies.BullPutSpread(<SYMBOL>, puts[^1].Strike, puts[0].Strike, expiry);
            
            // note since you are placing multiple contracts it will return a LIST of OrderTicket objects
            Buy(bullCallSpread, 1);
            */

            // references: 
            // - https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/option-strategies/bull-put-spread
            // - https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/IndexOptionBullPutSpreadAlgorithm.cs
            // - https://github.com/QuantConnect/Lean/blob/master/Common/Securities/Option/OptionStrategies.cs
        }
    }
}
#region imports
    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.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect {
    
    public class AlgorithmPortfolio {
        private readonly QCAlgorithm algorithm;
        
        public AlgorithmPortfolio(QCAlgorithm algorithm) {
            this.algorithm = algorithm;
        }
    }
}
#region imports
    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.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect {
    
    // this class would support all universe changes, 
    // including management of securities.
    public class AlgorithmUniverse {

        private QCAlgorithm algorithm;
        public Dictionary<Symbol, SymbolData> universe;

        public AlgorithmUniverse(QCAlgorithm algorithm) {
            this.algorithm = algorithm;
            this.universe = new Dictionary<Symbol, SymbolData>();
        }

        public IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) {
            // this is where you would do preliminary security selection
            return algorithm.Universe.Unchanged;
        }

        public IEnumerable<Symbol> FineFilterFunction(IEnumerable<FineFundamental> fine) {
            return algorithm.Universe.Unchanged;
        }

        public void Update(SecurityChanges changes) {
            // add/remove symbols from the universe instance variable
            
            // can also add options information here
            // here's an example of doing so:
            // var option = algorithm.AddOption(/*symbol object from added changes*/)
            // option.SetFilter(/*set filter information*/);
            // reference: https://www.quantconnect.com/learning/articles/introduction-to-options/quantconnect-options-api
            SymbolData sd = new SymbolData();
        }
    }
}
#region imports
    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.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion
namespace QuantConnect.Algorithm.CSharp
{
    public class AdaptableBrownMule : QCAlgorithm
    {

        public AlgorithmUniverse universe;
        public AlgorithmPortfolio portfolio;
        public AlgorithmExecution execution;

        public override void Initialize()
        {
            var delta = GetParameter("delta");
            // set classes
            universe = new AlgorithmUniverse(this);
            portfolio = new AlgorithmPortfolio(this);
            execution = new AlgorithmExecution(this); 

            SetStartDate(2022, 4, 13);
            SetCash(100000);
        
        }

        // overrides ondata function and passes it to orders class for handling
        public override void OnData(Slice data)
        {
            execution.HandleOrders(data); 
        }

        // overrides OnSecuritiesChanged function and sends it to the universe function
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            universe.Update(changes);
        }
    }
}