Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return -0.510% Drawdown 0.000% Expectancy 0 Net Profit -0.007% Sharpe Ratio -11.562 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.004 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -25.249 Tracking Error 0.001 Treynor Ratio -100.368 Total 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 * from QuantConnect.Data.Market import TradeBar 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 self.AddEquity("SPY", Resolution.Daily) '''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