Overall Statistics
Total Trades
35
Average Win
7.56%
Average Loss
-3.91%
Compounding Annual Return
9.987%
Drawdown
16.700%
Expectancy
0.899
Net Profit
77.057%
Sharpe Ratio
0.856
Probabilistic Sharpe Ratio
32.421%
Loss Rate
35%
Win Rate
65%
Profit-Loss Ratio
1.93
Alpha
0.015
Beta
0.491
Annual Standard Deviation
0.127
Annual Variance
0.016
Information Ratio
-0.629
Tracking Error
0.13
Treynor Ratio
0.222
Total Fees
$205.18
Estimated Strategy Capacity
$230000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
# EMA Cross Algorithm
# -------------------------------------------------------
STOCK = 'SPY'; MA_F = 15; MA_S = 30; TOLERANCE = 0.00015;
# -------------------------------------------------------
class EMA_CrossAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2009, 1, 1)  
        self.SetEndDate(2015, 1, 1)    
        self.SetCash(100000) 
        
        res = Resolution.Hour
        self.symbol = self.AddEquity(STOCK, res).Symbol 
        self.SetWarmUp(5*MA_S, Resolution.Daily)
        self.ema_fast = self.EMA(self.symbol, MA_F, Resolution.Daily);
        self.ema_slow = self.EMA(self.symbol, MA_S, Resolution.Daily);
        self.Schedule.On(self.DateRules.EveryDay(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol, 31), 
            self.Rebalance)
            
        
    def Rebalance(self):
        if self.IsWarmingUp: return 
        if not self.ema_fast.IsReady: return 
        if not self.ema_slow: return  
    
        self.Plot("EMAS", "ema_fast", self.ema_fast.Current.Value)
        self.Plot("EMAS", "ema_slow", self.ema_slow.Current.Value)

        if not self.Portfolio[self.symbol].IsLong:
            if self.ema_fast.Current.Value > self.ema_slow.Current.Value * (1 + TOLERANCE):
                # self.Log("BUY  >> {0}".format(self.Securities[self.symbol].Price))
                self.SetHoldings(self.symbol, 1.0)
                
        elif self.Portfolio[self.symbol].IsLong:        
            if self.ema_fast.Current.Value < self.ema_slow.Current.Value:
                # self.Log("SELL >> {0}".format(self.Securities[self.symbol].Price))
                self.Liquidate(self.symbol)