Overall Statistics
Total Orders
3045
Average Win
0.16%
Average Loss
-0.13%
Compounding Annual Return
71.347%
Drawdown
11.700%
Expectancy
0.199
Start Equity
100000
End Equity
128879.27
Net Profit
28.879%
Sharpe Ratio
2.395
Sortino Ratio
3.006
Probabilistic Sharpe Ratio
82.095%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.19
Alpha
0.118
Beta
1.593
Annual Standard Deviation
0.187
Annual Variance
0.035
Information Ratio
1.944
Tracking Error
0.124
Treynor Ratio
0.282
Total Fees
$2727.46
Estimated Strategy Capacity
$68000000.00
Lowest Capacity Asset
AMCR X58W2VQW0QXX
Portfolio Turnover
99.25%
# region imports
from AlgorithmImports import *
# endregion
class LiquidUniverseSelection(QCAlgorithm):
    
    filtered_by_price = None
    
    def initialize(self):
        self.set_start_date(2019, 1, 11)  
        self.set_end_date(2019, 7, 1) 
        self.set_cash(100000)  
        self.add_universe(self.coarse_selection_filter)
        # Ignore this for now, we'll cover it in the next task.
        self.universe_settings.resolution = Resolution.DAILY 

        # self.SetWarmup(timedelta(days=30))  # Warm up with 30 days of data

    def coarse_selection_filter(self, coarse):
        sorted_by_dollar_volume = sorted(coarse, key=lambda x: x.dollar_volume, reverse=True) 
        filtered_by_price = [x.symbol for x in sorted_by_dollar_volume if x.has_fundamental_data and x.price > 10]
        return filtered_by_price[:8]
   
    def on_securities_changed(self, changes):
        self.changes = changes
        self.log(f"on_securities_changed({self.time}):: {changes}")
        
        #1. Liquidate removed securities
        for security in changes.removed_securities:
            if security.invested:
                self.liquidate(security.symbol)
        
        #2. We want 10% allocation in each security in our universe
        # for security in self.changes.added_securities:
            # self.set_holdings(security.symbol, 0.1)

    def OnData(self, data):

        for symbol in data.keys():
            if not self.Securities[symbol].invested:    # Only invest if we have not yet invested
                self.set_holdings(symbol, 0.1)