Overall Statistics
Total Trades
63
Average Win
0.11%
Average Loss
-0.05%
Compounding Annual Return
21.133%
Drawdown
0.400%
Expectancy
0.507
Net Profit
1.624%
Sharpe Ratio
5.308
Probabilistic Sharpe Ratio
88.932%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
2.11
Alpha
0.142
Beta
0.115
Annual Standard Deviation
0.038
Annual Variance
0.001
Information Ratio
-2.863
Tracking Error
0.116
Treynor Ratio
1.765
Total Fees
$206.03
class OptimizedCalibratedFlange(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2013,10,1)   # Set Start Date
        self.SetEndDate(2013,10,31)    # Set End Date
        self.security = self.AddEquity("SPY", Resolution.Hour)
        self.spy = self.security.Symbol

        self.SetSecurityInitializer(self.CustomSecurityInitializer)

    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):
        '''Initialize the security with raw prices'''
        security.SetSlippageModel(CustomSlippageModel(self))
        
class CustomSlippageModel:
    def __init__(self, algorithm):
        self.algorithm = algorithm
        
    def GetSlippageApproximation(self, asset, order):
        # custom slippage math
        slippage = asset.Price * d.Decimal(0.0001 * np.log10(2*float(order.AbsoluteQuantity)))
        self.algorithm.Log("CustomSlippageModel: " + str(slippage))
        return slippage