How to reference the previous month's high or low in a data set and compare it with the current value - excel

I have an Excel spreadsheet of daily Open/High/Low/Close data for an stock index (link below) and wish to go through the data day by day to create a marker for each day. I would like this to be +1 if the high of the day is above the high of the previous month, -1 if the low of the day is below the previous month's low and 0 if neither of these conditions are satisfied. A previous answer on this forum showed me how to extract the monthly high and low for each month (also in the spreadsheet). It seems quite straightforward on the face of it but I can't seem to get anywhere. I've been trying to use nested "if" statements to do this. I have actually asked this question before but I had no response. Any help would be much appreciated.
Many Thanks, Paul
Link to image
https://imgur.com/gallery/rJen7xw

Related

Having problems spreading expense over months with partial month calculation

I am writing a nested if statement that will calculate monthly expense based on an "Expense Frequency" option. Most of them see to be working but I have two that will not work for some reason.
The first problem is the "Fixed" option - I want this to put the whole expense rate in the first month of the expense period. For some reason it is not triggering in the first month. I feel like this might be a simple fix?
The second problem is a little more complex. It is the "Spread Amount" option. When the months are full calendar months the calculation is easy, divide total expense amount by # of months. But when I factor in partial months the calculation diverges from what I am looking for. The shorter the time duration, the larger the variance is from the total expense. When I stretch the expense over a longer period the variance shrinks. It is a pretty complex calculation (I think) and basically I want to use days out of the month for the calculation in the partial months (first and/or last) and then whole months in the middle. I have attempted this in my attached spreadsheet and I thought it might work but it isn't. Is anyone able to help me out here? I would even be satisfied with a succinct explanation of why this calculation isn't possible / doesn't make sense / cannot be done so I can explain this to my boss. I am providing a cash reward for this if it can be handled in the next three hours. Please help!! Thank you!
This is my formula
=IF($I9="Spread Amount",IF(AND($J9<=O$6,$K9>=O$5),IF(EOMONTH($J9,0)=O$6,(($M9)/(DATEDIF($J9,$K9,"m")+1)((O$6-$J9+1)/O$4)),IF(EOMONTH($K9,0)=O$6,IF(EOMONTH($K9,0)=O$6,(($M9)/(DATEDIF($J9,$K9,"m")+1)(($K9-O$5+1)/O$4))),($M9-IF(ISERROR(HLOOKUP($K9,$6:9,$XFD9,0)),HLOOKUP(EOMONTH($K9,0),$6:9,$XFD9,0),0)-IF(ISERROR(HLOOKUP($J9,$6:9,$XFD9,0)),HLOOKUP(EOMONTH($J9,0),$6:9,$XFD9,0),0))/(DATEDIF($J9,$K9,"m")))),0),IF(O$7>$K9,0,IF($I9="EOQ",IF(OR(MONTH(O$7)=3,MONTH(O$7)=6,MONTH(O$7)=9,MONTH(O$7)=12),$M9,0),IF($I9="Spread Evenly",IF(AND($J9<=O$6,$K9>=O$5),IF(EOMONTH($J9,0)=O$6,$M9*((O$6-$J9+1)/O$4),IF(EOMONTH($K9,0)=O$6,$M9*(($K9-O$5+1)/O$4),$M9)),IF($I9="Fixed",IF(AND($J9>=O$5,$J9<=O$6),$M9,0),IF($I9="Repeat Annually",IF(MONTH($J9)=MONTH(O$6),$M9,0),0))),IF($I9="Odd Month",IF(ISODD(MONTH(O$6)),$M9,0),IF($I9="Daily",IF(AND($J9<=O$6,$K9>=O$5),IF(EOMONTH($J9,0)=O$6,($M9/($K9-$J9+1))(O$6-$J9+1),IF(EOMONTH($K9,0)=O$6,($M9/($K9-$J9+1))($K9-O$5+1),($M9/($K9-$J9+1))*O$4)),0))))))*1)
This is what the spreadsheet looks like

How to display the past 17 trading days (business days) when looking up Stock History in excel

I'm using the new STOCKHISTORY function in Excel and I'd like to always display the past 17 trading days from the point I indicate. The problem is with long weekends and holidays this alters the amount of business between two dates. I'm not sure if this will be a difficult question because I think the solution is not dependent on the fact that I'm using the STOCKHISTORY function. I have attached a photo with a simple explanation. On the left the formula for STOCKHISTORY is =STOCKHISTORY(E2,C4-C6,C4,0,1,0,2). This displays 17 business days because 22 is the magic number. On the right though if I query July 22nd with 22 day difference I only get 16 days. This is further wrong on many other dates.
I am open to having a separate reference on another sheet that has dates/formulas. I tried this but couldn't figure out a formula to pull down. Photo B displays an example of the correct number of dates that would show 17 trading days. I am also open to displaying more than 17 trading days as in the future I will need to alter the amount of trading days needed (I might need to display 15 days or 20 days).
In my head I feel like the answer has something to do with the NETWORKDAYS function and/or I should make a list of all the trading days in a year and then make a formula taking the current day and taking away a specific day. Or I could be totally wrong and the answer is obvious.
So I figured out an answer after reading some documentation. There is most likely better answers but it solves the problem enough.
So I created a list of all trading days (business days) as you can see in column O. Then in Column L a list of nearby holidays (Only needed a few exceptions). Then using the formula =(O35)-(WORKDAY(O36,-17,$L$35:$L$36)) I get the right solution which I verified in my example photo posted earlier. You could theoretically get a different number when doing your own calculations (i.e the answer 24 and 23 are both correct).

