For sharing purposes
For sharing purposes
First algorithm here =). Feedbacks are welcomed. I was wondering if it would be a better idea to long stocks with promising signs and short the reverse instead of the current implementation. Thanks
Thanks for sharing Dan! This looks interesting - it might be worth running the backtest over a longer period of time to see more history.
Also, if you're considering live trading the algorithm, I would put your global variables into context in initialize(). For example,
def initialize(context):
context.COND1_USED = True
context.SMA_RATIO_LOWER_BOUND = 1.0
context.COND2_USED = True
Context is used to save state of variables between bars of the backtest and in live trading. Nice first algo!
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 Dan look sharp, thanks for sharing. I was reading through the code and I don;t quite understand a few bits. If you don't mind, could you through some text around what rerank does and how it impacts the trade execution?
Cheers
Hi Rick, thank you for looking at my code. The rerank basically is called once everyday ATM, it calls other function to rerank the stocks based on their momentum. The momentum is calculated by looking at two MAVG, one is 2 days the other is 1 day. The rerank function makes sure that everyday you're buying the stock that has a positive momentum, and sell the stocks that have a negative momentum. Thanks
Hi Alisa, did you guys make changes to the MAVG function. Because right now if I deploy my code minutely like this
def initialize(context):
pass
def handle_data(context, data):
order(sid(24), 50)
log.info(str(data[sid(41575)].mavg(1)))
log.info(str(data[sid(41575)].mavg(4)))
The mavg(1) and mavg(4) are returning the same result. Any idea why this is happening? Thanks.
Hi Dan, This behavior is now fixed, go ahead and try it again. Thanks!
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.