Overall Statistics
Total Orders
4
Average Win
0.17%
Average Loss
0%
Compounding Annual Return
0.491%
Drawdown
0%
Expectancy
0
Start Equity
10000
End Equity
10034.49
Net Profit
0.345%
Sharpe Ratio
0
Sortino Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-2.131
Tracking Error
0.089
Treynor Ratio
0
Total Fees
$5.30
Estimated Strategy Capacity
$13000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
Portfolio Turnover
0.77%
from AlgorithmImports import *

class Model1AlphaModel(AlphaModel):
  def __init__(self, **kwargs):
    self.symbol_1 = kwargs.get("symbol_1", None)
    self.symbol_2 = kwargs.get("symbol_2", None)
    self.symbol_1_weight = kwargs.get("symbol_1_weight", 0.5)
    self.symbol_2_weight = kwargs.get("symbol_2_weight", 0.5)
    self.last_open_insight_time = None
    self.last_close_insight_time = None
    self.last_monday_insight_time = None
    self.last_friday_insight_time = None
    self.model1_insight = False
    self.model2_insight = False
    
  def update(self, algorithm: QCAlgorithm, data: Slice) -> List[Insight]:
        insights = []
        current_time = algorithm.time
        # Market open and close signals for asset1
        if current_time.hour == 9 and current_time.minute == 40 and not self.model1_insight:
            insights.append(Insight.price(self.symbol_1, timedelta(minutes = 20), InsightDirection.UP, weight=self.symbol_1_weight))
            # self.last_open_insight_time = current_time.date()
            self.model1_insight = True
        if algorithm.Portfolio[self.symbol_1].invested:
          if current_time.hour == 15 and current_time.minute >= 30 and self.model1_insight:
              insights.append(Insight.price(self.symbol_1, timedelta(minutes = 20), InsightDirection.DOWN, weight=self.symbol_1_weight))
              # self.last_close_insight_time = current_time.date()
              self.model1_insight = False
        
        # Monday morning and Friday before market close signals for asset2
        if current_time.weekday() == 0 and current_time.hour == 9 and current_time.minute == 40 and not self.model2_insight: #and current_time.hour == 9 and current_time.minute == 40 and not self.model2_insight:
            insights.append(Insight.price(self.symbol_2, timedelta(minutes = 20), InsightDirection.UP, weight=self.symbol_2_weight))
            # self.last_monday_insight_time = current_time.date()
            self.model2_insight = True
        if algorithm.Portfolio[self.symbol_2].invested:
          if current_time.weekday() == 4 and current_time.hour == 15 and current_time.minute >= 30 and self.model2_insight: #and current_time.hour == 15 and current_time.minute == 30 and self.model2_insight:
              insights.append(Insight.price(self.symbol_2, timedelta(minutes = 20), InsightDirection.DOWN, weight=self.symbol_2_weight))
              # self.last_friday_insight_time = current_time.date()
              self.model2_insight = False
        
        return insights
# region imports
from AlgorithmImports import *
from AlphaModel.model1AlphaModel import Model1AlphaModel
# endregion

class Multimodelstrategy(QCAlgorithm):

    def initialize(self):
        self.initialize_config()
        self.set_start_date(2013, 10, 7) 
        self.set_end_date(2014, 6, 20)  
        self.set_cash(self.totalCash)
        
        self.symbol_1 = self.add_equity(self.asset1, Resolution.MINUTE).Symbol
        self.symbol_2 = self.add_equity(self.asset2, Resolution.MINUTE).Symbol
        # symbol_1 : buy at open, liquidate at market close
        # symbol_2 : but at monday, liquidate at end of the week 
        self.symbol_1_share = 0.5
        self.symbol_2_share = 0.5
        self.total_cash_allocated = self.totalCash
        self.symbol_1_total_cash = self.total_cash_allocated * 0.5
        self.symbol_1_initial_cash = self.symbol_1_total_cash
        self.symbol_2_total_cash = self.total_cash_allocated * 0.5
        self.symbol_2_initial_cash = self.symbol_2_total_cash
        kwargs = {
            "symbol_1": self.symbol_1,
            "symbol_2": self.symbol_2,
            "symbol_1_weight": self.symbol_1_share,
            "symbol_2_weight": self.symbol_2_share
        }
        self.add_alpha(Model1AlphaModel(**kwargs))
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
    def initialize_config(self):
        self.asset1 = self.get_parameter("asset1", "AAPL")
        self.asset2 = self.get_parameter("asset2", "SPY")
        self.totalCash = self.get_parameter("TotalCash", 10000)
        

    def on_data(self, data: Slice):
        pass