Overall Statistics
Total Trades
25
Average Win
2.42%
Average Loss
-2.82%
Compounding Annual Return
1.724%
Drawdown
16.200%
Expectancy
0.237
Net Profit
2.629%
Sharpe Ratio
0.177
Probabilistic Sharpe Ratio
13.164%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.86
Alpha
0.022
Beta
0.015
Annual Standard Deviation
0.12
Annual Variance
0.014
Information Ratio
0.391
Tracking Error
0.213
Treynor Ratio
1.408
Total Fees
$26.82
from Alphas.RsiAlphaModel import RsiAlphaModel

class VerticalUncoupledCircuit(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 8, 20)  # Set Start Date
        self.SetCash(8000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity("PFE", Resolution.Daily)
        
        # Indicators section
        #----------------------------------------
        # define a 14-period daily RSI indicator with shortcut helper method
        self.rsi = self.RSI("SPY", 14,  MovingAverageType.Simple, Resolution.Daily)
        
        # Chart section
        #----------------------------------------
        self.SetBenchmark("SPY")
        mainChart = Chart("Equity Curve With Benchmark")
        mainChart.AddSeries(Series("Equity Curve", SeriesType.Line, 0))
        mainChart.AddSeries(Series("Benchmark", SeriesType.Line, 0))
        self.AddChart(mainChart)
        self.scale = None


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments: data: Slice object keyed by symbol containing the stock data
        '''
        
        if self.scale == None:
            self.scale = 8000 / data["SPY"].Price
        
        if not self.Portfolio.Invested:
            self.SetHoldings("PFE", 1)
            #self.SetHoldings("SPY", .5)
        
        self.Plot("Equity Curve With Benchmark", "Equity Curve", self.Portfolio.TotalPortfolioValue)
        self.Plot("Equity Curve With Benchmark", "Benchmark", self.Benchmark.Evaluate(self.Time) * self.scale)
class my_algos:
    def rsi_algo_v1(self):
        self.Debug("hello from rsi_algo_v1 Fn")
#from Alphas.RsiAlphaModel import RsiAlphaModel
from System.Drawing import Color
#import src.algos.my_algos

class VerticalUncoupledCircuit(QCAlgorithm):

    def Initialize(self):
        #self.SetStartDate(2017, 8, 20)  # Set Start Date
        self.SetStartDate(2018, 8, 20)  # Set Start Date
        self.SetCash(8000)  # Set Strategy Cash
        self.my_stock = "PFE"
        
        self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity(self.my_stock, Resolution.Daily)
        
        # Indicators section
        #----------------------------------------
        # define a 14-period daily RSI indicator with shortcut helper method
        self.rsi = self.RSI(self.my_stock, 10,  MovingAverageType.Simple, Resolution.Daily)
        # initialize the indicator with the daily history close price / History Request Warm-Up
        history = self.History([self.my_stock], 10, Resolution.Daily)
        for time, row in history.loc[self.my_stock].iterrows():
            self.rsi.Update(time, row["close"])
        #----------------------------------------
        # define a MACD indicator with shortcut helper method
        self.macd = self.MACD(self.my_stock, 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily)
        
        
        # Chart section
        #----------------------------------------
        self.SetBenchmark(self.my_stock)
        mainChart = Chart("Equity Curve With Benchmark")
        mainChart.AddSeries(Series("Equity Curve", SeriesType.Line, 0))
        mainChart.AddSeries(Series("Benchmark", SeriesType.Line, 0))
        mainChart.AddSeries(Series("macd", SeriesType.Line,"", Color.Red))
        self.AddChart(mainChart)
        self.scale = None


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments: data: Slice object keyed by symbol containing the stock data
        '''
        #if not self.macd.IsReady:
            #self.Debug(dir(data))
            #pe = qb.GetFundamental(["PFE"], "ValuationRatios.PERatio", datetime(2018, 8, 20), datetime.now())
            #self.Debug(pe)
        
        if self.scale == None:
            self.scale = 8000 / data[self.my_stock].Price
        
        # check if this algorithm is still warming up
        if not self.macd.IsReady: return
    
        macd_fast_value = self.macd.Fast.Current.Value
        macd_slow_value = self.macd.Slow.Current.Value
        #self.Debug(hist)
        
        
        #------------------------------------------------------------------------------------
        if self.rsi.IsReady:
            # get the current RSI value
            rsi_value = self.rsi.Current.Value
            #self.Debug(rsi_value)
            # get the current average gain of rsi
            average_gain = self.rsi.AverageGain.Current.Value
            # get the current average loss of rsi
            average_loss = self.rsi.AverageLoss.Current.Value
        
        
        # Below stock buy-sell block moved under above IF block
        # so that buy-sell algo is triggered after Indicator warm-up is complete.
            if not self.Portfolio.Invested:              # If portfolio is not invested
                if rsi_value <= 37:                      # If RSI for stock is low
                    self.SetHoldings(self.my_stock, 1)           # then buy stock
                    #self.SetHoldings("SPY", .5)
                else:
                    pass #unncessary else block
            
            if self.Portfolio.Invested:                  # If portfolio is invested
                if rsi_value >= 60:                      # If RSI for stock is HIGH
                    self.SetHoldings(self.my_stock, 0)           # then buy stock
                    #self.SetHoldings("SPY", .5)
                else:
                    pass #unncessary else block
            
        
        self.Plot("Equity Curve With Benchmark", "Equity Curve", self.Portfolio.TotalPortfolioValue)
        self.Plot("Equity Curve With Benchmark", "Benchmark", self.Benchmark.Evaluate(self.Time) * self.scale)
        #self.Plot("Equity Curve With Benchmark", "MACD Signal", self.macd.Signal)
#from Alphas.RsiAlphaModel import RsiAlphaModel

class VerticalUncoupledCircuit(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 8, 20)  # Set Start Date
        self.SetCash(8000)  # Set Strategy Cash
        self.my_stock = "PFE"
        
        self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity(self.my_stock, Resolution.Daily)
        
        # Indicators section
        #----------------------------------------
        # define a 14-period daily RSI indicator with shortcut helper method
        self.rsi = self.RSI(self.my_stock, 10,  MovingAverageType.Simple, Resolution.Daily)
        # initialize the indicator with the daily history close price / History Request Warm-Up
        history = self.History([self.my_stock], 10, Resolution.Daily)
        for time, row in history.loc[self.my_stock].iterrows():
            self.rsi.Update(time, row["close"])
        
        # Chart section
        #----------------------------------------
        self.SetBenchmark(self.my_stock)
        mainChart = Chart("Equity Curve With Benchmark")
        mainChart.AddSeries(Series("Equity Curve", SeriesType.Line, 0))
        mainChart.AddSeries(Series("Benchmark", SeriesType.Line, 0))
        self.AddChart(mainChart)
        self.scale = None


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments: data: Slice object keyed by symbol containing the stock data
        '''
        
        if self.scale == None:
            self.scale = 8000 / data[self.my_stock].Price
        
        # check if this algorithm is still warming up
        if self.rsi.IsReady:
            # get the current RSI value
            rsi_value = self.rsi.Current.Value
            #self.Debug(rsi_value)
            # get the current average gain of rsi
            average_gain = self.rsi.AverageGain.Current.Value
            # get the current average loss of rsi
            average_loss = self.rsi.AverageLoss.Current.Value
        
        
        # Below stock buy-sell block moved under above IF block
        # so that buy-sell algo is triggered after Indicator warm-up is complete.
            if not self.Portfolio.Invested:              # If portfolio is not invested
                if rsi_value <= 37:                      # If RSI for stock is low
                    self.SetHoldings(self.my_stock, 1)           # then buy stock
                    #self.SetHoldings("SPY", .5)
                else:
                    pass #unncessary else block
            
            if self.Portfolio.Invested:                  # If portfolio is invested
                if rsi_value >= 60:                      # If RSI for stock is HIGH
                    self.SetHoldings(self.my_stock, 0)           # then buy stock
                    #self.SetHoldings("SPY", .5)
                else:
                    pass #unncessary else block    
            
        
        self.Plot("Equity Curve With Benchmark", "Equity Curve", self.Portfolio.TotalPortfolioValue)
        self.Plot("Equity Curve With Benchmark", "Benchmark", self.Benchmark.Evaluate(self.Time) * self.scale)