Overall Statistics |
Total Trades 63 Average Win 0.11% Average Loss -0.05% Compounding Annual Return 23.181% Drawdown 0.400% Expectancy 0.627 Net Profit 1.767% Sharpe Ratio 5.853 Probabilistic Sharpe Ratio 91.637% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 2.25 Alpha 0.162 Beta 0.114 Annual Standard Deviation 0.038 Annual Variance 0.001 Information Ratio -2.694 Tracking Error 0.116 Treynor Ratio 1.95 Total Fees $63.81 |
import decimal as d import numpy as np class OptimizedCalibratedFlange(QCAlgorithm): def Initialize(self): self.SetStartDate(2013,10,1) # Set Start Date self.SetEndDate(2013,10,31) # Set End Date self.SetSecurityInitializer(self.CustomSecurityInitializer) self.security = self.AddEquity("SPY", Resolution.Hour) self.spy = self.security.Symbol def OnData(self, data): open_orders = self.Transactions.GetOpenOrders(self.spy) if len(open_orders) != 0: return if self.Time.day > 10 and self.security.Holdings.Quantity <= 0: quantity = self.CalculateOrderQuantity(self.spy, .5) self.Log("MarketOrder: " + str(quantity)) self.MarketOrder(self.spy, quantity, True) # async needed for partial fill market orders elif self.Time.day > 20 and self.security.Holdings.Quantity >= 0: quantity = self.CalculateOrderQuantity(self.spy, -.5) self.Log("MarketOrder: " + str(quantity)) self.MarketOrder(self.spy, quantity, True) # async needed for partial fill market orders def CustomSecurityInitializer(self, security): self.Debug("CustomSecurityInitializer called") '''Initialize the security with raw prices''' security.SetSlippageModel(CustomSlippageModel(self)) security.SetFeeModel(CustomFeeModel(self)) class CustomFeeModel: def __init__(self, algorithm): self.algorithm = algorithm def GetOrderFee(self, security, order): self.algorithm.Debug("GetOrderFee called") fee = max(1, security.Price * order.AbsoluteQuantity * d.Decimal(0.00001)) self.algorithm.Log("CustomFeeModel: " + str(fee)) return fee class CustomSlippageModel: def __init__(self, algorithm): self.algorithm = algorithm def GetSlippageApproximation(self, asset, order): slippage = asset.Price * d.Decimal(0.0001 * np.log10(2*float(order.AbsoluteQuantity))) self.algorithm.Log("CustomSlippageModel: " + str(slippage)) # return slippage return 0