Monday, July 11, 2016

Statistical Analysis of the SENSEX - Probability distribution of Local minima

So I have decided to revive my blog but as I now have a toddler who just yanked the power cable from my laptop..I will have to be quick with this article :)

Recently, while I was debating the pros and cons of Mutual fund investments with a few of my colleagues, the topic of "timing" the market came to be discussed. While it is common knowledge that it is impossible to predict the ups and downs of the market indices (like the SENSEX) on a day to day basis, I felt that a long term data analysis should yield something interesting. Even purely random events have a Gaussian distribution after all.

So I pulled up the last 37 years of daily closing values of the SENSEX from here and did the following
1) Found the minimum values of the Index on a monthly basis
2) Found the date and the day of the week that minimum value was reached

The probability distribution of the SENSEX hitting the lowest value in a month is as depicted below where the first chart illustrates the Day of the week probabilities while the second displays the Day of the month distribution.









Interesting Data Analytic conclusions
1)  The 1st day of the Month and Wednesdays are when the probability of the SENSEX being the lowest are the highest
2) The 15th of the Month and Fridays are the converse

I havent really got down to thinking about why this is the way it is but probably a lot of investments like SIPs get auto debited and channeled to the market in the beginning of the month causing a dip in prices but the data reveals that if you are dealing with index funds its better (statistically speaking) to buy during the first week of the month and sell by the 15th to maximize good return probability.

NOTE: I shall not be responsible for any losses incurred by anyone treating the above data analysis as a Stock tip. I am still recovering from my own :)


Wednesday, October 22, 2014

Infinity - Is a physical interpretation posible?

Infinity is an interesting subject indeed but its one that is lightly brushed over in most mathematical treatments.
Over the course of numerous discussions I have had with peers and friends, it has become apparent that by and large the "average" understanding of infinity is
1) It is a very large number
2) Its obtained as a result of an undefined operation (like division by zero)

These are wrong and do not even give a cursory view of what Infinity is. The subject of Infinity is beyond the scope of a single blog post but I will attempt to highlight a few of the special properties of Infinity which I think are fundamentally important. I will also briefly allude to more interesting characteristics but will have to leave that for some other day.

Alright, so lets see, what do we start off with? Lets start with two basic statements
1) Infinity is not a number, it is a concept
2) There are no infinities in physical reality

Lets illustrate these two aspects using a simple divergent series, also called the Grandi Series which is just a series of alternating negative and positive ones. Let us call this series S.

S = 1-1+1-1+1-1+1-1+1-1...............................

Now, if asked to express the sum to n terms of this series, it is quite apparent that there are two ways of looking at it

S = (1-1)+(1-1)+(1-1)+................................∞ = 0
or
S = 1+(-1+1)+(-1+1)+...................................∞ = 1

so essentially, depending on whether we choose to terminate the series at an even or an odd number we have either 0 or 1. Pretty simple isn't it?
Lets take another look at it now.
Let us take S and add it to itself so that we have
 
  S =  1-1+1-1+1-1+1-1+1-1...............................
+S =       1-1+1-1+1-1+1-1+1-1............................
----------------------------------------------------------------------------------
2S = 1+0+0+0+0....................................................0
 
Here, the second S had been slightly shifted to allow for ease of demonstration. All terms after the first, cancel each other out. Thus we have
2S = 1
S = 1/2
In essence, the sum of a infinite series comprising of integers is 1/2? Doesn't that sound surprising? It should. In fact it should be shocking, because this is true. Why do two methods yield such different results?
In the first case, we treated the series as infinite but forced it terminate at an even or an odd number of terms (which essentially is NOT infinity as that is not a number). The second proof made no such assumption and the series was continued ad infinitum.
Proof of this and other such sums are consistently used in M-Theory (String theory) and yield results.
The biggest conundrum is how do we reconcile this result with the physical world? Can we?
 
Let us assume that the 1 and -1 represent the states of a switch that turns on a light so that the light is either on or off and someone is rapidly flipping the switch.
If the switch is being flipped very very rapidly and you are asked if the light is on or off? What would you say?
Lets look at it another way. What would you say is the probability that the light is ON or OFF for that matter? 1/2 isn't it?
 
This does not imply that the 1/2 obtained as a sum of the series is somehow linked to the probability distribution of a light going on and off but nevertheless, this thought experiment is a bridge between a completely mathematical construct and physical reality.
 
Infinity is far more interesting with there being orders of infinity as well. So essentially there are some infinities which are "bigger" than other infinities. Interested folks can read up on Cantors theories. I will leave them for another day.
 
Adios....

Sunday, December 1, 2013

Life and the Central Limit Theorem - An asscociation made in mathematical heaven

Too often in life we tend to generalize and associate individual behavior with the behavior of a group. Many of our social biases stem from such a tendency and what we fail to appreciate is the wonderfully complex world we live in.
The Central Limit theorem is one of those beautifully constructed mathematical models that seek to bring about a semblance of order in a chaotic world. In its simplest formulation, it provides a way of visualizing the behavior of seemingly random events. It essentially is a mathematical model of life, a life that involves a myriad of possibilities, a plethora of possible outcomes - some good some bad.
The simplest demonstration of this theorem can be obtained by the roll of an unbiased dice. If we roll one dice then at every roll we can land up with any of the six numbers from 1 - 6 and the probability of occurrence of any of these digits is the same and equal to 16.66%
However, if we now roll two dice and evaluate the sum of the digits that show up then the total number of possible outcomes goes up to 11 with the probability of a 7 showing up now being the highest. The probability is not longer uniformly distributed. This is because 7 can show up as a result of the following combinations
1 - 6
2 - 5
3 - 4
4 - 3
5 - 2
6 - 1

If we start rolling more dice simultaneously and repeat the analysis, the distributions creeps closer and closer to a normal distribution yielding the simplest demonstration of the theorem. I have coded the algorithm for evaluating this in a spreadsheet and it is available here and you can try it out. The only input required is the number of dice that you want to roll together and hit "Calculate". The code evaluates the total number of outcomes possible and then then probability distribution is plotted.
Caution: Owing to the mathematical complexity of evaluating the total number of combinations which rises exponentially with larger number of dice, do not input more than 6 as it is likely to crash your PC ( if its a 32 bit CPU). If you have a 64 bit processor then you can try a bigger number

PS: Code could have probably been written to use recursion but got lazy and hence relied on mathematical jugglery.
Case 1: When one die is used. Number of possible combinations and outcomes is 6



Case 2 : With two dice the number of combinations is 36 and outcomes is 11


Case 3: With 6 dice the number of combinations is 46656 and outcomes is 31


The moral is that a lot of unrelated events can still lead to something that is so wonderfully symmetric and this applies to more aspects of our lives then we care to think about. From the noise that affects electronic circuits (Additive White Gaussian Noise) to how the marks/ratings will be distributed among a random selection of individuals to why individuals in a group behave differently than when alone ( Mob psychology), patters of behavior and data are often more relevant than individual behavior.
As individuals we make choices but given the random nature of individual choice, the outcomes follow a Gaussian distribution which we unwittingly contribute to. Extreme cases of success and failure are the outliers on this curve while humanity's choice as a whole is the mean. Making choices closer to the mean would imply a higher probability of favorable outcome but if everyone does it then it takes away the importance of individual choice.
Neo : "Choice, the problem is choice." - Matrix

Friday, July 26, 2013

Fast and Furious - 1st Gear (Bangalore Edition)

Bangalore - The second most affluent city in India, a city that millions call home and a subset of those millions also call it an obstacle course.
The Government of India has stipulated that a Drivers License obtained anywhere in India has national validity. I beg to differ. A DL just says that you "may" legally be allowed to drive. The roads in Bangalore begs the question.... CAN you drive..PUNK? (Read this out aloud imagining yourself to be possessed by Nana Patekar to get the drift)
In order survive the daily ordeal, here are a few tips that can help you keep a check on your sanity.

The Mental Preparation:
As any good Bangalorean will tell you, the brain is the most important organ in the human body...on weekdays. On weekends, the kidneys/liver and lungs call the shots. However, I digress, a day of office commute should begin with a deep breath and empty bowels. Watching inspirational and motivational videos is a good start but if you are pressed for time then try convincing yourself that you love driving.Over a period of time you may be able to actually convince yourself that you like driving, this is a variation of self hypnotic therapy and is useful in some cases.

The Physical Preparation:
Eat a healthy breakfast, go light on fluids (unless you are carrying adult diapers). Light stretching focusing on the calf muscles, triceps and wrists is essential. As always, try doing the exercises in sets and with a predefined rhythm. I have personally found that repeating the phrase "Clutch, Gear, Brake" repeatedly while working out is a healthy outlet and helps in both
               a) Mental Preparation
               b) Physical Preparation
and is a mantra that you can repeat as often as you like during the drive

The Car: 
Whether you have  Reva or a BMW, you need to forget that your car has anything beyond 1st and 2nd gear. I have heard rumors of  roads where the courageous have shifted to 3rd but there are no confirmed reports. Always ensure that you are not low on fuel and stock you car with supplies like you would if you knew that a zombie attack was imminent. Know how to work the controls, with one hand/foot, simultaneously..and yes, I mean the brakes too. Your other appendages can then productively be engaged in fiddling with your smart phone. Get a seat with Lumbar Support. I have heard that the Cab drivers here have a seat that has a protruding spike placed below the posterior which juts out at random times. It is supposed to improve your driving skill but has the undesirable side effect of causing rapid accelerations, sudden brakes and wild turns.

The Road:
Ha ha..got you!! What road?

The Potholes:
At first glance you may mistakenly assume that you drove out of your apartment and landed on the surface of the moon and start postulating on whether it was a wormhole or a manhole that got you there but not so fast. These potholes are a major tourist attraction and there are actually major roads that have been named after the potholes. 80ft road and 100ft road are such roads where the depth of the pot holes are 80ft and 100ft respectively. Some "outsiders" think that the names allude to the width of the roads...such ignorance!! These potholes have numerous advantages
1) The water accumulated in these potholes percolates and replenishes the ground water level
2) They act as well designed speed breakers.They are guaranteed to break more than your speed and are regarded as engineering marvels.
3) They keep drivers constantly on alert and many have actually reported that so keen is their focus on the potholes that they do not look at road signs or landmarks.The potholes are like playing a game of connect the dots. It takes out the monotony of driving.

Above all,  be positive, your car has a Power steering and Disc Brakes for a reason, use them. To be a successful car driver in Namma Bengaluru you need to lose the fear, lose the fear of death,disability and car repairs and you shall prevail.
So repeat after me  Clutch, Gear , Brake.. Clutch , Gear, Brake............Accel..BRAKE!!!!

Friday, May 17, 2013

Home Loans Vs Renting - Cost of Ownership




Should I buy a house and spend the next 20 -25 years of my life worrying about an EMI or should I just live as a Tenant?

This question seems to have as many answers as people you choose to ask. The fact is that there are aspects of this deal which are hard to pin down in numbers and most people tend to justify the decision that they have themselves made. I have seen many articles written on this but I think that rather than presenting a conclusion, what is really needed is to have all the aspects listed out so that people are provided with something that they can try and figure out for themselves.

This link has a spreadsheet(Loan_Feasibility.xlsx) that I have shared and can be downloaded. I will, in the following paragraphs describe how this works along with the assumptions that have been made. I hope this is useful for all those who are in the midst of taking this decision.

Listed below is a screen shot of how the spreadsheet looks like and the section by section explanation of the various fields follows

Input  Paramters:

Property Value: This is where you need to enter the current value of the property you are after
Own payment: This is the amount that you can pay up front for the property
Loan: This is auto calculated based on the above listed inputs
Loan Interest Rate: This is an Input parameter and you can plug in the expected ROI for your loan
Loan tenure(months): Self descriptive input parameter. Should be < 300 months (25 years)
Annual Inflation: This is another input parameter that is a critical factor to be considered
Rent: This is the monthly rent that you would expect to pay if you stay in a SIMILAR property.
EMI: This is auto calculated based on the loan amount, interest rate and tenure provided.

All the rest of the fields are auto calculated based on the inputs and the following sections describes how these are being calculated. You can play around with the excel to factor in additional details if needed. There are no macros in the spreadsheet, just cell formulas, which are easy to manipulate.

Owned Apt Cost:

Loan Repaid: This is the total amount of loan repaid (EMI*tenure)
FD loss (own Payment): This is the amount that you would have had if you had invested in a FD instead of paying the down payment for the property. Assumed annual cumulative return@Inflation for duration of the Tenure
Tax Savings (30%): The current 1.5L rebate on income tax is factored in here. Assuming a tax bracket of 30%

Rented Apt Cost:

Rent paid: This is the total amount that will be paid out as rent over the duration of the tenure. The assumption here is that the rent increases@Inflation every year.
EMI Savings: This is the savings that would accrue for you if you go in for rent rather than paying an EMI. The calculation also accounts for the fact that the savings is invested and earns interest@Inflation for the relevant duration i.e for a 20 year tenure, the savings of the first year earn interest for 20 years,the savings for year 2 accrue interest for 19 years and so on. Also note that with the rent increasing @Inflation every year it will get to a point where rent becomes higher than the EMI (which is fixed) and hence at that point, the savings become negative. This has also been accounted for.

Conclusions:

 Difference b/w Ownership Cost and Rent: This is the difference between the two costs i.e cost of ownership - cost of renting.
Current value of Asset: This is the current value of the asset.Assumption is that the appreciation was @Inflation
Net Worth(Ownership): This is the price of the asset minus the cost incurred

Net Worth (Rent): This is the amount expended when living as a tenant

Difference: This is your perceived net worth after the end of the tenure

*Points to Ponder

1) The difference between the EMI and the rent that you would have to pay for a SIMILAR property has a significant bearing on the outcome so validate this assumption. Saying that the property price is 90L for a 3 BHK and then comparing it against paying a rent of 10,000 is illogical simply because if you are actually planning to buy a property worth 90L then it has to have the amenities/environment etc that should command a higher rent.
2) The rate of Inflation is being used to calculate the returns on FD, increase in Rent as well as appreciation in property price. This is realistic but honestly speaking  it is a convenience to make such an assumption but for the calculation intended here, it should suffice.
3) The final asset value also has a huge bearing on the outcome. Be realistic about it. The calculation assumes appreciation @Inflation for the tenure of the loan. This will never happen in the long run so adjust this accordingly. Over the last 5 years however, this logic seems to have held good.
4) Try and keep your EMI to be around 40-50% of your take home salary. Its a safer bet.
5) One obvious thing that is not factored in here is the part prepayment possibility as that is difficult to estimate. However, this too can have a very significant bearing on the total amount you dish out for the loan.

Please play around with the spreadsheet and try out different combinations of the Input paramters to see the effect on the outcome. My favorite calculation was to first decide on a property price/loan details and then play around with the rent parameter to bring the Difference b/w Ownership Cost and Rent as close to Zero as possible. This would give you the "equivalent" rent.

Example:  

In the snapshot given above, the Property price is 90L,down payment was 30L for a Loan Tenure of 20 years@11%. Inflation is at 8% and Rent is 25K.
Overall it shows that the net worth of the person owning the property would be 87L higher then a Tenant.

If you play around with the Rent parameter then the equivalent rent in this scenario will turn out to be 
Rs 41155

Happy decision making!!! Ending with a few lines by a great man

"Ownership has a cost but also brings joy
Leverage your credit, don't be coy
Or chill for a while, pay the rent
Maybe the Earth will expand and you wont repent"- Samrat (A tormented EMI payer) :-)