Overall Statistics
Total Orders
374
Average Win
3.08%
Average Loss
-1.63%
Compounding Annual Return
95.202%
Drawdown
16.400%
Expectancy
0.370
Start Equity
1000000
End Equity
1950831.41
Net Profit
95.083%
Sharpe Ratio
2.041
Sortino Ratio
2.529
Probabilistic Sharpe Ratio
82.447%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
1.88
Alpha
0.471
Beta
1.015
Annual Standard Deviation
0.295
Annual Variance
0.087
Information Ratio
1.714
Tracking Error
0.276
Treynor Ratio
0.593
Total Fees
$10558.23
Estimated Strategy Capacity
$2500000.00
Lowest Capacity Asset
NFLX SEWJWLJNHZDX
Portfolio Turnover
63.26%
from datetime import timedelta
from AlgorithmImports import *

class Magnificent7IntradayStrategy(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2023, 9, 1)
        self.set_end_date(2024, 9, 1)
        self.set_cash(1000000)
        
        self.symbols = [self.add_equity(ticker, Resolution.MINUTE).symbol for ticker in ["TSLA", "AMZN", "NFLX", "AAPL", "NVDA", "GOOGL", "MSFT", "META", "AVGO", "TSM","WMT"]]
        
        self.rsi_indicators = {symbol: self.rsi(symbol, 14, MovingAverageType.WILDERS, Resolution.MINUTE) for symbol in self.symbols}
        self.sma_indicators = {symbol: self.sma(symbol, 200, Resolution.MINUTE) for symbol in self.symbols}
        
        self.schedule.on(self.date_rules.every_day(), self.time_rules.every(timedelta(minutes=15)), self.trade)
        
        self.set_universe_selection(ManualUniverseSelectionModel(*self.symbols))
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
        
        self.set_execution(ImmediateExecutionModel())

        # Schedule trading hours
        self.schedule.on(self.date_rules.every_day(), self.time_rules.every(timedelta(minutes=15)), self.trade)
        
        # Risk management
        self.set_risk_management(MaximumDrawdownPercentPerSecurity(0.015))
        
        self.last_trade_date = {symbol: None for symbol in self.symbols}
        self.settings.minimum_order_margin_portfolio_percentage = 0

    def trade(self):
        current_time = self.time
        if current_time.weekday() >= 5 or not (current_time.hour == 9 and current_time.minute >= 45):
            return
        for symbol in self.symbols:
            if not self.rsi_indicators[symbol].is_ready or not self.sma_indicators[symbol].is_ready:
                continue
            
            price = self.securities[symbol].price
            rsi_value = self.rsi_indicators[symbol].current.value
            sma_value = self.sma_indicators[symbol].current.value
            
            if self.last_trade_date[symbol] == current_time.date():
                continue
            
            if rsi_value < 30 and price < sma_value:
                self.set_holdings(symbol, 1)
                self.last_trade_date[symbol] = current_time.date()
            
            if self.portfolio[symbol].invested:
                previous_day_high = self.history(symbol, 1, Resolution.DAILY)["high"].iloc[0]
                
                if price >= previous_day_high or rsi_value > 80:
                    self.liquidate(symbol)
                    self.last_trade_date[symbol] = current_time.date()  # Update trade date on exit



# region imports
from AlgorithmImports import *
# endregion

# Your New Python File
class Magnificent7IntradayStrategy(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 1, 1)
        self.set_end_date(2024, 4, 1)
        self.set_cash(1000000)
        self.symbols = [self.add_equity(ticker, Resolution.MINUTE).symbol for ticker in ["TSLA", "AMZN", "NFLX", "AAPL", "NVDA", "GOOGL", "MSFT", "META", "AVGO", "TSM", "WMT"]]
        self.rsi_indicators = {symbol: self.rsi(symbol, 14, MovingAverageType.WILDERS, Resolution.MINUTE) for symbol in self.symbols}
        self.sma_indicators = {symbol: self.sma(symbol, 200, Resolution.MINUTE) for symbol in self.symbols}
        self.schedule.on(self.date_rules.every_day(), self.time_rules.every(timedelta(minutes=15)), self.trade)
        self.set_universe_selection(ManualUniverseSelectionModel(*self.symbols))
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
        self.set_execution(ImmediateExecutionModel())
        self.set_risk_management(MaximumDrawdownPercentPerSecurity(0.015))
        self.last_trade_date = {symbol: self.start_date for symbol in self.symbols}
        self.settings.minimum_order_margin_portfolio_percentage = 0

    def trade(self):
        current_time = self.time
        if current_time.weekday() >= 5 or not (current_time.hour == 9 and current_time.minute >= 45):
            return
        for symbol in self.symbols:
            if not self.rsi_indicators[symbol].is_ready or not self.sma_indicators[symbol].is_ready:
                continue
            price = self.securities[symbol].price
            rsi_value = self.rsi_indicators[symbol].current.value
            sma_value = self.sma_indicators[symbol].current.value
            if self.last_trade_date[symbol] == current_time.date():
                continue
            if rsi_value < 30 and price < sma_value:
                self.set_holdings(symbol, 0.1)  # Allocate 10% of the portfolio to each stock
                self.last_trade_date[symbol] = current_time.date()
            if self.portfolio[symbol].invested:
                previous_day_high = self.history(symbol, 1, Resolution.DAILY)["high"].iloc[0]
                if price >= previous_day_high or rsi_value > 80:
                    self.liquidate(symbol)
                    self.last_trade_date[symbol] = current_time.date()