Back to Community
General notebook question

Hey everyone,

I've got a quick question hopefully someone can help me out with. Currently working in the notebook and I want the table to display my portfolio weights based off of my trading signal --> All weights = 0, except IEF at 1.0, if the current price of SPY is below its 200 day moving avg. If Current > Moving Avg, it displays the weights I have computed, with IEF held constant at 0.20. I don't have an issue displaying the table normally, its when I want the table to take the signal into account where I'm running into a problem.

I keep trying to do an "if statement" but no luck (as you can see in the notebook).

If anyone could point me in the right direction, I'd greatly appreciate it.

Thanks,
Tom

Loading notebook preview...
Notebook previews are currently unavailable.
1 response

Hi Tom,

Currently, the ‘if’ statement is attempting to compare multiple values in spy_data to another set of values in spy_moving_avg which can’t be done.

Instead, compare only one value in spy_data to another value in spy_moving avg. To compare the last value in spy_data to the last in spy_moving_avg use: ‘if spy_data[-1] < spy_moving_avg[-1].

The way you have it written now, setting weights to weights inside the ‘if’ statement just sets the variable to itself. Perhaps you intend some other logic here.
Let me know if you need any more help!

Best,
Robert

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.