Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Internal Bug discovered - email sent

Hi,

I'm receiving this error from you system when running my algo:

Something went wrong on our end. Sorry for the inconvenience. Please email us so we can help.  
AttributeError: 'int' object has no attribute 'amount'  

I've checked all my .amount usage and not of if stops the algo. Seems to end at the end of day. Could someone from Quantopian support have a look at it please.

Thanks in advance.

3 responses

Hi Andrew,

Thanks I saw your email and wanted to share here so that everyone can benefit. In initialize(), you set a variable equal to context.portfolio.positions. And then in handle_data() you over-write this positions object. From our logs, this indeed looks to be a bug in our backend and we'll get that fixed - thanks for the report.

In the meantime, you can create a new dictionary variable (not portfolio.positions) to track your custom data.

Cheers,
Alisa

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

Hi Alisa,

Thanks for your quick response. I'll have a look at it shortly in more detail.

Quick question though: surely assigning context.portfolio.positions object to a variable makes a copy of the instance and not an alias. In which case, surely I can do whatever I like to my custom variable, no? Other than that, I can't see where else I'm using context.portfolio.positions. Could you point me at the place where I overwrite the object?

Thanks.

Hi Andrew,

Assignment in python does in fact only add an alias to the object on the right-hand-side. Python refers to this as (re)binding of names to values, and there are various discussions out there regarding these semantics, which apply to assignment and also to passing of arguments to functions.

That being said, it's still confusing that an algo should be able to mess with the internal state of the simulation. To improve the experience, we should probably make the positions attribute return a copy, which would match the behavior you expected in the first place.

Best,
Rich

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.