How to calculate and program CAGR, if during this time I put in and take out some extra capitals?
Just don’t put in/out money and that is it.
What if it is my 401k, and me and company put in some money every month?
You need to decide if you want to calculate something that interests you (like CAGR) or if you want to do “virtual reality”. If you are interested in getting job done, you just run backtest and be done. Start with high enough initial equity so all trades are taken and look at the result and that’s it. If you have too much free time you can tweak your calculations, export the equity (or use ~~~EQUITY) and do whatever calculation you need. If you have even more time you can write your custom backtest code that will add cash to your account every month or every other period. You can derive your own method of calculation and add it as custom metric.
Sorry, my question was very simple.
What will be my initial capital to calculate CAGR, in my case of 401K, when I and company put some money every month? Is it the beginning capital in Jan, or I have to calculate by each month and then aver?
@maury314: Are you trying to report the CAGR of your trading system (which will approximately the same regardless of cash deposits and withdrawals), or the CAGR of your account, which will be very much affected by deposits and withdrawals?
In either case, do you already understand how to calculate CAGR from an equity curve? If you don’t have a firm grasp of the math, then it will be impossible to write the AFL.
Annually Compounding Annual Growth Rate
ACAGR = RatioCycles – 1
Ratio = EndValue / StartValue
Cycles = 1 / DateRangeInYears
DateRangeInYears = (EndDate – StartDate) / 365.25
Equity From ACAGR
Equity = OriginalEquity * (1 + ACAGR) (DateRangeInYears)
So … What should be equal to StartValue in my case (deposit every month and withdraw some time) with for my accounts?
Right. So what about my first question: are you trying to calculate CAGR for the account, i.e. cash deposits and withdrawals will be considered similarly to trading gains and losses? Or are you trying to calculate CAGR for the trading system only, independent of cash deposits and withdrawals?
… Account …
@maury314 If you want to calculate your account cagr while occasionally making additions and subtractions from the account then you will need to make complex mathematical calculations and code them into the Custom Backtest Interface. I suspect both steps are beyond your capabilities (not meant as an insult as they are beyond mine too). You can start by reading this http://www.financialwisdomforum.org/gummy-stuff/xirr.htm
and investigating the Excel function "XIRR" which has a formula that looks similar to this,
There are simpler approximations but they too require a fair bit of calculations and code writing.
Have you reached the stage that your trading strategies are so solid that you can spend your time doing these calculations as opposed to just keeping track of your overall portfolio growth (or shrinkage) ?
Thanks Larry, finally I got the answer.
Some my response …
I am using Roger Scott Market Geeks service.
You are not insulting me … . I understand and like the Excel function … I have PHD in math, but it was long time ago. My problem is that I don’t know object programming in a good level and my beautiful but bad Russion English , that cannot explain a good and fast way to people …
What is your simple approach?
Thanks Larry one more time …
The easiest solution would be to add a very basic mid-level CBT to your AFL. That way you can allow AmiBroker to continue to process all your signals, but at the end of each bar you can add or subtract a value to bo.cash which represents your deposits and withdrawals. Of course, you’ll need to figure out some logic to determine the correct dates (bars) on which to make those additions and subtractions. By using this approach, the CAGR number reported by AmiBroker will reflect both your trading profits and your account activity, i.e. it will be the CAGR of your account growth.
Thanks, that what I am doing, using Excel, but without function “XIRR”.
Thanks for XIRR !!! It works . Maury