Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How can I use data from two companies to short/long on a third company (correlations) ?

Hi,
I'm new in this community
I hope not to bore you with a basic question, but here is my problem
I've selected few data corresponding to two companies (RAI and RTN)
Based on this data, I'd like to short/long on a third company (LMT)

How can I do that?

I've read a lot of articles and forums, but they always operate using data from that single company
Any suggestions?

5 responses

Maybe an if statement would work. If conditions are met for the first two stocks, buy or sell the third stock.

Hi Eric, thanks for helping

As you can see on the source code

My idea was similar

for security in long_secs:
if data.can_trade(security):

order_target_percent(symbol('BCR'), 1)

But I can follow this path when "security" has more than one stock inside
I'm unable to select which stock should be used to influence my short/longs operations

What's your opinion?

Maybe running the ordering code each time a security is returned is the problem. The ordering code could make one decision based on inputs from every stock returned by the screen.

Eric may I ask for an example?
just few lines to understand your idea

I changed it to order_target_percent(security, 1) and it produced the same result so don't think hardcoding the security is necessary there. That should work with multiple securities as input, and the target percentage could be changed to 1 divided by the number of securities returned as well.