Overall Statistics
Total Trades
6
Average Win
2.05%
Average Loss
-0.13%
Compounding Annual Return
2374.021%
Drawdown
0.500%
Expectancy
4.442
Net Profit
1.774%
Sharpe Ratio
-9.703
Probabilistic Sharpe Ratio
0%
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
15.32
Alpha
0.021
Beta
2.151
Annual Standard Deviation
0.027
Annual Variance
0.001
Information Ratio
-9.028
Tracking Error
0.014
Treynor Ratio
-0.121
Total Fees
$51.66
import datetime


class MyCoarseUniverseAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 11, 4)  # Set Start Date
        self.SetEndDate(2019, 11, 5)  # Set Start Date
        
        self.SetCash(100000)  # Set Strategy Cash
        self.AddUniverse(self.PaulCoarseFilterFunction)
        
        self._asset_per_day = {
            datetime.date(2019, 11, 4): ['AAPL', 'GE'],
            datetime.date(2019, 11, 5): ['AMZN', ],
        }
        
        self._spy = self.AddEquity('SPY', Resolution.Minute)

        self.Schedule.On(
            self.DateRules.EveryDay(self._spy.Symbol),
            self.TimeRules.AfterMarketOpen(self._spy.Symbol, 1),
            Action(self._before_market_open_),
        )
        
        self.Schedule.On(
            self.DateRules.EveryDay(self._spy.Symbol),
            self.TimeRules.BeforeMarketClose(self._spy.Symbol, 1),
            Action(self._before_market_close),
        )

        self._daily_assets =  []


    def PaulCoarseFilterFunction(self, coarse):
        try:
            today_asset_list = self._asset_per_day[self.Time.date()]
        except:
            today_asset_list = []
            
        filtered = [
            item.Symbol
            for item in coarse
            if item.Symbol.Value.upper().strip() in today_asset_list
        ]
        self._daily_assets = filtered.copy()
        
        return filtered


    def OnData(self, data):
        pass
        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)
        
    
    def _before_market_open_(self):
        pct_invest = 1 / len(self._daily_assets)
        
        for asset in self._daily_assets:
            self.SetHoldings(asset, pct_invest)

    def _before_market_close(self):
        for asset in self.ActiveSecurities:
            current_symbol = asset.Value.Symbol
            current_quantity = self.Portfolio[asset.Value.Symbol].Quantity
            
            if current_quantity:
                self.MarketOrder(current_symbol, -1 * current_quantity)