| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return -95.414% Drawdown 10.500% Expectancy 0 Net Profit -8.098% Sharpe Ratio -8.611 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -3.068 Beta -0.606 Annual Standard Deviation 0.269 Annual Variance 0.073 Information Ratio -2.599 Tracking Error 0.418 Treynor Ratio 3.828 Total Fees $2.50 |
class BootCampTask(QCAlgorithm):
# Order ticket for our stop order, Datetime when stop order was last hit
stopMarketTicket = None
stopMarketOrderFillTime = datetime.min
highestSPYPrice = 0
def Initialize(self):
self.SetStartDate(2018, 12, 1)
self.SetEndDate(2018, 12, 10)
self.SetCash(100000)
spy = self.AddEquity("SPY", Resolution.Minute)
spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
def OnData(self, data):
self.Debug(f'Minute Bar High: {self.Securities["SPY"].High}')
if (self.Time - self.stopMarketOrderFillTime).seconds/60 < 15:
return
if not self.Portfolio.Invested:
self.MarketOrder("SPY", 500)
self.stopMarketTicket = self.StopMarketOrder("SPY", -500, 0.9 * self.Securities["SPY"].High)
else:
#1. Check if the SPY price is higher that highestSPYPrice.
if self.Securities["SPY"].High > self.highestSPYPrice:
#2. Save the new high to highestSPYPrice; then update the stop price to 90% of highestSPYPrice
self.highestSPYPrice = self.Securities["SPY"].High
updateFields = UpdateOrderFields()
updateFields.StopPrice = self.highestSPYPrice * 0.9
self.stopMarketTicket.Update(updateFields)
#3. Print the new stop price with Debug()
self.Debug("SPY: " + str(self.highestSPYPrice) + " Stop: " + str(updateFields.StopPrice))
def OnOrderEvent(self, orderEvent):
if orderEvent.Status != OrderStatus.Filled:
return
if self.stopMarketTicket is not None and self.stopMarketTicket.OrderId == orderEvent.OrderId:
self.stopMarketOrderFillTime = self.Time