Overall Statistics Total Trades 23 Average Win 0.10% Average Loss -0.02% Compounding Annual Return 1.136% Drawdown 0.100% Expectancy 1.363 Net Profit 0.319% Sharpe Ratio 2.442 Loss Rate 57% Win Rate 43% Profit-Loss Ratio 4.51 Alpha 0.012 Beta -0.048 Annual Standard Deviation 0.005 Annual Variance 0 Information Ratio -1.846 Tracking Error 0.005 Treynor Ratio -0.237 Total Fees \$23.00
```import numpy as np

### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class Algorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017,1,1)
self.SetEndDate(2017,4,5)
self.SetCash(100000)
self.SetWarmUp(5)
self.UniverseSettings.Resolution = Resolution.Daily
self.Schedule.On(self.DateRules.MonthStart("SPY"),
self.TimeRules.AfterMarketOpen("SPY", 60),
Action(self.Rebalance))

self.changes = None

def OnData(self, data):
pass

def OnSecuritiesChanged(self, changes):
self.Debug("checking")
self.changes = changes

def CoarseSelectionFunction(self, coarse):
CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData]
sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=True)
self.universe = [x.Symbol for x in sortedByDollarVolume[:20]]
return self.universe

def Rebalance(self):
# liquidate securities that fell out of our universe
for security in self.changes.RemovedSecurities:
if security.Invested:
self.Liquidate(security.Symbol)

# invest in securities just added to our universe