Back to Community
schedule_function not working? I keep getting "Local variable 'schedule_function' is assigned to but never used"

I'm building a strategy, where I want the system to run only once per day. Here's the start of my code:

def initialize(context):  
    set_commission(commission.PerShare(cost=0.0075, min_trade_cost=1))  
    set_slippage(slippage.VolumeShareSlippage(volume_limit=0.025, price_impact=0.10))  
    schedule_function = (my_system, date_rules.every_day(), time_rules.market_close(hours=1))  
    context.spy = sid(8554)  
    context.aapl = sid(24)  
def my_system(context, data):  
    # trading strategy, signal generation, and trade execution

    .............................  

Also, "my_system" is the function that has all my strategy code, such as signal generation, trading execution, and rebalancing. But for some reason, the backtest doesn't work, and I get the error message:

"Local variable 'schedule_function' is assigned to but never used"

Why is this?

2 responses

Probably just a typo... the schedule function code should be

    schedule_function(my_system, date_rules.every_day(), time_rules.market_close(hours=1))  

There was an equal sign in there. With the equal sign, Python thought you were trying to create a new local variable called schedule_function and assign a value to it. schedule_function is a method and should be called as above.

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 Dan, appreciate it