Keep only the first and last business day of each month in Excel

I posted this question combined with a dozen other questions I now solved yet this one still remains, hopefully someone has a smart idea.
Challenge:
I got a spreadsheet with daily stock prices for 500 companies with the goal to calculate monthly returns. To achieve this I only need the frist and last business/ trading day of each month. As the data covers roughly 20 years the option to delete the days within these two manually isn't really efficient. Any ideas how to do it faster?
Thanks in advance!

Select pay rate based on day and shift start time

Im creating an excel pay sheet so i can keep tabs on my pay.
I have two pay rates,
£9.30 is paid for hours worked from 6pm to 8am Monday to Thursday
£10.30 is paid for hours worked from 6pm Friday to 8am Monday.
I have a column that displays the pay rate, i want this to populate automatically with excel looking at the day of the week and then the start time and then returning the correct pay rate.
For example,
If the day is a Mon and the start time is 6pm return £9.30
If the day is Fri and the start time is 6pm return £10.30 etc etc
Any one have any ideas on how i can achieve this? Id rather this be formula based instead of VBA if possible but if it cant be formula based then VBA it is.
Thanks in advance
I had to make a few assumptions because your question was unclear about the possible start times for your shifts. Your wording and examples lead me to believe that your shifts always begin at 6 PM regardless of the day. I created a possible solution or start to a solution based on that assumption that does not rely on VBA. I've included links to an excel workbook with my solution and a screen shot. (I'm only allowed 2 links with my current rep.)
As Gowtham Shiva suggested in the comments, a screen shot of what you have so far would be helpful.
I created two tables and a named ranged called “valDays”. To use the workbook, you enter the date and start time for your shift in tblPay. Enter the pay rate for a specific day and time in tblRates. valDays provides a way to convert the text for a day of the week into a number for calculating date/time serial numbers.
Feel free to comment/message me for clarification. I’ll do my best to reply and refine the solution as necessary. I hope you find this answer helpful and appreciate feedback. This is my first time providing an answer on Stack Overflow.
I’m going to assume you know how to name a range, create tables, and rename tables in excel. If you don’t there are plenty of YouTubers and bloggers that cover these topics quite well.
List the days in a column off to the right. (I used column K.) “Sun”, “Mon”, “Tue”, etc. Select all the cells with the days of the week and name the range “valDays”.
Formula in tblRates[Serial]:
“=MATCH(tblRates[[#This Row],[Day]],valDays,0)+tblRates[[#This Row],[Time]]”
Formula in tblPay[Serial]:
“=WEEKDAY([Date])+[StartTime]”
Formula in tblPay[Rate]:
“=INDEX(tblRates[Rate],MATCH([Serial],tblRates[Serial],0))”
You can download the excel document and view these screenshots of a possible solution.
Link to Excel Workbook on Google Drive
Screenshot1

Excel Index Function

I just want to thank you guys in advance. I think you guys are doing a great job in helping people out with programming stuff. Pats on the back for all of you.
Here is what I've been working on: I have daily stock price return data on about 4000 stocks. I want to add them to my portfolio after observing their performance for 12 months. I will choose the top 10% best performers and bottom 10% worst performers. I will create multiple portfolios over a period of time. I have done that with no problem.
I want to use the INDEX function to calculate the daily return of my portfolio. Not all 4000 stocks are in my portfolio, about 300 stocks are in my portfolio at any given time. The daily portfolio returns will be calculated by multiplying the weights (they are equal weighted, so 1/300) to that stock's return on the specific date. I assume it has to do with a combination of INDEX, SUMPRODUCT, and IF or MATCH functions.
I have been thinking this for a long time and I just can't get to the bottom of it. I have attached pictures for a portion of what I was working on. I think will give you a good picture of what I'm trying to do. I bet this is such an easy thing for you guys. I hope you can help me out! Thanks again!
PICTURES:IN or OUT portfolio & Stock's individual returns
Charles
Not sure I understood your problem, but here is a trial suggestion:
You get data for 4000 stocks while you are monitoring 300. So, you need to find the correct one within your sheet (there will be 3700 that will not match anything).
If you have your stocks listed in, say, column "A", you could use the function LOOKUP (well explained in the Web). If you need to get the row of your stock, you can use the function MATCH.
If this is not what you are looking for, it means that I (at least) did not understand you, so you would need to add details to your question.

Resources