When investing in a retirement fund using DCA(Dollar-Cost Averaging) strategy, does it perform better than the inflation rate?
In this Article, we will find out what is the past inflation rate in Thailand.
Then we will find out how the DCA on a fund performs.
And then we will plot a bar chart to compare the average return against inflation.
Step 1: Import Eikon Data APIs and libraries
Step 2: Find out the inflation rate
These are the price indexes.
Convert it to percent changes per year.
Step 3: Retrieve Fund NAV for the past years
Step 4: Define your past contribution.
Please note that these are sample numbers which include random increment per year.
Step 5: Fill contribution data into NAV dataframe using the date.
If the date could not be found in NAV dataframe, add 1 day to the date (until the NAV is found).
Then remove all the rows without a contribution
Step 6: Add calculated data to the dataframe. They are Total Amount Invested, Unit Invested, Total Unit Invested and Gain/Loss columns.
Once you complete this step, you are able to see how much you gain(or loss).
But this still does not give you the idea of how much it grows per year on average.
Step 7: Get current NAV
Append it to the previous dataframe
Step 8: Define xirr() function
XIRR is the internal rate of return for a schedule of cash flows that is not necessarily periodic.
Step 9: Prepare data from dataframe for xirr function
Calculate xirr
Step 10: Compare between Inflation and Average Return
First, let add "Return" to the CPIs dataframe
Next, plot bar chart to compare the inflation rates and average return
Here is the chart:
You can see from the bar chart that the average return from the sample DCA investing on "LP63500988" fund usually wins against inflation.
Except in 2011(against Food) and 2013(against House).
You can try running this Jupyter Notebook sample using your own contribution data and use the actual fund you are DCA investing in.
Reference: