Friday, June 17, 2016

Now reading...

 laced with profanity, but makes for good reading. not your typical self-help book.
 this book unexpectedly made my top 10 of all time... so far. unforgettable, if only because the (simple) story is so moving. to me, it is not just about a little boy or about a monster. it is about all of us, and how we deal with loss. thought-provoking.
this four volume tome from carol alexander gives you pretty much all the information you will likely need on market risk, in one place. excellent work, all topics covered in as much depth as you need it for a first go-around.
 a poignant book about what it means to be alive, to die, and to make the most of your days in-between. great writing.

 john kay writes very well about what makes the financial system tick and issues that plague it. well-balanced narrative that even people that work in the industry can appreciate.
the writing is poor, but the plot is well done and the story reads well overall. written by a brit, there is lots of english slang... something that american audiences might not appreciate.

I used to think love stories were sappy... until I read this book. segal tugs at your heart-strings. moving story.

 chakravarti rajagopalachari has no shortage of detractors. but I think his books are magnificent especially the mahabharata, the ramayana, and the bhagavad gita. stories lovingly told following the canon, and without flowery embellishments.

 I like eknath easwaran's version of the bhagavad gita. lucid, clear, and an absolute joy to read.

 a very clear book on VaR. perhaps one of the best. I like alexander's writing too.

reading this book is hard work, and you need to take your time with this one to make sure you really understand all the lessons here... but it is a classic, and it will leave you with a nice, deep understanding of how investments work.

lee child's thrillers are among the best, but be warned, the tension is sometimes almost unbearable. the endings are usually satisfying.

 preston and child's pendergast series is fantastic. riptide is a stand-alone novel, but shows you what they can do with any story. great reads!


 this is jeffery deaver's best book. the lincoln rhyme series is good too. the rest just seem a bit warped (to me anyway)

you read these a little for fun, a little for the writing, the atmosphere, and the way the story is told. purple cane road is one of his best.
barry eisler does thrillers very well. his john rain character is one of the best I've read in this genre recently. the entire series is exciting - the above are three I've read most recently

 adrian mckinty keeps the narrative rolling. interesting stories well told. this is fun reading but almost on its way to serious literature.

 sam kean does it again. in The Disappearing Spoon, he covered the periodic table. here he describes the co-evolution of two sciences - genetics and evolution.

 interested in the most important equations that influence our experience as human being in this world? this book does a great job explaining them.

fantastic exploration of some of the harder problems in mathematics explained in very easy to understand terms

a self help book with a difference - some interesting perspectives and exercises. a relatively quick read.
a fascinating book about how the periodic table came to be. chemistry made extremely interesting. hard to put down.
statistics in practice. compelling reading if you want to build realistic models.
 considered by many to be the happiest man alive, mathieu ricard tries to teach you how to be happy.
solid, basic (I mean this in the most complimentary way) book on modeling. highly recommended as a first book on models - uses just Excel.
if you're serious about learning statistics, this book will get you there. it doesn't (can't) get much more lucid than this.
think success, acknowledge the possibility of failure, but persevere and succeed anyway.  zander's beautiful book on life, success, and the art (yes, it is an art) of possibility.
einhorn's cautionary story of a short position he took, and the company's attempts to obfuscate accounting, malign him personally, and generally discredit him. true story that makes an impression.
 interesting background and analysis of the habits of successful money managers.
think everyone lost money during the sub-prime crisis? think again. this is a story of the winners.
maclean and nocera give you a front-row seat to the sub-prime crisis... telling it as it happened. a cautionary tale, worth reading.
trevor hastie and rob tibshirani are excellent teachers of statistical learning - their mooc is second to none, and their explanations always clear and lucid. love these books!
lev dynkin et al's authoritative take on the quantitative management of bond portfolios. highly recommended.
interesting and intense. robert crais does it again. 
if you liked the movie "Fail Safe" (many consider it a classic), you'll love this gripping tale, well told.
one of my favorite books - ever need a quick boost of positive energy? read this book - works like a shot of vitamin B keeping those mental negativity demons at bay.
 mouboussin explains with some basic but insightful mental models, how one can think about luck, skill, and how to distinguish between the two in various situations.
pete blaber does an excellent job telling of his exploits on the battlefield describing how good and bad decisions are made and can be improved - both in war and in the boardroom
this trilogy by new author krishna udayshankar is an extremely well-written, non-canon following retelling of the Indian classic, the Mahabharata.
 greenblatt's book covers special investment situations including for example risk arbitrage, capital structure changes, spin-offs, etc.
 thornton o'glove makes accounting sing. this is the most riveting book on accounting I've ever read.

interesting tale, swashbuckling adventure, well told. excellent effort for a first novel.
good presentation of models for equity portfolio management using quantitative techniques - ebook doesn't have appendices and derivations that are in the paper version, so buyer beware.
exciting fictional spy story well told by a former CIA spook.
 discussion of Warren Buffett shareholder letters outlining his views on various topics - makes for interesting reading though not necessarily directly applicable in all cases by individual investors.
 find financial modeling of investment ideas and related mathematics fascinating? this book presents simple models in simple language without too much math, and leveraging Microsoft Excel as a basic computational tool. highly recommended.
 fascinating novel of an underdog that goes on to win. beautiful blend of fanciful alchemy with fantasy
 a very focused view of liquidity pools and more specifically dark pools that serve as venues for trading of most equities in the US (if not the world) today. concentrated coverage of details. 

two books that had a large impact on me as a youngster, but whose memory has faded since - as one grows up one sees the real world less in idealistic terms and takes a more pragmatic view... but these books are fantastic nonetheless
two of my favorite books in the english language. hesse tells these moving tales in very lucid, simple prose which makes it a pleasure to read.

Thursday, May 19, 2016

on dynamic programming and generating functions

Recently I have had several conversations regarding Dynamic Programming (DP) and related ideas with colleagues, so thought a post here might be in order.

Technique, Applicability, Example
Dynamic programming is a problem solving technique where a problem is broken down into simpler pieces, one or more of which recur. These smaller problems are easier to solve, and once solved, these solutions can be reused and the various parts can then be put together in clever ways to solve the larger problem we started with. The excellent algorithms text by Cormen, Rivest et al [CLRS] covers this in great detail.

Solving problems that fall into this class typically leverages ideas like memoization (remembering the solutions of smaller sub-problems already solved), recurrence relationships, and recursion. A typical oft-cited example is the Fibonacci series of numbers which starts 0, 1, 1, ... and each subsequent term is the sum of two previous ones. From this, the recurrence relationship is easily derived to be:
Fib(n) = Fib(n-1) + Fib(n-2) with Fib(0)=0, and Fib(1)=1. (In this case the recurrence relationship is obvious. For some problems it might not be, and might take some more work to figure out.)

Fibonacci coded as a simple recursion without memoization struggles to calculate even the 40th number in the series. This is an example of a case where the power of algorithms becomes immediately tangible. The code with memoization on the other hand returns the desired answer almost immediately.

# fibonacci series expansion without memoization
def fib2(n):
 if n==0: return 0;
 elif n==1: return 1;
 else: return fib2(n-1)+fib2(n-2);

# fibonacci series computation with memoization
f={0:0,1:1}; # set up the initial dictionary

def fib(n):
 if n in f: return f[n]; # if already computed, return it
 if n-1 in f and n-2 in f: # if not already computed, but needed terms available, 
  f[n]=f[n-1]+f[n-2];      # compute needed number, store it, then return it.
  return f[n];
 return fib(n-1)+fib(n-2); # use the recurrence relationship.

Why does memoization work? Because it remembers calculations that were already done, and instead of recalculating things, just uses these answers again... returning the desired answer almost immediately. For instance, the code without memoization computes Fib(5) as Fib(4)+Fib(3), then compute Fib(4) as Fib(3)+Fib(2), and so on, and the tree of function calls it completes to calculate Fib(3) are repeated all over again in the tree of function calls to compute Fib(4). In contrast, the code with memoization computes each Fibonacci number just once, stores the results in a hash-table, then reuses these as needed.

In other words, the naive algorithm is exponential in complexity terms, while the memo-ized version runs in polynomial time. This is an important distinction. I particularly love this example because this drives home the idea of the importance of algorithmic complexity in directly observable terms (just see how long one takes to compute numbers vs the other), even for an audience of lay-persons.

If at first you don't succeed... try, try again
"Insanity is doing the same thing again and again and expecting different results"
                                                                                                                    -- Albert Einstein

But wait! Even the code with memoization has some issues, one of which is discussed below. Why does the first attempt to compute fib(3000) fail, but the same call succeed later?

fib(1000);  
fib(3000); # gives a RuntimeError: maximum recursion depth exceeded

# but then try
fib(1500);
fib(1800);
fib(2000);
fib(2300);
fib(2600);
fib(2800);
fib(3000); # this works!

This is because in the first instance, the space between the already computed Fibonacci numbers (fib(1000)) to the target Fibonacci number (fib(3000)) is sparse. The number of recursive calls needed to bridge this gap in the memoization table is too large in one go. However, it is possible to work towards that gap by computing more and more numbers in the interim (say a gap of 300-600 each time) till the target is reached. Each of these intermediate calculations further populates the hash table until we can easily compute the desired number.

Does this negate Einstein's famous (and possibly apocryphal) quote? Probably not. Because the second invocation of fib(3000) is not the same as the first. The system is in a different state when it encounters the second call given all the intermediate computations that were completed in the interim.

The Path Forward
Understanding DP is critical to solving many problems asked in software engineering reviews, such as the following. The more impressive candidate however, is generally one that can look at somewhat more complicated problems, de-construct them into simpler sub-problems that are susceptible to DP methods, devise a solution for those, then put those solutions back together to answer the original seemingly intractable problem.

Typical interview questions - most of these can be easily solved using recurrence relations:
  1. Devise the most efficient means of finding the largest internally increasing or decreasing sub-sequence given a list of numbers. What are they? How many exist? How long are they?
  2. Demonstrate how to find the largest common sub-sequence given two sets of numbers or letters. A good interviewer will ask you both to indicate the size of the largest sub-sequence as well as give him the list of all sub-sequences that meet his criteria.
  3. In how many ways can you make change for $x, using coins with various denominations.
  4. In how many ways can you partition a number K using positive integers <=K? e.g. 5=1+4=1+1+1+3=2+2+1 etc.,

Sunday, March 20, 2016

Machine Learning study questions

This is a very basic set of questions in Machine Learning. This post is incomplete, more questions to be added over time.

Theory

  1. What is bias? variance? What is the bias-variance trade-off?
  2. What is meant by the term "the curse of dimensionality"?
  3. Explain over-fitting with an example
  4. Explain Bayes theorem with an example
  5. What is a V-C bound?
  6. What is the Hoeffding inequality? What does it mean?
  7. What are parametric, semi-parametric, and non-parametric methods? Give an example of each.
  8. What is supervised learning? unsupervised learning? reinforcement learning? online learning?
Methods
  1. Briefly describe the perceptron model and how it works
  2. What would you look at as you design a linear regression and read its output?
  3. What is multicollinearity? Heteroskedasticity?
  4. What is a confidence interval? t-statistic? p-value?
  5. What is Laplacian smoothing? When and how would you use it?
  6. What is a logistic regression? Where would you use it? How do you read its output?
  7. Why is logistic regression a useful technique? Which kinds of data distributions does it work best with?
  8. What is a generalized additive model?
  9. What is gradient descent? Explain stochastic gradient descent. What assumptions does it make?
  10. How would you influence the rate of convergence of stochastic gradient descent?
  11. What is Hill Climbing? Give an example of where you would use this.
  12. What is cross-validation? Describe two different ways of performing this.
  13. Describe three distinct ways of dealing with data sets that have more features than samples available.
  14. What are neural networks? How do they work? What are the different kinds of neural nets?
  15. What is deep learning?
  16. Describe how one might design the structure of a neural net to solve a problem.
  17. What are the different techniques of optimizing weights to reflect the learning a neural network undergoes as it is trained with a data set? (e.g. genetic algorithms, particle swarm optimization, back propagation)
  18. What is maximum likelihood estimation? How would you use it?
  19. Describe a naive Bayes model with an example.
  20. What is a Probabilistic Graphical Model (PGM)? Where might it be used?
  21. What are kernel methods? Give examples of their use (e.g. kernel smoothing, support vector machines)
  22. What are genetic algorithms? Illustrate with an example where and how these can be used.
  23. What are support vector machines (SVMs)? How can they be built and used?
  24. What is a self organizing map? How does it work? What is vector quantization?


Applications

  1. You are given a million points in 10 dimensional space. I have a hypothesis that these points are clustered in 8 groups. I want to test this hypothesis. What methods would you use and why?
  2. What is the complexity of the method you would use for the above?
  3. Perform a relative computational complexity analysis of K-means clustering vs. Hierarchical Clustering. Does it make a difference to your analysis if you do agglomerative hierarchical clustering vs divisive hierarchical clustering?
  4. The clusters you see when you run your algorithms on my data are elongated hyper-ellipsoids. What does this tell you about the data? What would you do in this situation to make inferencing easier?


Implementation
...

Wednesday, February 3, 2016

business growth drivers

What drives business growth?

If you're in any business, any industry, or even choosing one to be in, it makes sense to think through this to see the impact of your choice on your future... particularly so if you have already taken steps to future-proof your skill-set to give you freedom to explore multiple possible evolutions in the path forward.

A model like Porter's five forces is often quite useful in performing these kinds of analyses, but as with everything else, your analysis is based on the best information you have when you build your model, and as either the world changes and more information comes to light, or as you uncover more information about your domain of interest through your own study or research, it makes sense to revisit your assumptions.

In this post we look at some common business models prevalent today and study business growth drivers in each case.

Example: "Platform services"

This is an example of a service where network effects play a major role in driving growth. Take for example an Internet video hosting service. You need to achieve critical mass both in terms of people viewing content as well as with those generating the content being viewed i.e. you are building up a platform. When you have more content, you attract people with different tastes to come in to view it, and as more people view the content, you have more people who want to generate the content (who want the viewers' eyeballs), and you get a "virtuous cycle". Once you have critical mass, growth picks up suddenly, then takes off.

Similar arguments hold for other such services - new credit-card launch (merchants and users), new social media platform (users - content consumers, and users - content generators), Internet marketplaces (merchants and customers).  Key to growth in each of these cases is achieving critical mass as a first entrant, before competitors can grow. Once you have a lock, further growth should be easy, and your company will grow to be a behemoth... if you don't make costly mis-steps.

So what helps growth here?
  1. critical mass - lots of people like your service, and lots more are joining every day, on both sides of the platform - both the content creators and the consumers
  2. sticky service - people like your service, and it is not easy for competitors to build something comparable
  3. high switching costs - if people "join" the service together with their friends, and contribute content to the platform or form relationships on the platform, they will be less willing to leave as individuals, losing the network they have built there
  4. "protected" innovation - if you have patents on new technology that makes your service attractive, differentiates it from anything else available when it is first launched, and is hard for competitors to replicate, you have time to build your "moat" which will raise switching costs over time. That, and the investment (see (6) on monetization below) to keep the business at the leading edge contribute to faster growth
  5. barriers to entry - ideally you want a situation where you can enter new business domains at low cost (say as a first mover) but where, as time progresses, barriers to entry rise exponentially for competitors who want to clone your success from doing the same.
  6. easy and early monetization - many of the examples cited (e.g. video hosting, social media) in support of this model utilize advertising to pay the bills. Others charge users outright (e.g. credit card companies charge users an annual fee, and merchants a processing fee per transaction for the convenience). Yet others use differentiated pricing for different levels of service (e.g. reduced delivery charges) or force higher discounts on sellers for access to a high-volume sales platform.
Once a business is entrenched, it is quite difficult for a competitor to unseat it from its top position. So what would you do if say you wanted to create a social network application and get it to be as successful as Facebook?
  1. First, you have to give people a reason to switch. Is there something compelling you can offer, that users both want badly, cannot get from Facebook (e.g. you own patents on the technology), while giving them all the features they are already accustomed to? Alternatively, find "pain points" on the existing service, then build your platform to specifically address those, then advertise these differences every chance you get.
  2. Second, you have to give them the means to move from the platform they are currently on to your platform, seamlessly. How would you do this? If user content on the social media platform belongs to the user, not the platform provider, you can provide the user with tools to move her content to your platform, while simultaneously emailing or contacting her network on the old platform about the move. The tools would of course tout your new platform's differentiated capabilities to the user's network. If you can pull down some small fraction of the user's network with each switch, you can slowly work forward towards critical mass in your user population. It goes without saying that the tool we speak of should work completely seamlessly and without any hitches if we want users to switch.
  3. Third, you want to capture as much of the new subscriber market as you can. People not already on the existing leading platform, but wanting to join. And those who joined the existing platform but are disenchanted with it.
  4. And finally, you want to identify high impact users - these are the ones that are most connected on the existing platform - and get them to switch, offering whatever incentives you can. Of course, as a competitor you do not have access to any user's connectivity graph, but networks like LinkedIn for instance routinely indicate the number of connections or friends a person has, and this helps identify users that are a. better connected, and b. more active on the existing platform, and these are valuable to get to switch. If the platform has service (e.g. games etc) providers, use the same approach to get them to sign on to your platform inclusively at first, then exclusively as you gain mind-share.
  5. Also, use whatever opportunities present themselves to push your agenda. A network failure on the old service with lots of complaints on service inaccessibility? Advertise heavily so people think of your service then. Flaunt early adopters' testimonials and the differentiated nature of your offering every chance you get. Create a buzz. Get noticed. Win market-share.
While difficult, the above is by no means impossible. Facebook did this to a now almost forgotten MySpace. But to be fair, MySpace never captured the popular imagination in its heyday as Facebook does today, so the shift now might be more difficult than previously.

Now let's look at a slightly different business model.

Example: Internet Search

Here the business drivers are quite different. The market is characterized by:
  1. several direct substitutes - google, bing, duck duck go, come to mind at once
  2. low switching costs - all a dissatisfied user has to do is click another link
  3. high barriers to entry - sure, writing a search engine is not that difficult, but writing a competitive one that can take on the big boys on their home turf is strictly non-trivial
  4. easy interoperability - all search features common to various engines are table-stakes. 100% interoperability in terms of being able to search for various kinds of pages or "toolbar API" capabilities are expected.
  5. established underlying standards - some searches run better in "home" browsers than in others (e.g. bing in IE). Sometimes one might even argue that the search engine pegged by default into a browser's download settings has an advantage out of the gate, though savvy users will of course change these settings to best choose their tastes.  
  6. expectations of feature parity - also covered under (4) above. And when the expected nice features one is used to are not available, this causes people to switch. e.g. google identifies and tags pdf documents as pdfs. The quality of search results is arguably better. There is a side panel with a summary story of your search terms. All these things keep users coming back.
  7. strong patent moats for innovation - the search wars are won or lost on algorithms these days. What machine learning techniques underpin one search engine vs another, making one better or worse? Does the engine unobtrusively store your search history and use that to set a context for your future searches?
  8. scope for some meaningful differentiation - how do you monetize it? ad-revenue? automated reverse dutch auction bidding for keywords? Something else? Is your technology patented? A cash cow can not only take care of your search business, but also fund your other innovation.
  9. grab those eyeballs on all possible screens: feel PC screens are saturated with your users? move to mobile. integrate their search experience across screens. let users bookmark searches, ... the list goes on.
So how do you position yourself to succeed? The marketplace here is littered with the carcasses of even some erstwhile successful firms. Alta Vista, Inktomi/ Hotbot, Yahoo!, the list goes on. Once again today there is a single strong firm in the lead, but that position has been held before by others that have since become obsolete. So what makes one firm more able to entrench itself and grow, while earlier leaders wither away?

One could argue that the above factors coupled with constant innovation and large smart indexing of the ever expanding Internet is key.