Overall Statistics
Total Trades
480
Average Win
1.37%
Average Loss
-1.00%
Compounding Annual Return
7.986%
Drawdown
9.300%
Expectancy
0.395
Net Profit
149.256%
Sharpe Ratio
0.821
Loss Rate
41%
Win Rate
59%
Profit-Loss Ratio
1.37
Alpha
0.07
Beta
-0.053
Annual Standard Deviation
0.081
Annual Variance
0.007
Information Ratio
-0.047
Tracking Error
0.202
Treynor Ratio
-1.264
Total Fees
$3207.30
import numpy as np
import decimal as d
from decimal import Decimal

### <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(2007,10, 7)  #Set Start Date
        self.SetEndDate(2019,8,25)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash
        # Find more symbols here: http://quantconnect.com/data
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("TLT", Resolution.Minute)
        #self.Debug("numpy test >>> print numpy.pi: " + str(np.pi))
        
        #Buy Monday afternoon
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.At(14, 56), self.MondayBuy)
        
        #Sell on Tuesday afternoon
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Wednesday), self.TimeRules.At(10, 32), self.TuesdaySell)
        
        self.SPY7 = self.EMA("SPY", 7, Resolution.Daily);
        
        bars = self.History(["SPY"], 220, Resolution.Daily)
        if not bars.empty:
            for index, row in bars.loc["SPY"].iterrows():
                close = row["close"]
                self.SPY7.Update(index, close)
                
    def MondayBuy(self):
        
        #if not self.Portfolio.Invested:
        #if not self.Securities["SPY"].Price < self.SPY7.Current.Value * d.Decimal(0.996):
            #self.SetHoldings("SPY", 1)
        
        if self.Securities["SPY"].Price < self.SPY7.Current.Value: #* d.Decimal(0.996):
            self.SetHoldings("SPY", 1)
            
    def TuesdaySell(self):
        
        #if self.Securities["SPY"].Price > self.SPY7.Current.Value:
        self.Liquidate("SPY")
            
        #if self.Portfolio.Invested:
        #self.Liquidate("SPY")
        #self.SetHoldings("TLT", 1)
        #self.SetHoldings("SPY", -0.2)
        
    #end