Hello Friends,
This is going to be difficult. I tried my best but wasn't successful and it will be little difficult for me to explain my desired output. However, I will try my best.
In stock market, there is something called as Top Gainers and Top Losers that shows top stocks that performed best and worst. While calculating, the gain and loss percentage, it considers previous day's close price and today's close price when the market closes.
I want a similar data but change in calculation. Instead of considering previous and current day's close, it should consider current day's high and low. I need to find out how much percentage the stock rose from its day low (Top Bounce Back) and how much percentage the stock fell from its day high (Top Pull Back).
Purpose is to find out the best timeframe with highest percentage. To do this, my logic is to read the first data from the "raw.csv" file and record low and high and calculate percentage rise. and then iterate through each row of that particular stock to find if the percentage was higher than before. Keep iterate through the end of the row of that particular stock to find the best time frame where the percentage is highest. Do it for all stock and dump the result in TopBounceBack.csv. In this we were checking percentage increase from low to high. Do a similar exercise to find out percentage increase from high to low and dump result in TopPullBack.csv. I hope I have explained my problem correctly.
For better understanding, I am attaching 3 files where I calculated the result by doing manual work.
raw.csv = it has sample data for four stocks
TopBounceBack.csv = it has the desired output for performing stocks
TopPullBack = it has the desired output of worst stock
After trying much when i failed, I processed raw.csv file manually and came up with the next two desired output csv files. I thought, while doing it manually, I can get a logic but I failed.
Appreciate some help. Kindly help me with a code that can output csv files as per desired results.
Thank you
EDIT: I have added the purpose in my question.
Bookmarks