Overall Statistics |
Total Trades 27 Average Win 0% Average Loss 0% Compounding Annual Return -98.259% Drawdown 3.500% Expectancy 0 Net Profit -3.274% Sharpe Ratio -16.489 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.703 Beta 1.109 Annual Standard Deviation 0.126 Annual Variance 0.016 Information Ratio -12.626 Tracking Error 0.066 Treynor Ratio -1.878 Total Fees $54.00 |
from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from datetime import tzinfo, datetime, timedelta from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Orders import * from QuantConnect.Data import * import decimal as d class OrderTicketDemoAlgorithm(QCAlgorithm): '''In this algorithm we submit/update/cancel each order type''' 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.SetEndDate(datetime.now().date() - timedelta(1)) self.SetStartDate(2013,10,07) #Set Start Date self.SetEndDate(2013,10,9) #Set End Date self.SetCash(10000) #Set Strategy Cash self.SetBenchmark("EURUSD") self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage,AccountType.Margin) # Find more symbols here: http://quantconnect.com/data asset = self.AddForex("EURUSD",Resolution.Hour) self.EURUSD = asset.Symbol self.newTicket = None self.Log("initialized Complete") def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.''' # Creating an Order: if not self.Portfolio.Invested: self.Log("Submitting StopLimitOrder") close = self.Securities[self.EURUSD.Value].Close StopLong=close + d.Decimal(0.003) LimitLong=StopLong+d.Decimal(0.0001) # How do we add a take profit of say Decimal(0.0004)? self.newTicket = self.StopLimitOrder(self.EURUSD, 1000, StopLong, LimitLong) time_order=self.newTicket.Time EXPIRY=time_order+timedelta(hours=2) self.Log("Order: {0}. time order: {1}. EXPIRY: {2}".format(self.newTicket,time_order,EXPIRY)) # Alex: adds this else because EXPIRY must be defined for later use else: self.Log("ELSE -timedelta(1){0}.".format(timedelta(1))) EXPIRY=self.UtcTime-timedelta(1) # Alex's suggested Hack - seems this could create bugs? self.Log("self.UtcTime:{0}.".format(self.UtcTime)) self.Log("EXPIRY:{0}.".format(EXPIRY)) self.Log("self.newTicket :: {0}.".format(self.newTicket)) if self.newTicket!=None: #ALEX 's Suggestion - Not sure how it contributes to our objective - if anyone could clarify? if self.UtcTime >= EXPIRY: self.newTicket.Cancel() self.Log("Order Expired: self.Time >= EXPIRY") self.newTicket=None def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) self.Log("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent)) def TimeIs(self, day, hour, minute): return self.Time.day == day and self.Time.hour == hour and self.Time.minute == minute