Overall Statistics
Total Trades
679
Average Win
0.03%
Average Loss
-0.03%
Compounding Annual Return
134.552%
Drawdown
1.000%
Expectancy
0.315
Net Profit
7.509%
Sharpe Ratio
9.043
Probabilistic Sharpe Ratio
99.492%
Loss Rate
29%
Win Rate
71%
Profit-Loss Ratio
0.84
Alpha
0.196
Beta
1.07
Annual Standard Deviation
0.088
Annual Variance
0.008
Information Ratio
5.688
Tracking Error
0.041
Treynor Ratio
0.747
Total Fees
$42852.98
Estimated Strategy Capacity
$85000000.00
Lowest Capacity Asset
KO R735QTJ8XC9X
import numpy as np
import pandas as pd
import math
import time

class StatArb1(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2012, 1, 4)
        self.SetEndDate(2012, 2, 5)
        self.SetCash(20000000)
        
        self.filtered = []
        
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.LiquidWithFundamentalsFilter)
        
        self.spy = self.AddEquity("SPY",Resolution.Daily)
        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                 self.TimeRules.AfterMarketOpen("SPY", 10),        
                 self.RefactorPortfolio)

    
    def LiquidWithFundamentalsFilter(self, coarse):
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
        self.filtered = [ x.Symbol for x in sortedByDollarVolume 
                      if x.Price > 10 and x.DollarVolume > 10000000 and 
                       x.HasFundamentalData][:25]

        return self.filtered


    def RefactorPortfolio(self):
        targets = []
        
        for x in self.Portfolio.Values:
            if x.Invested and x.Symbol not in self.filtered:
                targets.append(PortfolioTarget(x.Symbol, 0.))
                
        for symbol in self.filtered:
            targets.append(PortfolioTarget(symbol, 1/25))
            
        self.SetHoldings(targets)