Back

'ForexHolding' object has no attribute 'TotalMargin'

       I'm working on building a python class structure that makes it easier to swap out strategies and risk models while using multi-timeFrames techniques. I've been off in my own code world for a few months, and I came back and went to run it and hit an Attribute error I'm unfamiliar with. 

During the algorithm initialization, the following exception has occurred: AttributeError : 'ForexHolding' object has no attribute 'TotalMargin'
at Initialize in main.py:line 39
at __init__ in SymbolBox.py:line 37
at __init__ in TradeManagment.py:line 13
:: self.TotalMargin = self.symbol.TotalMargin /5
AttributeError : 'ForexHolding' object has no attribute 'TotalMargin'

 

I found these two links, but I'm still having a hard time seeing which classes I should be indexing through/ what part of the API I'm incorrectly calling. 

https://www.quantconnect.com/lean/documentation/topic27440.html

https://www.quantconnect.com/lean/documentation/topic26941.html

It centers around the QC portfolio. The code below is going to be slightly broken up, I'm including the code in each class that produces the error. It's during __init__ so the rest of the code seems unecessary. 

    class Main

        self.symbols = ['EURUSD','NZDUSD']

        for i in self.symbols:

            sym = self.AddSecurity(SecurityType.Forex, i, Resolution.Hour,leverage= 100).Symbol
            self.allTicks[sym] = SymbolBox(i, sym, self.timeFrames, self)

 

    class SymbolBox

        def __init__(self, symbol,sym, timeFrames, QCAlgorithm):

            '''
            inits all variables and classes needed by each symbol to trade.
            Handles all day for each Symbol inside its' respecive class.
            '''

            self.tick = symbol
            self.s = sym
            self.algo = QCAlgorithm
            self.symbol = QCAlgorithm.Portfolio[sym]
    

            self.TM = TradeManagment(QCAlgorithm,sym)

 

    class TradeManagment

        def __init__(self,QcAlgo,symbol):

            self.algo = QcAlgo
            self.symbol = QcAlgo.Portfolio[symbol]
            #symbol is pulling only the string, not the class. Need to decide how to place
            self.TotalMargin = self.symbol.TotalMargin /5
 

My leading theory so far is that when I call self.AddSecurity().Symbol in main I'm pulling out and storing one call too deep into the class and getting the wrong variable?

        

        

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.


Hi Brent,

TotalMargin is not an API, you should use TotalMarginUsed. For detailed API information, please read this documentation page.

Hope this helps!

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.


That would be perfect, but I'm trying to get all the Margin available regardless of holding.

So, 

leverage = 10

distribution = 5

(self.Portfolio.TotalPortfolioValue * leverage) / distribution

...?

0

Hi Brent,

I think you want to get the remaining margin. If so, you can use self.Portfolio.MarginRemaining API. If you want to get the required margin, you can use self.Portfolio.TotalMaginUsed. And if you would like to get the total margin (remaining margin+margin used), self.Porfolio.TotalPortfolioValue should be fine. For detailed API information, please read the page here.

Hope this helps!

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