Overall Statistics
Total Trades
99
Average Win
0%
Average Loss
0%
Compounding Annual Return
465.270%
Drawdown
83.500%
Expectancy
0
Net Profit
106349.071%
Sharpe Ratio
4.113
Probabilistic Sharpe Ratio
98.573%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
2.114
Beta
1.068
Annual Standard Deviation
0.883
Annual Variance
0.78
Information Ratio
3.243
Tracking Error
0.682
Treynor Ratio
3.401
Total Fees
$0.00
class ModulatedNadionProcessor(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 1, 1)  # Set Start Date
        self.SetCash(10)  # Set Strategy Cash
        self.SetWarmup(52*7)
        
        self.btc = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
        
        self.high = self.MAX("BTCUSD", 52*7) # 52 week high indicator
        
        self.dca_period = 26*7 # DCA for 6 months
        self.dca_interval = 7 # Invest each week
        self.countdown = 0 # Countdown to end of DCA period
        self.investment_amount = 10 # Investment amount
        self.invested_amount = 0 # Keep track of invested amount
        
        self.SetBenchmark(lambda x: self.invested_amount) # Benchmark is invested amount


    def OnData(self, data):
        if self.IsWarmingUp:
            return
        
        if self.invested_amount:
            self.Plot("Active Performance", self.Portfolio.TotalPortfolioValue - self.invested_amount) # Plot active performance
        
        if self.countdown: # Check if in DCA period
            if not self.countdown % self.dca_interval: # Invest each week only
                self.invest()
            self.countdown -= 1
            return # Ignore 52 week highs during DCA period
        
        if data.Bars[self.btc].High == self.high.Current.Value: # Hit 52 week high
            self.countdown = self.dca_period - 1 # Start DCA
            self.invest()
    
    def invest(self):
        self.invested_amount += self.investment_amount
        self.Portfolio.SetCash(self.investment_amount) # Set amount of cash available to be able to buy extra BTC
        self.SetHoldings(self.btc, 1) # Invest wholly in BTC, will leave no cash left over