Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
SQLAlchemy (Fundamental Data) - order_by involving arithmetic operations and multiple columns

I have the following problem using SQL Alchemy: I want to rank the stocks according to a relation between two fundamental values. As the size of the resultset is limited, the ranking should be done in the query itself. Now the problem is that I cannot find any information in the SQL Alchemy documentation (or the Quantopian documentation) on implementing something like
"SELECT (x - y) AS z
FROM table_name
ORDER BY z DESC"
without using the text function (and pure sql) which causes an import error.

Any help on this issue is greatly appreciated as it completly blocks my development at the moment.

5 responses

Ueli,
Could you do the subtraction and sorting in the algo using the resulting dataframe?

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.

thanks for the reply... yes of course I could do the operation in the resulting dataframe but this would only work if my universe would be restricted to a fixed number (<200) which I would have to choose in advance.

do you see what I mean?

thanks for the support

I am not seeing the 200 symbol restriction in the before_trading_start() function.
This function gets called 15 minutes before trading start.
In here I don't have access to stock price data, but I seem to able to do a fundamental query that brings all 6000 symbols and their fundamentals, an hence can filter after the query.

would that help?

thanks a lot for the reply. i will check this asap!

my bad. you are completely right. I mixed up the restriction about 200 securities in universe with that in the fundamental data query. thanks a lot!!!!