Overall Statistics Total Trades1Average Win0%Average Loss0%Compounding Annual Return-0.510%Drawdown0.000%Expectancy0Net Profit-0.007%Sharpe Ratio-11.562Loss Rate0%Win Rate0%Profit-Loss Ratio0Alpha-0.004Beta0Annual Standard Deviation0Annual Variance0Information Ratio-25.249Tracking Error0.001Treynor Ratio-100.368Total Fees\$1.00
```import numpy as np
import pandas as pd
from datetime import datetime, timedelta
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *

class BasicTemplateAlgorithm(QCAlgorithm):
'''High beta strategy'''

def Initialize(self):

'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialize.'''

#Initial investment and backtest period
self.SetStartDate(2019,2,25)    #Set Start Date
self.SetEndDate(2019,2,27)       #Set End Date
self.SetCash(10000)          #Set Strategy Cash

#Capture initial investment for risk off purposes
self.ClosingPortValue = self.Portfolio.TotalPortfolioValue
self.CurrentPortValue = self.Portfolio.TotalPortfolioValue
self.CurrentHoldValue = self.Portfolio.TotalHoldingsValue

#Universe

'''Schedule Function Here'''
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Every(TimeSpan.FromMinutes(6)), self.UpdatePortValues)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Every(TimeSpan.FromMinutes(7)), self.CheckDailyLosses)

'''Set Warmup Here'''

self.SetWarmup(TimeSpan.FromDays(30))

#OnData
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'''

#Verify all indicators have warmed up before anything happens
if self.IsWarmingUp: return

self.SetHoldings("SPY", 0.10)

#Update Portfolio Values
def UpdatePortValues(self):

self.marginRemaining = self.Portfolio.MarginRemaining
self.CurrentPortValue = self.Portfolio.TotalPortfolioValue
self.CurrentHoldValue = self.Portfolio.TotalHoldingsValue

self.Log("Portfolio Values Have Been Updated")

#CheckLosses
#Check intraday losses and run defensive function if a 5.6% drop is recognized
def CheckDailyLosses(self):

self.CurrentPerformance = round( ((float(self.CurrentPortValue)/float(self.ClosingPortValue))-1)*100,2)

if (self.CurrentPortValue <= self.ClosingPortValue*0.944):
if(self.IsMarketOpen("SPY")):
self.HighLosses()

else: self.Log("Current Performance: {0}%".format(self.CurrentPerformance))

return```