Back

Problems with Incorporating Reality Modeling and Fee Models into Universes

I am currently having an issue. Fees are destroying my gains, so I decided to learn how to use the reality modeling section in the documentation. I am trying to incorporate the given line:

self.Securities["IBM"].FeeModel = ConstantFeeModel(1.5)

yet with my selection of stocks replacing the "IBM" and the fee being 0. When I try this, my algorithm no longer will work correctly. What variable do I use to replace "IBM"? I have tried many and have had no luck, I guess I don't understand how to transfer this knowledge for one stock into a whole universe. Thank you for any help.

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.


Hey Gage; you can use a SecurityInitializer to configure it for your entire universe.

1

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.


Thanks Jared. I am still having issues incorportating it. Why would this code not work? It says lambda cannot contain assignment. 

self.SetSecurityInitializer(lambda x: self.x.FeeModel = ConstantFeeModel(0))

 

0

In this case, I think you would not use the self. as x is a local variable in the lamba (function). 

You can see here for a full example using a full-function instead of a lamba.

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.


After reading that and working on it I still cannot figure it out. I will just keep trying. If anyone seeing this can offer additional advice much appreciated.

0

A lambda function behaves almost equivalently to:

foo = lambda x: x**2

def foo(x):
return x**2

so as Jared mentioned, you wouldn't want self in there.

Furthermore, the syntax for lambda functions is args:expression, and you can't do assignment ( = ) in an expression. (Note: In Python 3.8+, this is possible with " := " instead but LEAN runs on Py3.6 I believe).

Give this a shot:

def SetCustomFeeModel(x):
x.FeeModel = ConstantFeeModel(0)

# Try this
self.SetSecurityInitializer(SetCustomFeeModel)

# Maybe this
self.SetSecurityInitializer(lambda x: SetCustomFeeModel(x))

If not, then the full example that Jared posted would work.

0

I still cannot figure this out. I have tried returning x, adding self in places, etc. I read all the links here and cannot get it. I have attached my code if anyone else would like to give it a shot.

0

Here:

0


Hi Gage,

To set the fees model to 0 for a universe, we need to utilize the SetSecurityInitializer method.

self.SetSecurityInitializer(lambda x: x.SetFeeModel(CustomFeeModel()))

We define our CustomFeeModel as

class CustomFeeModel:
def GetOrderFee(self, parameters):
return OrderFee(CashAmount(0, 'USD'))

See the attached backtest for reference. Also, consider reviewing our documentation on security initializers.

Best,
Derek Melchin

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