Hii
Why we are using new as variable in 3 line. Wouldnt it override the previous one sorry i am new to python programming?
In the code, the variable 'new' is being used over and over as an input for different functions, and then being reassigned with the output of those functions. This is known as chaining or method chaining, it's a common way to simplify the code and make it more readable.
The reason it doesn't override the existing 'new' variable is that the output of each function is being saved to the same variable 'new' and being used as an input for the next function. So, the variable 'new' keeps getting updated with the new value after each function call.
Here's an example of what is happening:
new = relative(stock_dataframe=new, benchmark_dataframe=benchmark, benchmark_name='SP500',forex_dataframe=forex, forex_name='USDGBP', decimals=2, start=None, end=None)
Here, the function 'relative' is being called with 'new' as an input, and the output is being saved to the same variable 'new'.
new = swings(df=new, high='rebased_high', low='rebased_low', argrel_window=20)
Here, the function 'swings' is being called with 'new' as an input, and the output is being saved to the same variable 'new' again.
new = regime_fc(df=new, close='rebased_close', swing_low='srebased_low', swing_high='srebased_high', threshold=1.5, t_dev=63, decimals=3)
Here, the function 'regime_fc' is being called with 'new' as an input, and the output is being saved to the same variable 'new' again.
By chaining these method calls in this way, the code is more readable and easier to understand, and it also makes it clear that the intermediate results are being stored in the same variable, rather than creating multiple variables that could lead to confusion.
I hope this was helpful.
Thanks Very well explained