In the Short Selling, the 'floor and ceiling method' code is not so easy to understand and I nee help,
in particular for the code in the "5. loop swing to calculate regime", it could be possible explain the if loop to find the ceiling/floor row by row.
And in particular I saw that you test the standard deviation with a threeshold of 1.5 as a condition to set ceiling or floor, is there a particular reason to use 1.5?
Sigma=1.5 is probably enough to be certain that a new floor or ceiling is distinguished from the previuos one.
Tks Konstatin
Hi Rocco,
Made changes to the content, but you havent explained why 1.5 was used? Please add the explanation also and then post the below response.
As you might have watched in floor and ceiling video, you know that we need to find the floor and the ceiling to identify if there is a regime change. First, we establish the floor and then we go looking for the ceiling. We set and declare the first floor and ceiling location.
To determine the floor, we ignore all the swing highs and for the ceiling, we ignore all the swing lows. We perform a distance test using the standard deviation in volatility units. If the test is passed, we record the floor and ceiling or else we record a regime change, -1 or +1, bearish or bullish.
In this particular section, # Loop swings to calculate regime, we loop all the swing highs and swing lows using the for loop. In the first case, when we are looking for ceiling, we run three conditional statements, one when swing_highs>0, ceiling_test>-threshold and the final one to confirm if the ceiling has been found. Since we are looking for the ceiling, we will only look for the highest swing highs and ignore the swing lows.
In this code below:
# Highest swing high from range[floor_ix:swing[i]]
top = regime[floor_ix:regime.index[i]]['srHigh'].max()
# Test for the Highest
ceiling_test = round(
(regime['srHigh'][i]-top)/regime['stdev'][i], 1)
We create a distance test, which must be passed to define a ceiling. And if this ceiling test>-1.5, then we locate the new location for ceiling and assign it. But if doesn't clear the distance test, we record a negative regime change, -1. Similar are the steps to locate floor and if that distance test doesn't gets passed, we record a positive regime change, +1.
And, there is no way to tell in advance if the current low is going to be the bottom. Peter Lynch once said that "more money has been lost in the "last 5%" trying to find the bottom than in during the bear itself". We only know a posteriori when new lows fail to take the bottom and move decidedly higher. A simple but robust way is to calculate the distance to the bottom in standard deviations. 1.5 stdev has a cumulative density probability of 80%. We all know that returns are not normally distributed, but still it is probably going to be above 50%.
Hope this explaination helps. Let us know if you have any other doubt.
To determine the floor, we ignore all the swing highs and for the ceiling, we ignore all the swing lows. We perform a distance test using the standard deviation in volatility units. If the test is passed, we record the floor and ceiling or else we record a regime change, -1 or +1, bearish or bullish.
In this particular section, # Loop swings to calculate regime, we loop all the swing highs and swing lows using the for loop. In the first case, when we are looking for ceiling, we run three conditional statements, one when swing_highs>0, ceiling_test>-threshold and the final one to confirm if the ceiling has been found. Since we are looking for the ceiling, we will only look for the highest swing highs and ignore the swing lows.
In this code below:
# Highest swing high from range[floor_ix:swing[i]]
top = regime[floor_ix:regime.index[i]]['srHigh'].max()
# Test for the Highest
ceiling_test = round(
(regime['srHigh'][i]-top)/regime['stdev'][i], 1)
We create a distance test, which must be passed to define a ceiling. And if this ceiling test>-1.5, then we locate the new location for ceiling and assign it. But if doesn't clear the distance test, we record a negative regime change, -1. Similar are the steps to locate floor and if that distance test doesn't gets passed, we record a positive regime change, +1.
And, there is no way to tell in advance if the current low is going to be the bottom. Peter Lynch once said that "more money has been lost in the "last 5%" trying to find the bottom than in during the bear itself". We only know a posteriori when new lows fail to take the bottom and move decidedly higher. A simple but robust way is to calculate the distance to the bottom in standard deviations. 1.5 stdev has a cumulative density probability of 80%. We all know that returns are not normally distributed, but still it is probably going to be above 50%.
Tks, I am new with Python I need to understand it better. I think I need some time