Overall Statistics
Total Trades
3
Average Win
3.97%
Average Loss
0%
Compounding Annual Return
29.680%
Drawdown
2.700%
Expectancy
0
Net Profit
4.365%
Sharpe Ratio
2.321
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.023
Beta
0.729
Annual Standard Deviation
0.093
Annual Variance
0.009
Information Ratio
-1.966
Tracking Error
0.057
Treynor Ratio
0.295
Total Fees
$11.27
from System.Collections.Generic import List
from QuantConnect.Data.UniverseSelection import *
import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):

	def Initialize(self):
		self.SetCash(100000)
		self.SetStartDate(2013,1,1)
		self.SetEndDate(2013,3,1)
		self.coarse_number = 2
		self.reb = 1
		self.first_month = 0
		self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
		
		self.UniverseSettings.Resolution = Resolution.Daily
		self.AddUniverse(self.CoarseSelectionFunction)
		
		self.Schedule.On(self.DateRules.MonthStart(self.spy), 
		self.TimeRules.AfterMarketOpen(self.spy,5), Action(self.rebalance))

	
	def CoarseSelectionFunction(self, coarse):
		if self.reb != 1:
			return (List[Symbol]())
		
		self.reb = 0

		sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) 
		top = sortedByDollarVolume[:self.coarse_number]
		
		self.symbols = [x.Symbol for x in top]
		list = List[Symbol]()
		for x in top:
			list.Add(x.Symbol)
		return list
		
	
	def OnData(self, slice):
		pass
	
	def rebalance(self):
		if self.first_month == 0:
			self.first_month += 1
			return
		
		history = self.History(252,Resolution.Daily)
		for i in self.symbols:
			bar = map(lambda x: x[i], history)
			i.prices = [float(x.Close) for x in bar]
			i.mom_20 = i.prices[-1]/i.prices[-20]
			
		self.symbols = [x for x in self.symbols if hasattr(x,'mom_20')]
		
		factor1 = sorted(self.symbols, key = lambda x: x.mom_20, reverse = True)

		self.long = factor1[0]

		self.Liquidate()
		
		self.SetHoldings(self.long,1)

	


		self.reb = 1