I'm taking the beginner course in algo-trading. In the MAC strategy we buy when short-term average price is greater than long-term average and sell when the long-term is greater. I want to confirm what is meant by sell. Does it mean to close the position or to SHORT it ?
Hello Obimba,
It's great to know you are starting your journey in algo trading.
Let me ask you something:
- Do you mean the course "Getting started with Algorithmic Trading!"?
- You're talking about the strategy presented in section 9, right?
In case both questions' answers are true, let's try to answer:
In the notebook presented in section 9, unit 6, we have in the cell 5 the construction of the signal, which is this code line:
data.loc[:, 'signal'] = np.where(data['window_ST'] > data['window_LT'], 1, -1)
This code line is explained as follows:
- In case the window_st (short-term moving average) is higher than the window_LT (long-term moving average), then the signal will be equal to 1, meaning we are going to BUY the asset.
- In case the window_st (short-term moving average) is lower than the window_LT (long-term moving average), then the signal will be equal to -1, meaning we are going to SHORT SELL the asset.
Whenever you see this type of condition in which you have the dichotomy 1 and -1, then it means we're talking about BUY and SHORT SELL the stock.
Let's propose another type of signal, the following:
data.loc[:, 'signal'] = np.where(data['window_ST'] > data['window_LT'], 1, 0)
Do you notice the difference? In case the long-term window is higher than the short, we put 0 as the value, instead of -1.
Imagine we have as the signal column the following data:
day | signal
day 1 | 0
day 2 | 1
day 3 | 1
day 4 | 0
day 5 | 0
First, on day 1, we don't have any position on the stock. Then on day 2, our algorithm tells us to buy (since the signal is 1). We continue to have the same long position on day 3. Finally, on day 4, our algorithm tells us to close the position, so we do that. On day 5, we don't have any position, neither long nor short, as on day 4.
To sum up:
signal | meaning
0 | We take no position at all, neither long or short
1 | We go long, meaning we buy the asset
-1 | We go short, meaning we short sell the stock.
I hope this clarifies your doubts,
Thanks and regards,
José Carlos
Thanks for your detailed explaination. This clarifies it