Hello
I get this error message when backtesting the attached option strategy:
During the algorithm initialization, the following exception has occurred: 'BullPutSpreadStrategy' object has no attribute 'UniverseFunc'
QUANTCONNECT COMMUNITY
Hello
I get this error message when backtesting the attached option strategy:
During the algorithm initialization, the following exception has occurred: 'BullPutSpreadStrategy' object has no attribute 'UniverseFunc'
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.
AlMoJo
from AlgorithmImports import *
class BullPutSpreadStrategy(QCAlgorithm):
def Initialize(self) -> None:
self.SetStartDate(2018, 2, 1)
self.SetEndDate(2024, 3, 5)
self.SetCash(30000)
self.longDelta = 0.83
self.shortDelta = 1.15
option = self.AddOption("AAPL", Resolution.Daily)
#equity = self.AddEquity("AAPL", Resolution.Daily)
self.symbol = option.Symbol
option.SetFilter(self.UniverseFunc)
return universe.IncludeWeeklys().Strikes(-40, 40).Expiration(timedelta(120), timedelta(120))
Can anybody help please?
Mia Alissi
The error message you're seeing suggests that the 'BullPutSpreadStrategy' object does not have an attribute 'UniverseFunc'. This is likely because the 'UniverseFunc' method is not defined in your 'BullPutSpreadStrategy' class.
In the context of QuantConnect's LEAN engine, 'UniverseFunc' is a method that defines the universe of assets that the algorithm should consider for trading. This method is typically used in conjunction with the 'SetFilter' method of the Option object to specify the option contracts that the algorithm should consider.
Here is an example of how 'UniverseFunc' might be defined in Python:
In this example, 'UniverseFunc' is a method that takes an 'OptionFilterUniverse' object as input and returns an 'OptionFilterUniverse' object. The method uses the 'IncludeWeeklys', 'Strikes', and 'Expiration' methods of the 'OptionFilterUniverse' object to specify the option contracts that the algorithm should consider.
You should ensure that a similar method is defined in your 'BullPutSpreadStrategy' class and is correctly linked to your Option object.
Source: QuantConnect Documentation
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.
Mia Alissi
The error in your code is due to the incorrect indentation and placement of the
UniverseFunc
method. In Python, the method should be defined within the class and properly indented. Here is the corrected code:In this corrected code, the
UniverseFunc
method is defined within theBullPutSpreadStrategy
class and is properly indented. This method is then passed to theSetFilter
method of the Option object to specify the option contracts that the algorithm should consider.Source: QuantConnect Documentation
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.
AlMoJo
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!