| Overall Statistics |
|
Total Trades 4936 Average Win 0.08% Average Loss -0.07% Compounding Annual Return 13.320% Drawdown 20.200% Expectancy 0.028 Net Profit 13.320% Sharpe Ratio 0.532 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 1.08 Alpha 0.877 Beta -43.338 Annual Standard Deviation 0.267 Annual Variance 0.071 Information Ratio 0.468 Tracking Error 0.267 Treynor Ratio -0.003 Total Fees $5403.92 |
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 BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2016,1,01) #Set Start Date
self.SetEndDate(2017,1,01) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction)
self._changes = SecurityChanges.None
self.CoarseSymbols = 200
self.FineSymbols1 = 150
self.FineSymbols2 = 100
self.FineSymbols3 = 50
self.FineSymbols4 = 20
def CoarseSelectionFunction(self,coarse):
sortedbyDollarVolume = sorted(coarse, key = lambda x: x.DollarVolume, reverse = True)
return[x.Symbol for x in sortedbyDollarVolume[:self.CoarseSymbols]]
def FineSelectionFunction(self,fine):
sortedbyMetric1 = sorted(fine, key = lambda x: x.OperationRatios.ROIC.OneYear, reverse = False)
sortedbyMetric2 = sorted(sortedbyMetric1[:self.FineSymbols1], key = lambda x: x.ValuationRatios.EVToEBITDA, reverse = True)
sortedbyMetric3 = sorted(sortedbyMetric2[:self.FineSymbols2], key = lambda x: x.ValuationRatios.BookValuePerShare, reverse = False)
sortedbyMetric4 = sorted(sortedbyMetric3[:self.FineSymbols3], key = lambda x: x.OperationRatios.ROE.OneYear, reverse = False)
return[x.Symbol for x in sortedbyMetric4[:self.FineSymbols4]]
def OnData(self, data):
if self._changes == SecurityChanges.None: return
# liquidate removed securities
for security in self._changes.RemovedSecurities:
if security.Invested:
self.Liquidate(security.Symbol)
# we want equal allocation in each security in our universe
# 1 / 20 = 0.05 so use 0.045 to prevent insufficient funds
for security in self._changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.045)
self._changes = SecurityChanges.None;
# this event fires whenever we have changes to our universe
def OnSecuritiesChanged(self, changes):
self._changes = changes