Back to Community
Why is This Algorithm Trading on Fundamentals Without Updates?


I was playing around with fundamental data and noticed that the attached algorithm seems to trade every week.

I've checked the logs though and none of the fundamental data has changed week to week so why does it keep buying and selling each week?


Loading notebook preview...
Notebook previews are currently unavailable.
2 responses

One reason you will see trades each week is because of the order method being used

    for security in long_secs:  
        if data.can_trade(security):  
            order_target_value(security, 10000)

The 'order_target_value' method will place either a buy OR a sell market order in an attempt to adjust the current portfolio holdings to be $10,000. If the price of the security went up a little over the week, then that method will try to sell a few shares. If the price went down, then it will try to buy a few shares.

Is this buy and sell a few shares each week behavior what you are seeing?

If you want to simply hold a fixed quantity of shares (rather than a fixed dollar amount as above) then use the 'order_target' method ( )

Ok brilliant thanks. I'm trying to develop a 'buy and hold' strategy that only trades when new fundamental data comes out, which I would have thought to be at reporting seasons.

Nb. 'longs' are filtered by fundamental factors.

So, I tried the below;

def my_rebalance(context,data):  
    long_secs = context.output[context.output ['longs']].index  
    long_weights = 1.00 / len(long_secs)  
    for security in long_secs:  
        if data.can_trade(security) and security not in context.portfolio.positions:  
            order_target_percent(security, long_weights)

   for security in context.portfolio.positions:  
        if data.can_trade(security) and security not in long_secs:  
            order_target_percent(security, 0)  

I would have thought that it would buy based on fundamental factors and only sell when the fundamentals change and it falls out of the long_secs list. (There should be no weekly adjusting weights of current portfolio as I've said 'not in context.portfolio.positions').

But this still trades significant volume each week. Why is it not simply buying and holding?