Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Schedule year start

In the documentation I've seen that it is only possible to schedule a rebalance each week/month, but it is not possible to do it in a long period of time (i.e rebalance yearly).

quantopian.algorithm.date_rules.every_day() Create a rule that triggers every day.
quantopian.algorithm.date_rules.month_start([...]) Create a rule that triggers a fixed number of trading days after the start of each month.
quantopian.algorithm.date_rules.month_end([...]) Create a rule that triggers a fixed number of trading days before the end of each month.
quantopian.algorithm.date_rules.week_start([...]) Create a rule that triggers a fixed number of trading days after the start of each week.
quantopian.algorithm.date_rules.week_end([...]) Create a rule that triggers a fixed number of trading days before the end of each week.

Do you know if there is any function that allows to do it?

Thanks

1 response

There isn't a built in function to schedule annually or any other frequency than those listed above. However, one can write a small bit of code to accomplish any frequency desired. For example to run the first of every January one could do something like this

def initialize(context):  
    schedule_function(first_of_year_rebalance, date_rules.month_start(), time_rules.market_open())

def first_of_year_rebalance(context, data):  
    # Execute our rebalance code only if it's January.  
    today = get_datetime('US/Eastern')  
    if today.month not in [1]:  
        # It's not January so just return  
        return  

There are also a number of posts that address similar scheduling needs. Search for 'get_datetime' or 'schedule' and you will find some more.

https://www.quantopian.com/posts/custom-rebalance-using-date-rules
https://www.quantopian.com/posts/rebalancing-less-frequently-than-1-month-help
https://www.quantopian.com/posts/using-schedule-function-every-day-but-mondays-possible

Good luck,

Dan

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.