Overall Statistics
Total Orders
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
3.844%
Drawdown
0.500%
Expectancy
0
Start Equity
1000000
End Equity
1002138
Net Profit
0.214%
Sharpe Ratio
0.199
Sortino Ratio
0.216
Probabilistic Sharpe Ratio
59.672%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.005
Beta
0.129
Annual Standard Deviation
0.013
Annual Variance
0
Information Ratio
-0.747
Tracking Error
0.078
Treynor Ratio
0.02
Total Fees
$2.00
Estimated Strategy Capacity
$87000.00
Lowest Capacity Asset
GOOCV XC7Z2Q3F70KM|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.68%
# region imports
from AlgorithmImports import *
# endregion

class Magnificent7(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2020, 1, 10)
        self.set_end_date(2020, 1, 30) # Set End Date

        self.set_cash(1000000)
        self.underlying_tickers = ['GOOG', 'AAPL', 'NVDA', 'AMZN', 'MSFT','TSLA','META']
        self.option_symbols = {} # Dictionary to store symbols
        self.sma_dict = {} # Dictionary to store the SMA for each symbol
        # self.vwap_dict = {} # Dictionary to store VWAP
        self.SetBenchmark("SPY")
        self.sma_window = 100
        # self.vwap_window = 100
        
        for ticker in self.underlying_tickers:
            # Add equity to universe
            equity = self.add_equity(ticker)
            # Add equity option contracts to universe and create list
            option = self.add_option(ticker)
            # Filters the option chain so that only 
            # strikes that are +$100 above current underlying price and
            # strikes $0 below current underlying price option and 
            # within 10 to 45 days to expiration (DTE) of current date
            # are available. (Speeds up code!)
            option.set_filter(0, 100, timedelta(10), timedelta(45))
            self.option_symbols[ticker] = option.symbol
            # Add SMA indicator to dictionary based on ticker symbol
            self.sma_dict[ticker] = self.sma(equity.Symbol, self.sma_window)
            # self.vma_dict[ticker] = self.vwap(equity.Symbol, self.vwap_window)    
            
    def on_data(self, slice: Slice) -> None:
      for ticker in self.underlying_tickers:
            bar = slice.bars.get(ticker)
            if bar:
                if not self.portfolio.invested and bar.Close < self.sma_dict[ticker].Current.Value:                    
                    chain = slice.option_chains.get(self.option_symbols[ticker])
                    if chain is None: return
                    # we sort the contracts to identify call options
                    call = [x for x in chain if x.Right == OptionRight.Call]
                    # we sort the contracts by closest expiration
                    contracts = sorted(call, key = lambda x: x.expiry, reverse=False)
                    # we sort the contracts based on given delta
                    delta_contracts = sorted(contracts, key = lambda x: abs(x.Greeks.Delta - 0.25))
                    # if found, trade it
                    if len(delta_contracts) == 0: return
                    self.market_order(ticker, 100)
                    self.market_order(delta_contracts[0].symbol,-1)


# region imports
from AlgorithmImports import *
# endregion

class Magnificent7(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2020, 11, 10)
        # self.set_end_date(2024, 4, 1) # Set End Date

        self.set_cash(100000)
        self.underlying_tickers = ['GOOG', 'AAPL', 'NVDA', 'AMZN', 'MSFT','TSLA','META']
        self.sma_dict = {} # Dictionary to store the SMA for each symbol
        self.SetBenchmark("SPY")
        self.sma_window = 100

        for ticker in self.underlying_tickers:
            equity = self.add_equity(ticker)
            # Add SMA indicator to dictionary based on ticker symbol
            self.sma_dict[ticker] = self.sma(equity.Symbol, self.sma_window)

    def on_data(self, slice: Slice):
      for ticker in self.underlying_tickers:
            bar = slice.bars.get(ticker)
            if bar:
                if not self.portfolio.invested and bar.Close < self.sma_dict[ticker].Current.Value:
                    self.set_holdings(ticker, 1/len(self.underlying_tickers))
                elif self.portfolio.invested and bar.Close > 1.1*self.sma_dict[ticker].Current.Value:
                    self.set_holdings(ticker, 0)