Overall Statistics
Total Trades
80
Average Win
1038.86%
Average Loss
-5.12%
Compounding Annual Return
230.082%
Drawdown
70.800%
Expectancy
36.082
Net Profit
1708.190%
Sharpe Ratio
2.836
Probabilistic Sharpe Ratio
89.170%
Loss Rate
82%
Win Rate
18%
Profit-Loss Ratio
202.95
Alpha
1.698
Beta
0.032
Annual Standard Deviation
0.616
Annual Variance
0.38
Information Ratio
0.209
Tracking Error
0.907
Treynor Ratio
55.273
Total Fees
$478.08
Estimated Strategy Capacity
$2900000.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Market import TradeBar

class RollingWindowAlgorithm(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(2016,6,1)  #Set Start Date
        self.SetEndDate(2018,11,1)    #Set End Date
        self.SetCash(1000)           #Set Strategy Cash
      
        self.symbol= "BTCUSD"
        self.btc = self.AddCrypto("BTCUSD", Resolution.Daily,Market.GDAX)
        self.btc.SetLeverage(1)
        self.btc_symbol = self.btc.Symbol
        
        self.Settings.FreePortfolioValuePercentage = 0
        
        self.period = 200
        self.sma = self.SMA(self.symbol,self.period )
        
        self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
        #self.SetBrokerageModel(BrokerageName.AlphaStreams)
        
        self.invested = 0
        self.Schedule.On(self.DateRules.MonthStart("BTCUSD"), self.TimeRules.BeforeMarketClose("BTCUSD",0),self.deposit)
        
    def deposit(self):
        self.Portfolio.CashBook["USD"].AddAmount(100)
        self.invested += 100

    def OnData(self, data):
        close = self.Securities[self.symbol].Close
        
        if close > self.sma.Current.Value:
            usd = int(self.Portfolio.CashBook['USD'].Amount)
            quantity = usd * 0.95 / data[self.btc_symbol].Price # Add 5% cash buffer to avoid error 
            quantity = int(quantity * 1000) / 1000.0 #  The minimum order quantity for BTCUSD is 0.001
            if quantity > 0:
                self.MarketOrder(self.btc_symbol, quantity)
            
        else:
            self.Liquidate(self.btc_symbol)
        
        self.Plot("Quantity", "BTC", self.Portfolio.CashBook['BTC'].Amount)