| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return -71.984% Drawdown 2.300% Expectancy 0 Net Profit -1.614% Sharpe Ratio -4.022 Probabilistic Sharpe Ratio 8.884% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.108 Beta 0.913 Annual Standard Deviation 0.159 Annual Variance 0.025 Information Ratio -2.534 Tracking Error 0.023 Treynor Ratio -0.699 Total Fees $1.00 Estimated Strategy Capacity $220000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 19.54% |
from AlgorithmImports import *
import statistics
### <summary>
### Using rolling windows for efficient storage of historical data; which automatically clears after a period of time.
### </summary>
### <meta name="tag" content="using data" />
### <meta name="tag" content="history and warm up" />
### <meta name="tag" content="history" />
### <meta name="tag" content="warm up" />
### <meta name="tag" content="indicators" />
### <meta name="tag" content="rolling windows" />
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(2022,1,1) #Set Start Date
self.SetEndDate(2022,1,5) #Set End Date
self.SetCash(10000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.spy=self.AddEquity("SPY", Resolution.Hour)
# Creates a Rolling Window indicator to keep the 2 TradeBar
self.winSPY = RollingWindow[TradeBar](2)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
# Add SPY TradeBar in rollling window
self.winSPY.Add(data["SPY"])
# Wait for windows to be ready.
if not self.winSPY.IsReady: return
currBarSPY = self.winSPY[0] # Current bar had index zero.
pastBarSPY = self.winSPY[1] # Past bar has index one.
self.Log("SPY Security LocalTime: {} Price:{:.2f} High:{:.2f} Low:{:.2f} Close:{:.2f}".format(self.spy.LocalTime,
self.spy.Price, self.spy.High, self.spy.Low, self.spy.Close))
self.Log("SPY window: {} -> {:.2f} ... {} -> {:.2f}".format(pastBarSPY.Time, pastBarSPY.Close, currBarSPY.Time, currBarSPY.Close))
if not self.Portfolio.Invested:
self.SetHoldings("SPY", 1)