Quaterly Returns from Monthly Prices

SS1312

New Member
Joined
May 10, 2022
Messages
3
Office Version
  1. 2007
Platform
  1. Windows
Hey,
Hope everyone is doing okay and keeping safe

I have been tasked to make a Fund Performance dashboard using VBA I am able to get stock data from yahoo. Also managed to calcuated monthly returns from daily NAVs. However I am struggling to calculate Quarterly returns.

Here is the code. Though this works in calculating quarterly returns the issue is it repeats. Here is a picture (practice file cant mention real returns)

It calculates the monthly returns, but for quarterly retuns I only want for actual quarter ends in a financial year in a year. However here is it calculating for every month

If anyone can guide me it can be of great help. Thanks

VBA Code:
Sub Button2_Click()

Worksheets("Prac").Activate

           
  Dim old_ As Double
  Dim new_ As Double
  Dim start_row As Integer
  start_row = 4

  ' Track the number of rows
   Dim num_row As Integer
   num_row = 0
   While (Not (IsEmpty(Cells(start_row + num_row, "G"))) And Not (IsEmpty(Cells(start_row +
   num_row, "G"))))
   num_row = num_row + 3
 Wend

 Dim end_row As Integer
 end_row = num_row + start_row - 1
' Calculate Rate of Return
Dim m_r_j As Double
Dim m_r_m As Double

For r = start_row To end_row - 3 Step 1
 old_ = Cells(r, "G")
 new_ = Cells(r + 3, "G")

 m_r_j = (new_ - old_) / old_
 Cells(r + 3, "M").Value = m_r_j

 Next
 End Sub


1653626549611.png
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the forum.

Change "Step 1" to "Step 3".

Also, your While conditions check for column G twice. Should the second one be H?
Book1
FGHIJKLMN
3MonthlyQuarterlyPeriodically
421-Jul1009.56315763.05
521-Aug1053.517132.24.35%
621-Sep1091.1117618.153.57%
721-Oct1132.00818114.93.75%12.13%
821-Nov1066.37116983.2-5.80%
921-Dec1086.33217354.051.87%
1022-Jan1108.52617339.852.04%-2.07%
1122-Feb1072.69116793.9-3.23%
1222-Mar1121.07217464.754.51%
Prac
 
Upvote 0
Thanks,

However I want 3.20% and -0.44% value to be shown. Since those are the quaterly returns.
 
Upvote 0
VBA Code:
Sub Button2_Click()

Worksheets("Prac").Activate

           
  Dim old_ As Double
  Dim new_ As Double
  Dim start_row As Integer
  start_row = 4

  ' Track the number of rows
   Dim num_row As Integer
   num_row = 0
   While (Not (IsEmpty(Cells(start_row + num_row, "G"))) And Not (IsEmpty(Cells(start_row + num_row, "G"))))
   num_row = num_row + 3
 Wend

 Dim end_row As Integer
 end_row = num_row + start_row - 1
' Calculate Rate of Return
Dim m_r_j As Double
Dim m_r_m As Double

For r = start_row To end_row - 3 Step 1
If Month(Cells(r, "F")) Mod 3 = 0 Then

 old_ = Cells(r, "G")
 new_ = Cells(r + 3, "G")

 m_r_j = (new_ - old_) / old_
 Cells(r + 3, "M").Value = m_r_j
End If
 Next
 End Sub
 
Upvote 0
Okay this does work. However if i add months as in April, May - it doesnt work
 
Upvote 0
But it does work if you also add June, right? April and May aren't ends of quarters. I'm not really sure what more you want.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top