Back

IB tiered fee structurs

I needed to emulate IB 's tiered structure of fees in python, where most examples I found were for C#.  Anyways, this works and may help someone else: 

for security in self.stocks:
self.Securities[security].SetSlippageModel(CustomSlippageModel())
self.Securities[security].SetDataNormalizationMode(DataNormalizationMode.Raw)
self.Securities[security].SetFeeModel(CustomFeeModel(self)) #ConstantFeeModel(10.00))

class CustomFeeModel(FeeModel):
def __init__(self, algorithm):
self.algorithm = algorithm

def GetOrderFee(self, parameters):
# custom fee math

# less than 300000 shares
#USD 0.0035 USD 0.35 1.0% of trade value

minfee = max(0.35, parameters.Security.Price * parameters.Order.AbsoluteQuantity * 0.0035 )
maxfee = parameters.Order.AbsoluteQuantity * 0.01
fee = min(minfee,maxfee)

self.algorithm.Log("CustomFeeModel: " + str(fee))
return OrderFee(CashAmount(fee, "USD"))

# Custom slippage implementation
class CustomSlippageModel:
def GetSlippageApproximation(self, asset, order):
try:
return decimal.Decimal(0.0002)
except:
self.Log('An unknown error occurred trying CustomSlippageModel.' + str(sys.exc_info()[0]) )
return 0.0002

Hope this helps someone else. 

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed