Back of the Envelope

Observations on the Theory and Empirics of Mathematical Finance

Posts Tagged ‘2016-17

[WP] Shiny for Finance

leave a comment »

For those familiar with R, Shiny offers a great alternative to spreadsheets. Targeted at instructors, we have a new paper introducing Shiny for finance applications in the classroom. Here is a longish abstract:

Despite the popularity of open-source languages like R and Python in modern empirical research and the data-science industry, spreadsheet programs like Microsoft Excel remain the data analysis software of choice in much of the business-school curriculum, including at IIMA. Even if instructors are comfortable with modern programming languages, they have to pitch their courses at the level of computer literacy prevalent among students. Excel then appears to be a natural choice given its popularity, but this choice constrains the depth of analysis that is possible and requires a certain amount of dumbing-down of the subject by the instructor. Recent software advances however make the ubiquitous web browser a worthy challenger to the spreadsheet. This article introduces one such browser-based tool called Shiny for bringing finance applications to the classroom and smart phones. Fueled by the availability of high-quality R packages in finance and statistics, Shiny brings together the power of HTML with the R programming language. It naturally creates an environment for the instructor to focus on the role of parameters and assumptions in analysis without the clutter of data, and allows the instructor to go beyond the toy problems that are necessitated by the nature of spreadsheets. The learning curve is short for an interested instructor with even a rudimentary exposure to programming in any language. The article ends with the discussion of a fully-worked out example of Shiny for teaching the mean variance efficient frontier in a basic investments course.

The working paper is here. It needs a bit of fine tuning yet, but comments welcome.

Advertisements

Written by Vineet

April 4, 2017 at 12:30 pm

[PGP-I FM] Time Value of Money

leave a comment »

Chapter 2 of your book has a decent enough description of the mechanics of time value of money, so I won’t spend too much time on this post motivating and explaining it. If you understand the Present Value Rule, then finding the time value of money of future certain cash flow boils down to just simply summing simple geometric progressions (GP). That brings us to the first tip of the day:

Tip 1: When finding time value of money, more often than not you should be able to reduce it to a mathematical problem of valuing finite GPs. Use it!

For this post then I’ll just summarize the math and the main results.

Discount Factors

I include Discount Factors here only to set the notation for this post. There is nothing new here. Given an annual discount rate r the Discount Factor DF_i (with annual compounding) is given as:

\displaystyle DF_i = \frac{1}{(1 + r)^i}

(For much of this post, annual compounding is assumed.)

Perpetuities

A perpetuity (P) is an endless stream of cash flows (C_i) starting at the end of the year i (e.g. Consols). Assuming constant interest rates, mathematically it means summing up the following infinite GP:

\begin{aligned} \displaystyle PV(P) &= \frac{C_1}{1 + r} + \frac{C_2}{(1 + r)^2} + \frac{C_3}{(1 + r)^3} + ... \\& = \sum_{i=1}^{\infty} \frac{C_i}{(1 + r)^i} \end{aligned}

If the problem at hand warrants assuming constant cash flows, i.e. if C_i = C \forall i this simplifies to:

\begin{aligned} \displaystyle PV(P) &= \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + \frac{C}{(1 + r)^3} + ... \\& = \sum_{i=1}^{\infty} \frac{C}{(1 + r)^i} \\&= \frac{C}{r} \end{aligned}

Perpetuities are not so important as financial instruments, but the formula/derivation for PV(P) as above is immensely useful in simplifying calculation of PVs of annuities, as we’ll see below.

Annuities

An annuity (A_n) for a term n is a finite stream of cash flows (C_i) starting at the end of the year i. Annuities can be interpreted both as payments to be made (EMIs, regular savings from your salary, recurring deposits) as well as payments to be received (coupon payments from a bond). Mathematically, of course, it’s just summing up the following finite GP:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C_1}{1 + r} + \frac{C}{(1 + r)^2} + \frac{C_3}{(1 + r)^3} + ... \frac{C_n}{(1 + r)^n} \end{aligned}

First of all notice that we can write an annuity as a function of the discount factors DF_i as:

\begin{aligned} PV(A_n) &= C_1 DF_1 + C_2 DF_2 + ... + C_n DF_n \\&= \sum_{i=1}^{n} C_i DF_i \end{aligned}

So, if we consider all cash flows C_i = 1, then we have the Annuity Factor AF_n for term n as:

\begin{aligned} AF_n &= DF_1 + DF_2 + ... DF_n \\&= \sum_{i=1}^{n} DF_i \end{aligned}

Tip 2: If you have manageable number of terms (say, less than 4-5) in a situation, and you’ve already calculated some of the DFs already as part of the problem, then use the discount factor way to find the PV of the annuity. It’ll not only be easier (i.e. you’ll perhaps make less mistakes) but also save time. Otherwise, use the formula in the textbook/as we derive below.

Just like for perpetuities, if the problem at hand warrants assuming constant cash flows, i.e. if C_i = C \forall ithis simplifies to:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + \frac{C}{(1 + r)^3} + ... \frac{C}{(1 + r)^n} \end{aligned}

Tip 3: Now one way to sum it up is to use the formula for summing finite GPs, but that’s messy – and it will only get worse when you have an annuity which is growing/falling. We exploit our derivation for perpetuity here. Write:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + \frac{C}{(1 + r)^3} + ... \frac{C}{(1 + r)^n} \\& + \big[ \frac{C}{(1 + r)^{n + 1}} + \frac{C}{(1 + r)^{n + 2}} + ... \big] - \big[ \frac{C}{(1 + r)^{n + 1}} + \frac{C}{(1 + r)^{n + 2}} + ... \big] \end{aligned}

where we have just added and subtracted a term going to perpetuity. Write:

\displaystyle A_1 = \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + ... + \frac{C}{(1 + r)^n}

\displaystyle \begin{aligned} A_2 &= \frac{C}{(1 + r)^{n + 1}} + \frac{C}{(1 + r)^{n + 2}} + ... \\& = \frac{1}{(1 + r)^n} \big[ \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + ... \big] \\&= \frac{1}{(1 + r)^n} \sum_{i=1}^{\infty} \frac{C}{(1 + r)^i} \end{aligned}

Clearly A_1 + A_2 is:

\displaystyle \begin{aligned} A_1 + A_2 &= \frac{C}{1 + r} + \frac{C}{(1 + r)^2} + ... + \frac{C}{(1 + r)^n} + \frac{C}{(1 + r)^{n + 1}} + \frac{C}{(1 + r)^{n + 2}} + ... \\&= \sum_{i=1}^{\infty} \frac{C}{(1 + r)^i} \end{aligned}

That is, we can simplify PV(A_n) as:

\begin{aligned} \displaystyle PV(A_n) &= (A_1 + A_2) - (A_2) \\&= \sum_{i=1}^{\infty} \frac{C}{(1 + r)^i} - \frac{1}{(1 + r)^n} \sum_{i=1}^{\infty} \frac{C}{(1 + r)^i} \\&= \frac{C}{r} - \frac{1}{(1 + r)^n} \frac{C}{r} \end{aligned}

Notice how we have used the the’perpetuity A_2 to our advantage to convert our original annuity into perpetuity and then subtracted back A_2.

We have now the final result for PV(A_n):

\displaystyle PV(A_n) = \frac{C}{r} \big[ 1- \frac{1}{(1 + r)^n} \big]

Growing Annuities

If we have a growing annuities (either upwards or downwards), then our expression PV(A^{g}_n) changes to:

\begin{aligned} \displaystyle PV(A^{g}_n) &= \frac{C}{1 + r} + \frac{C(1 + g)}{(1 + r)^2} + \frac{C(1 + g)^2}{(1 + r)^3} + ... \frac{C(1 + g)^{n - 1}}{(1 + r)^n} \end{aligned}

If we take out the factor \displaystyle \frac{1}{1 + r} from the above equation we end up with a finite GP again, but with a different common ratio – in this case \displaystyle \frac{1 + g}{1 + r}.

Repeat the same steps as earlier (write PV(A^{g}_n) again as a difference of two perpetuities – only the common ratio is different) and we end up with a similar result for growing annuities. Let’s outline the proof:

\begin{aligned} \displaystyle PV(A^{g}_n) &= \frac{C}{1 + r} + \frac{C(1 + g)}{(1 + r)^2} + \frac{C(1 + g)^2}{(1 + r)^3} + ... \frac{C(1 + g)^{n - 1}}{(1 + r)^n} \\& + \big[ \frac{C(1 + g)^n}{(1 + r)^{n + 1}} + \frac{C(1 + g)^{n + 1}}{(1 + r)^{n + 2}} + ... \big] - \big[ \frac{C(1 + g)^n}{(1 + r)^{n + 1}} + \frac{C(1 + g)^{n + 1}}{(1 + r)^{n + 2}} + ... \big] \end{aligned}

Again, we can similarly define A^{g}_1 and A^{g}_2, and go through exactly the same steps to show that:

\begin{aligned} \displaystyle A^{g}_1 + A^{g}_2 &= \sum_{i=1}^{\infty} \frac{C(1 + g)^{i - 1}}{(1 + r)^i} \\&= \frac{C}{r - g} \end{aligned}

And we end up with final result as:

\displaystyle PV(A^{g}_n) = \frac{C}{r - g} \big[ 1- \frac{(1 + g)^n}{(1 + r)^n} \big]

Note that there is nothing in the above formula that prevents g from being negative. g can very well be less than 0 – that would be the case where our future cash-flows are going down in a systematic manner.

Some other Things to Remember

1. When there is only a single unit cash flow (i.e. C_n = 1) in the future, the following relationships hold:

\displaystyle PV_n = DF_n

\displaystyle FV_n = \frac{1}{DF_n}

2. For an annuity with constant cash flow every year we can talk about an Annuity Factor (AF_n) as:

\begin{aligned} AF_n &= DF_1 + DF_2 + ... DF_n \\&= \sum_{i=1}^{n} DF_i \end{aligned}

3. In general, one may think of PV of a unit sum of cash flow n years later with compounding k times a year as the following general expression:

PV_n = \displaystyle \frac{1}{(1 + \frac{r}{k})^{nk}}

And accordingly, the general expression for an annuity with a unit sum received k times a year becomes:

\displaystyle \sum_{i = 1}^{nk}  \frac{1}{(1 + \frac{r}{k})^{i}}

The Inflation Problem

This is with reference to a couple of problems around inflation in the textbook. The inflation problem is just an application of the idea of a growing annuity. In presence of inflation, for your consumption to remain the same in ‘real’/quantity terms, annual cash-flows must grow at a rate commensurate with the inflation rate – i.e. the cash-flows must grow that match the inflation rate.

The only difference is that, because our typical annuity starts at the end of the year, unlike the earlier case of a growing annuity, our first annuity payment in this case would also be higher by a rate equivalent to the inflation rate.

So, if the inflation rate is known (that is, we know it’s going to remain the same for the entire horizon), then the expression for this annuity will be:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C(1 + g)}{1 + r} + \frac{C(1 + g)^2}{(1 + r)^2} + \frac{C(1 + g)^3}{(1 + r)^3} + ... \frac{C(1 + g)^n}{(1 + r)^n} \end{aligned}

So, in this case we can factor out \displaystyle \frac{1 + g}{1 + r} and we are again left with a GP with a common ratio \displaystyle \frac{1 + g}{1 + r}. Nothing else changes.

And if we now write

\displaystyle \frac{1 + r}{1 + g} = 1 + \rho

\begin{aligned} \displaystyle \Rightarrow \rho &= \frac{1 + r}{1 + g} - 1 \\& < r \end{aligned}

then we can rewrite PV(A_n) as:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C}{1 + \rho} + \frac{C}{(1 + \rho)^2} + \frac{C}{(1 + \rho)^3} + ... \frac{C}{(1 + \rho)^n} \end{aligned}

which is just a normal annuity, but with a different discount rate \rho. And what is this discount rate \rho? Think of it as the ‘real’ interest rate that applies in the presence of inflation. That is, in presence of inflation our effective discount rate goes down (why?).

The inflation problem is just an application of the idea of a growing annuity. In presence of inflation, for your consumption to remain the same in ‘real’/quantity terms, annual cash-flows must grow at a rate commensurate with the inflation rate – i.e. the cash-flows must grow that match the inflation rate.

The only difference is that, because our typical annuity starts at the end of the year, unlike the earlier textbook case of a growing annuity, our first annuity payment in this case would also be higher by a rate equivalent to the inflation rate.

So, if the inflation rate is known (that is, we know it’s going to remain the same for the entire horizon), then the expression for this annuity will be:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C(1 + g)}{1 + r} + \frac{C(1 + g)^2}{(1 + r)^2} + \frac{C(1 + g)^3}{(1 + r)^3} + ... \frac{C(1 + g)^n}{(1 + r)^n} \end{aligned}

So, in this case we can factor out \displaystyle \frac{1 + g}{1 + r} and we are again left with a GP with a common ratio \displaystyle \frac{1 + g}{1 + r}. Nothing else changes.

And if we now write

\displaystyle \frac{1 + r}{1 + g} = 1 + \rho

\begin{aligned} \displaystyle \Rightarrow \rho &= \frac{1 + r}{1 + g} - 1 \\& < r \end{aligned}

then we can rewrite PV(A_n) as:

\begin{aligned} \displaystyle PV(A_n) &= \frac{C}{1 + \rho} + \frac{C}{(1 + \rho)^2} + \frac{C}{(1 + \rho)^3} + ... \frac{C}{(1 + \rho)^n} \end{aligned}

which is just a normal annuity, but with a different discount rate \rho. And what is this discount rate \rho? Think of it as the ‘real’ interest rate that applies in the presence of inflation. That is, in presence of inflation our effective discount rate goes down (why?).

One Last Tip

When all else fails, use ab initio. For any cash flow that you are supposed to value list down the ‘time-axis’ on the first row (0 --- 1 --- 2 --- 3 --- 4 --- ... --- N), and below that list down all cash flows (with their right sign) of a kind (cash flow from each activity/operation on a separate line/row. This would make sure you’re counting each cash flow at the ‘right’ time (and not more than once). Now just bring back all of them to separately time 0 and sum them up. And you are done.

Variations on the time value of money problems are situations when one knows the PV (your car/home loan for example), and you have to do some algebra/arithmetic to find some regular cash flow (your EMI). At others times when you know the cash flows and you may have to find the PV. (Always try and do the algebra first and then plug in the numbers as a last step – more often than not algebra helps simiplify the final expression and reduce possibility of silly mistakes. Though, of course, this may all be moot, as these days you’ll be probably using some software like Excel to do the job for you. Doesn’t hurt to know the principles though.)

It is an urban legend that Albert Einstein said that compound interest is the most powerful force in the universe – the Indians perhaps didn’t think through it!

Compound Interest

Written by Vineet

August 18, 2016 at 1:08 pm

[WP] Open access temptations

leave a comment »

Information science isn’t exactly my area of research, but it has been fun exploring the shady side of open access. Here is the abstract:

Backlash against “megapublishers” which began in mathematics a decade ago has led to an exponential growth in open access journals. Their increasing numbers and popularity notwithstanding, there is evidence that not all open access journals are legitimate. The nature of the “gold open access” business model and increasing prevalence of “publish or perish” culture in academia has given rise to a dark under-belly in the world of scientific publishing which feeds off academics’ professional needs. Many such “predatory” publishers and journals not only seem to originate out of India but also seem to have been patronized by academics in the country. This article is a cautionary note to early-career academics and administrators in India to be wary of this “wild west” of the internet and exercise due discretion when considering/evaluating open-access journals for scholarly contributions.

The working paper is here.

Written by Vineet

April 7, 2016 at 3:14 pm

Posted in Research

Tagged with , ,