Thursday, April 15, 2021

another dice game (expected value)

This is a question I often ask(ed) in interviews: 

Alice charges you $1 to play a game. She rolls a (fair) die 3 times. You win if the rolls are in strictly increasing order e.g. 1, 5, 6. You lose otherwise e.g. 1, 3, 3 or 2, 6, 1. Question is, how much should she pay you when you win, for this to be a fair bet? 

To answer this question correctly, you need to consider all cases, count them properly, and then use the formula for expected value. 

There are 216 different combinations of 3 dice - starting from (1, 1, 1) going all the way to (6, 6, 6). of these, we want to only include the ones that are strictly increasing. If we count them carefully, we find 20: (1, 2, 3); (1, 2, 4); (1, 2, 5); (1, 2, 6); (1, 3, 4); (1, 3, 5); (1, 3, 6); (1, 4, 5); (1, 4, 6); (1, 5, 6); (2, 3, 4); (2, 3, 5); (2, 3, 6); (2, 4, 5); (2, 4, 6); (2, 5, 6); (3, 4, 5); (3, 4, 6); (3, 5, 6); (4, 5, 6)

That is 20/216. So you win in 20 cases, and lose your 1$ in 216-20= 196 cases. So, to make up, you need $x such that: x*20=196*1 or x = 9.8$

The difficulty in solving this problem is not so much in the math, but in the mechanics. It takes work, most candidates are not willing to put in the effort during the interview. I'm more than happy to overlook counting errors (after all, an interview is a somewhat high pressure setting) but do expect to see how they think through the problem. 

Solving this problem in python is quite easy. Code is below to enumerate all cases and pick out the right ones. The expected value calculation is trivial once this is available.

import itertools;

x=[i for i in itertools.product(range(1,7),repeat=3)]; # all 3-dice score combinations possible

print(len(x)) # computer prints 216

y=[i for i in x if i[0]<i[1] and i[1]<i[2]]; # all 3-dice score combinations where you win

print (len(y)) # computer prints 20


A (cursory) look at ESG investing

Lately, a lot is being said about ESG (Environmental, Social and Governance) sensitive investing. Many claims are made about how people these days are more aware of environmental issues with one eye on global warming, etc. However, change begins at home with each and every one of us, we shouldn't just wait for others to change to save the planet. Regardless, this post is about ESG investing, so let's get to it. 

The UN has published a list of 17 SDGs or Sustainable Development Goals. These can be classified into 5 categories called the 5 Ps - the focus is on People, Planet, Prosperity, Peace, and Partnerships. The goals are: No Poverty; Zero Hunger; Good Health & Well-being; Quality Education; Gender Equality; Affordable and Clean Energy; Decent Work and Economic Growth; Industry, Innovation and Infrastructure; Reducing Inequalities; Sustainable Cities and Communities; Climate Action; Life Below Water; Life on Land; Peace, Justice and Strong Institutions; and Partnerships for the Goals. 

read more about UN SDGs here 

Socially Responsible Investing (SRI) or Impact Investing is effectively applying similar (but not necessarily the same) principles for value-driven investing. The goal is to do social good as you invest - integrating ethical and social causes into your investment framework. 

ESG is a more broad-based structure within whose context people try to incorporate various aspects of the SDGs and the SRI frameworks to invest money in ways that benefit society and the planet as a whole. 

Ben Felix explains some of the considerations in this interesting video: 

A useful description of an ESG framework in practice comes from Stashaway, a robo-advisor in Singapore that went from starting up to over 1B$ in AUM in less than 5 years! (I am not affiliated with them). 

read more from Stashaway.sg on this topic here 

Cliff Asness (AQR Capital) says in a recent interview, if you cut out a part of the investment universe that introduces additional constraints into the process and cannot by itself be value accretive. However, in recent years ESG is having an impact in the way corporates are able to raise funds. 

watch from youtube: AQR's Asness explains the quant view on ESG investing

Let's say you have 1M$ to invest. If cigarette making companies give you higher returns, you would invest there. However, if more and more people shun these investments on an ethical basis and money flows into say, Solar or Wind power companies, then the so called "sin industries" - cigarettes, gambling, etc. will have some trouble raising funds leading to an increase in the interest they have to pay, thereby raising their internal project hurdle rate, so less projects get funded and growth slows. Or so the theory goes. But if investors are all focused on the so called sustainability-friendly firms, this trade gets crowded, the stocks get bid up, and these pricier assets generate lower returns overall as a result.

Of course, just because a board is more diverse ("diversity takes time, but inclusion can be immediate" as some people like to say regarding the DNI or Diversity aNd Inclusion movement), or a company is more socially responsible, there are no guarantees that the company generates better revenues. However, it does stand to reason that a company that takes good care of its stakeholders - suppliers, consumers, and the entire supply chain - as opposed to just the shareholders in the company - would better weather the inevitable storms that every business has to face. So then, is ESG investing more an attempt to protect the downside vs. capture the upside of various investments? 

Litigation around environmental, social and governance (ESG) issues is on the rise, with both civil and criminal cases being heard by courts around the world. Such litigation poses not only financial risk but also reputational risk to the corporations involved. This trend therefore adds an additional layer of investment risk to companies with weak ESG metrics.                       -- Gregory Kunz, Head of Research, Pictet Asset Management (article)

When the last major financial crisis happened, there wasn't this much attention paid to the ESG movement, so we do not know how various firms weathered the volatility that resulted (rather, we can figure how they reacted to volatility during that period, but due to lack of ESG being mainstream, we cannot claim that the reaction factored in ESG aspects). However, people like to claim that in 2020 with Covid, corporates with higher (better) ESG scores outperformed the competition. There are research papers that indicate that it wasn't that environmentally aware companies did better but that the less environmentally friendly sectors were badly impacted due to stay-at-home restrictions and business closures. Lower demand for oil due to slowing growth is not necessarily an ESG driven theme, though perhaps the gradual shift towards electric vehicles is. It helps if savvy investors look deeper to understand the various drivers that move stocks in various sectors, and use that as a basis for drawing conclusions as opposed to just picking a favorite cause and running with it.

A fascinating course on Coursera offered by Erasmus University called "Principles of Sustainable Finance" explores these and other ideas from both sides and presents what I think is a fair and balanced view of the topic, all while educating us on what Sustainable Investing really means. Worth the time.

We can try to save the planet (we live here after all), invest wisely, and make money while doing good. Everyone wins. 

Using Simulation to Solve Probability Questions

Professor P runs two experiments: in A, he rolls a die till he gets two consecutive 6s. In B, he rolls a die till he gets a six followed by a 5. After running each experiment 100,000 times, he takes the average number of rolls needed - for A this number is x, for experiment B, this is y. The question is, is x=y? True or False?

The naive or lazy reader usually concludes that the answer is True. But this is not so. Let's think through this. 

In A, if he rolls a 6 and then rolls a different number, he has to start all over. In B, if he rolls a 6 and then rolls another number that is not a 6, he has to start over. But in B, if he rolls two sixes, he doesn't start over, he has another chance to try to roll a 5. This means that y < x in average. But how do we prove this? Mathematically, this can be done using the principle of iterated expectation. A well-written solution is available here. This tells us that the average number of rolls for A is 42, and that for B it is 36. 

In this post though, let's look at how to solve this problem if you are not able to do the slightly involved math. Simulations are a great way to do this. And python makes it simple beyond describing. Let's look at code: 

import random as r; 

def die_roll(): return r.randint(1,6); 

# experiment A
x=[]; # store the results of the simulation
for i in range(100000): 
 t=[die_roll(), die_roll()]; 
 while t[-1]!=t[-2] or t[-1]!=6: t+=[die_roll()];
 x+=[len(t)];

print(sum(x)/float(len(x))); # computer prints 42.06674

#experiment B
x=[];
for i in range(100000):
 t=[die_roll(), die_roll()]; 
 while t[-1]!=5 or t[-2]!=6: t+=[die_roll()];
 x+=[len(t)];

print(sum(x)/float(len(x))); # computer prints 36.08444

As you can see, a relatively lazy 5 minute piece of code can generate the same answers quite comfortably and makes it possible for us to confidently answer questions like this one. 

Why do interviewers ask questions like this in financial services interviews? 
This kind of evolution of a number series (through die rolls here) with the end of the series being defined by the first time a particular score appears similar in many ways, to the evolution of price movements and the pricing of knock-out options. True, the mechanics of option pricing is quite well defined in literature and there are formulas for achieving that, but in an interview setting the interviewer is trying to assess whether the candidate is able to think through issues like this and propose a method to solve this kind of problem. When I conduct interviews (and I have conducted several hundred over the years), I tell the candidate up front I don't care what numeric answer they come up with, I just want  to understand their approach to solving these problems, and what they are thinking.



The real cost of things

If there was something that was fairly cheap to buy and use, provided convenience or pleasure, but meant either that a. you would have longer term ill-effects from the use of the product, or b. that the product became progressively more expensive to use, you would find some ways of avoiding the product in question. 

Several examples of this kind of situation abound: 
  1. Cigarettes provide short-term pleasure and are known to cause cancer longer term.
  2. Recreational drugs of various kinds fall into a similar category - near term high, longer term brain damage
  3. Adrenaline junkies take larger and larger risks to get the rush, sometimes sacrificing safety risking severe injury or loss of life and limb.
In all these cases, taking a longer term view would help people make wiser choices. But what about situations where the quality of your choice changes with time? Let's look at a couple of examples of these:
  1. You buy shampoos, perfumes, and mouthwash in small containers - you know you'll use up larger quantities, but buy smaller containers for convenience, but the plastic is not biodegradable, and the ecosystem chokes up
  2. Garments you purchase are synthetic - similar issue - and with rapidly changing fashion, they get outmoded and are discarded quickly but do not disintegrate.
Even 15 years ago, these might not have been considered particularly bad ideas, but they would be frowned upon now. Single use plastics are another such item - utility is for limited time, but the damage caused is long lasting. This balance is to be set right if we believe we do not inherit the planet from our parents but borrow it from our children. There was even a recent article in the news that adults on average ingest a credit-card's amount of plastic each week through the food they consume. Microplastics are now invading water supplies, aquatic life, and other areas of the ecosystem that impact humans.

The true cost of a good thus, is not just the cost of its production, distribution and sale. The true cost should include the cost of harvesting the waste generated and recycling it away from the environment. As regulation ramps up (as it must), prices will reflect environmental realities. True, for a while corporations and people can get by through regulatory arbitrage, but this will likely be a limited period before laws are stringently enforced globally. In a related post in this blog, I explore some interesting ideas companies are pursuing in terms of becoming more planet-friendly. 

As individuals we cannot by ourselves solve global issues such as plastic pollution, but if we move together, convince our friends, etc. The movement can change the planet for the better. There are some outstanding efforts like the man who started a movement to clean up Versova Beach in Bombay, the couple that worked to re-forest areas of Latin America, and the movement to plant new trees in Singapore.

Saving our planet is not Greta Thunberg (or other young people)'s responsibility alone. We all live here. We all need to take an interest and do what little we can do to protect and conserve natural resources. As they say, "reduce, reuse, recycle". It appears that a greater awareness and adoption of ESG principles in investing will force a gradual movement in that direction.