Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
32.587%
Drawdown
38.600%
Expectancy
0
Net Profit
76.066%
Sharpe Ratio
1.207
Probabilistic Sharpe Ratio
53.471%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.312
Beta
-0.116
Annual Standard Deviation
0.248
Annual Variance
0.061
Information Ratio
0.666
Tracking Error
0.29
Treynor Ratio
-2.583
Total Fees
$12.07
import decimal as d
from datetime import timedelta
from Alphas.RsiAlphaModel import RsiAlphaModel

class ParticleCalibratedRadiator(QCAlgorithm):

    
    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(2018, 1, 1)    #Set Start Date
        self.SetEndDate(2019, 12, 31)      #Set End Date
        self.SetCash(100000)             #Set Strategy Cash
        
        self.symbol = 'AAPL'
        self.previous = None
        
        self.AddSecurity(SecurityType.Equity, self.symbol, Resolution.Daily)
        
        
        self.slow = self.SMA(self.symbol, 50, Resolution.Daily)
        self.fast = self.SMA(self.symbol, 30, Resolution.Daily)
        
        #self.rsi = self.RSI(self.symbol, 14)
      
    
        self.atr = self.ATR(self.symbol, 20)
        #elf.window = RollingWindow
        
        self.SetWarmUp(timedelta(days=50))
        
       

    def OnData(self, data):
        
        if not (self.slow.IsReady and self.fast.IsReady):
            return
        
        if not self.atr.IsReady:
            return
        
        if self.previous is not None and self.previous.date() == self.Time.date():
            return
    
        tolerance = 0.00015
    
        holdings = self.Portfolio[self.symbol].Quantity
    
        if holdings <=0:
            
        #finna long 
            if holdings <=0:
                if self.fast.Current.Value > self.slow.Current.Value:
                    if data[self.symbol].Close < (self.slow.Current.Value + self.atr.Current.Value * 0.5):
                        self.Log("Buy >> {0}".format(self.Securities[self.symbol].Price))
                        self.SetHoldings(self.symbol, 1.0)
        #finna short 
            if holdings > 0 and self.fast.Current.Value < self.slow.Current.Value:
                if data[self.symbol].Close < (self.slow.Current.Value + self.atr.Current.Value * 2.0):
                    self.Log("SELL >> {0}".format(self.Securities[self.symbol].Price))
                    self.Liquidate(self.symbol)
            
        
        
        self.previous = self.Time