Overall Statistics
Total Trades
9688
Average Win
0.09%
Average Loss
-0.04%
Compounding Annual Return
-0.884%
Drawdown
45.300%
Expectancy
0.004
Net Profit
-8.308%
Sharpe Ratio
-0.008
Loss Rate
66%
Win Rate
34%
Profit-Loss Ratio
2.00
Alpha
-0.009
Beta
0.148
Annual Standard Deviation
0.113
Annual Variance
0.013
Information Ratio
-0.299
Tracking Error
0.192
Treynor Ratio
-0.006
Total Fees
$18653.36
from clr import AddReference
AddReference("System.Core")
AddReference("System.Collections")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Algorithm")
import statistics
from datetime import datetime
from System.Collections.Generic import List

class ShortTimeReversal(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2006, 1, 1)
        self.SetEndDate(2016, 12, 31)
        self.SetCash(1000000)

        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseSelectionFunction)
        self._numberOfSymbols = 100
        self._numberOfTradings = 10

        self._LastMonth = -1
        self._LastDay = -1
        self._stocks = []
        self._values = {}

    def CoarseSelectionFunction(self, coarse):
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
        top100 = sortedByDollarVolume[:self._numberOfSymbols]
        list = List[Symbol]()
        for x in top100:
            list.Add(x.Symbol)
            #self.Log("This is symbol: {0}".format(x.Symbol))
        return list

    def OnData(self, data):
		if not self._values:
			self._stocks = []
			self.uni_symbol = None
			symbols = self.UniverseManager.Keys
			for i in symbols:
				if str(i.Value) == "QC-UNIVERSE-COARSE-USA":
					self.uni_symbol = i
			for i in self.UniverseManager[self.uni_symbol].Members:
				self._stocks.append(i.Value.Symbol)
				#self.Log("This is sym: {0}".format(i.Value.Symbol))
				self._values[i.Value.Symbol] = self.Securities[i.Value.Symbol].Price
			self._LastDay = self.Time.date()
			self._LastMonth = self.Time.month
		else:
			if self.Time.month != self._LastMonth:
				self._LastMonth = self.Time.month
					
				returns = {}
				for stock in self._stocks:
					newPrice = self.Securities[stock].Price
					returns[stock] = newPrice/self._values[stock]

				newArr = [(v,k) for k,v in returns.items()]
				newArr.sort()
				for ret, stock in newArr[self._numberOfTradings:-self._numberOfTradings]:
					self.SetHoldings(stock, 0)
				for ret, stock in newArr[0:self._numberOfTradings]:
					self.SetHoldings(stock, 0.5/self._numberOfTradings)
				for ret, stock in newArr[-self._numberOfTradings:]:
					self.SetHoldings(stock, -0.5/self._numberOfTradings)
				self._LastDay = self.Time.date()
				return
			delta = self.Time.date() - self._LastDay
			if delta.days >= 7:
				for stock in self._stocks:
					if self.Portfolio[stock].IsLong:
						self.SetHoldings(stock, 0.5/self._numberOfTradings)
					if self.Portfolio[stock].IsShort:
						self.SetHoldings(stock, -0.5/self._numberOfTradings)
				self._LastDay = self.Time.date()