please explain this line of code, what does it do exactly
course name: short selling in trading
high_low.loc[(high_low['swing_high_low'].shift(1) * high_low['swing_high_low'] < 0) &
(high_low['swing_high_low'].shift(1) < 0) & (np.abs(high_low['swing_high_low'].shift(1)) < high_low['swing_high_low']), 'swing_high_low'] = np.nan
We are eliminating all the swing low higher than highs. We are doing this because we buy at the swing low and sell at high. If swings low is higher than the swing high, it results in a loss-making position because you are buying at low and selling at a lower point.
In the code, we are checking this using three conditions.
- previous value of swing high low multiplied by a current value should be less than 0
- previous value of swing high low should be less than 0 and
- the absolute previous value of swing high low should be less than the current value.
If the above conditions satisfy, we will fill the swing_high_low column with nan value and further in the code will remove those.