Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Simple long short strategy

Hello,

I am new and am trying to implement my first backtest of a simple strategy.

The strategy involves two stocks, stock A and B. The difference between the intraday returns of these two stocks has mean 0% and standard deviation of 4%.

I would like to test the strategy where 50% of the portfolio is long the lower of the two, and short the higher of the two.

For example, it's noon, and the current price of stock A is down 2% from previous close, while the current price of stock B is up 2% from previous close. The algo would then allocate 50% of the portfolio, long stock A, and would short stock B equivalent to 50% of portfolio. Then, it would sell/buy to cover when the relationship has inverted. Stock B is instead 2% down, and stock A is 2% up, lets say a few days later whatever time this happens.

Please forgive me if I'm missing something obvious from the lectures/something searchable.

2 responses

I really like your codes, Vladimir :) concise and illustrative!

Thanks for sharing!

You guys get a room.