Inverting Laplace Transforms in R

Laplace transform is a useful mathematical tool that one must be familiar with, while doing applied work. It is widely used in Queueing models where probability distributions are characterized in terms of transforms. Inverting a Laplace transform to get to the probability distribution is an essential task in Queueing theory. For textbook examples and simple Markovian models, one might be fortunate to find convenient forms for LT inversion. However for most of the real life situations, a practitioner needs to know a way to numerically invert LT.

Effortless learning is a dangerous illusion

Via TES magazine

Mary Pat Wenderoth stops herself mid-lesson and asks her class a question about the day’s work. The students turn to their notes but she stops them. “Don’t look it up. Imagine your brain is a forest and your memory is in there somewhere. The more times you make a path to that memory, the stronger that path becomes. Try to figure it out.”

Wenderoth is a principal lecturer in biology at the University of Washington in Seattle, US. She keeps close tabs on research into how humans learn and knits the findings into her teaching methods. One of the most fundamental conclusions may appear contradictory:

Parrondo’s Paradox : Can two wrongs make it right

Parrondo’s Paradox : A combination of losing strategies becomes a winning strategy. 

This paradox can be seen via a simple simulation of three games.

  • Game Type 1 – You flip a biased coin that has 1/2-epsilon as the probability of heads. For each head you get $1 and for each tail you lose $1

  • Game Type 2 – If your capital is a multiple of 3, you flip a biased coin that has 1/10-epsilon, as probability of heads. If you capital is not a multiple of 3, you flip a biased coin that has 3/4-epsilon, as probability of heads . For each head you get $1 and for each tail you lose $1

M/M/1 Transient Queue length distribution

Computing steady state probabilities for a queueing system is somewhat easier than computing the transient distributions. The latter typically comprises a differential-difference equation and the usual trick of recursive substitution fails as there is a derivative in the equation. The  tools employed in solving a differential-difference equation are Generating functions, Laplace transforms and PDE solving tricks. Only for simple systems such as M/M/1 can one slog out and find a closed form solution. For a generic system, the algebraic manipulations get extremely tedious and one usually resorts to numerical methods. Having said that, it pays to know how the tools work for a simple case.

Difference and Differential Equations with Applications in Queueing theory : Book Review

image

In a book that has about 350 pages, the first 250 odd pages are devoted to probability, ODEs and difference equations. The last part of the book covers queuing theory for specific systems, i.e, Poisson arrivals, exponential service times of one or more servers. The most painful thing about this book is that there are innumerable typos. A book that is riddled with typos on almost every other page cannot be an appealing text for an undergrad.  My guess is that, this book will be never make it to an undergrad’s study table, unless the authors make a serious effort to publish an errata or come up with a better version of the book. Is there anything good about the book at all ? Well, may be, the chapter on difference equations is worth going over just once. On a second thought, I think that the first 250 pages of the book can be rewritten concisely so that it can be pushed to the appendix.  That leaves the last 100 pages of the book that reads more like a cheat sheet rather than a book from which one can really learn something. This book desperately needs a rewrite from the authors,else it is going to languish alongside the books that die silently every year.

“Sailor, Coconuts and Monkeys”– Continued Fractions

This puzzle has appeared in many forms but here is one variant:

Five sailors were cast away on an island. To provide food, they collected all the coconuts they could find. During the night one of the sailors awoke and decided to take his share of the coconuts. He divided the nuts into five equal piles and discovered that one nut was left over, so he threw this extra one to the monkeys. He then hid his share and went back to sleep. A little later a second sailor awoke and had the same idea as the first. He divided the remainder of the nuts into five equal piles, discovered also that one was left over, and threw it to the monkeys. Then he hid his share. In their turn the other three sailors did the same thing, each throwing a coconut to the monkeys. The next morning the sailors, all looking as innocent as possible, divided the remaining nuts into five equal piles, no nuts being left over this time. The problem is to find the smallest number of nuts in the original pile.

Flash Boys : Not So Fast – Summary

image

This book is a ~160 page tirade against the book “Flash Boys” that has captured everyone’s mindshare with the marketing slogan - ”U.S. stock market is rigged”. The author, Peter Kovac, has worked with a HFT firm for eight years and claims to be an industry insider. Since “Flash Boys” was basically anti-HFT book, it is natural to expect someone from the HFT to criticize the book. So, there we have Peter Kovac with a book length treatment that has similar title with Lewis book but a different tagline.

Advanced R : Book Review

There is a difference between an R user and an R programmer. The former is usually concerned with writing R scripts, using existing R libraries, in order to do data wrangling / model development / back testing or creating an reproducible research document. R programmer on the other hand is usually interested in creating a package / reusable code that can be used by others in his company / by R community.

Flash Boys : Book Review

image

Introduction: windows on the world

Michael Lewis starts off by saying that the mental picture of stock market that most people away from Wall Street carry has changed dramatically over the last decade. He claims that his intent of writing this book is to draw a picture that is the new reality of U.S markets.

Hidden in plain sight

Only Michael Lewis can take a “laying a fiber optic cable” story and make it in to a page turner. This chapter talks about Dan Spivey and his efforts to connect Chicago and New York by a line that is as straightlinish as possible. The company formed by Dan Spivey, called “Spread Networks” began work in 2008 and was finally completed in 2010. To get the necessary approvals for constructing the network and selling this network to Wall Street people, Dan partnered with Jim Barksdale, David Barksdale and Larry Tabb. The whole point of the line was to create inside the public markets a private space, accessible only to those willing to pay the tens of millions of dollars in entry fees. Spread Networks first press release was titled,

Securities Trading Primer

Joel Hasbrouck (NYU) has written a concise teaching note that serves as a primer to securities markets trading protocols. The document is ~100 pages and gives a 10,000 ft. view of rules for U.S securities markets. Here are some points from the teaching note:

  • Informed trading works like a tax on uninformed traders

  • A sequential trade model to hypothesize the behavior of informed, uninformed and passive traders

  • Increased demand in any market, from candy bars to cars, is also generally associated with a price increase. So why is order impact in security markets remarkable? A puzzle arises in connection with the relative size of the order and the price impact. For example, a firm might have 10 Million shares of stock outstanding. At a price of, say, $20 per share, the firm’s equity market capitalization is $200 Million. A 1,000 share marketable buy order might move the market share price upwards by $0.01. The total value of the order is about $20,000. Yet the market capitalization of the firm has increased by 10 Million x $0.01 = $100,000, about five times the total value of the order. It is as if an over-eager car buyer, accepting the dealer’s high initial “list price” offer, caused the price of that model to increase for everyone else in the world.

Scaling of the distribution of fluctuations

The following two papers analyze the scaling property of index returns and individual stock returns :

In this post, I will briefly summarize the main contents of the papers.

Scaling of the distribution of fluctuations of financial market indices :

It is well known that index returns and stock return distributions observed in reality are far from Gaussian. It was Mandelbrot who analyzed cotton prices and observed time scaling property – distribution of returns for various choices of time intervals have similar functional forms. He called it a Levy stable distribution. With the available high frequency data, various empirical studies have shown that distribution of returns decay faster than predicted by a Levy distribution. Hence a truncated Levy distribution has been proposed – the central part obeys Levy. The exponential truncation ensures that there is a finite second moment. This means that truncated Levy process with i.i.d. random variables should converge to Gaussian.

How to be alone – Book review

image

This book can be savored by anyone who loves silence and solitude. Solitude, in most of our lives, visits us when we are least prepared – unexpected work assignment to a different city/country, sudden hospitalization for an extended period of time, death of partner, break up etc. Most of us are ill-prepared to handle the sudden intrusion of solitude. This coupled with our childhood experiences of hyper protective parents questioning us – “Kid, you are very silent. Is everything OK with you?”— creates an unhealthy attitude towards situations where we are silent and alone.

The Complete Guide to Capital Markets for Quantitative Professionals : Summary

image

The book by Alex Kuznetsov gives a great overview of  the financial markets in U.S. The book is targeted towards a person who is coming from a technical background and intends to work in finance but does not have a clear idea about,”What exactly happens on Wall Street ?” The book is ~ 500 pages and covers quite a lot of ground. The first part of the book gives a basic idea of how a Wall Street sell-side firm is structured, who are key players in the financial industry etc. The second part is the juiciest part of the book where the author covers all the main markets in US, with just enough content allocated to each market, that a curious reader will be enthused to read other books about them. The third part of the book deals with technology areas, and is priceless for a newbie quant at any Wall Street firm. The fourth part is too specific to people who probably see themselves as sys-admins.

Open Secret : Review

image

LIBOR is the reference rate for 70 percent of the U.S. futures market, most of the swaps market, and nearly half of U.S. adjustable-rate mortgages. LIBOR, undoubtedly can be called the “world’s most important number”. It was conceptualized to meet a certain need, i.e. “what rate should be used for a floating rate note? “. Primarily it was used in the payoff computation of Eurodollar futures and subsequently it was used in interest rate swaps, derivatives on interest rate swaps, basis swaps, mortgages etc. The fact that LIBOR became a rigged rate was known to a few people in the financial world, i.e. rate traders, derivative traders, hedge fund managers, agencies that published LIBOR every morning. However it was known to a far wider audience after the 2008 WSJ article that screamed, “Emperor is naked ”. The title of this book is apt as it describes the situation before the regulatory agencies took action. Everybody knew what’s going on but nobody said anything. Too much was at stake.

What happens in Silence

Via This is your brain on silence :

While it’s clear that external silence can have tangible benefits, scientists are discovering that under the hoods of our skulls “there isn’t really such a thing as silence,” says Robert Zatorre, an expert on the neurology of sound. “In the absence of sound, the brain often tends to produce internal representations of sound.”

Imagine, for example, you’re listening to Simon and Garfunkel’s “The Sound of Silence,” when the radio abruptly cuts out. Neurologists have found that if you know the song well, your brain’s auditory cortex remains active, as if the music is still playing. “What you’re ‘hearing’ is not being generated by the outside world,” says David Kraemer, who’s conducted these types of experiments in his Dartmouth College laboratory. “You’re retrieving a memory.” Sounds aren’t always responsible for sensations—sometimes our subjective sensations are responsible for the illusion of sound.

Kaal Chakra

image

Had a chance to accompany my parents in watching a play, “Kaal Chakra”.The play is one of the flagship plays of Yatri theatre group (founded by Om Katare).

The play revolves around an elderly couple, Mr.&Mrs.Inamdar(Om Katare and Paromita Chatterjee). Like most of the middle class families, they put in their entire savings in bringing up their two kids. The elder son for various reasons takes on Mr. Inamdar’s business and leads a financially struggling life. The second son becomes a manager at pharma company. The real trouble starts when the Inamdars become old. Their sons and daughters-in-law become reluctant to look after the Inamdars. The trauma of a neglected elderly couple has been superbly enacted. Their emotional pain reaches an unbearable point, after which Mr.Inamdar gives an advertisement in the paper that they are available for adoption, if any family is willing to give it a shot.

Propensity score in observational studies

The classic paper, “The central role of the propensity score in observational studies for casual effects“ by Rosenbaum & Rubin, is cited in many of the applied econometrics papers that deal with causality. In a randomized experiment, the outcome of the treated group and control group can be directly compared because the groups are likely to be similar. In an observational study, one does not have this luxury and in almost all the cases, the treated group and the control group vary in their composition. Hence the need for a technique to compute the treatment effect where there is a selection bias. This paper introduces “propensity score” as a solution to the selection bias.

The causal impact of algorithmic trading on market quality

The paper titled, “The causal impact of algorithmic trading on market quality”, written by Nidhi Aggarwal and Susan Thomas, systematically identifies the casual relationship between Algorithmic trading intensity and market quality features in the Indian markets. In this post, I will briefly summarize the contents of the paper :

What is the paper about ?

How does algorithmic trading (AT) affect the quality of securities markets ? is something that is always discussed/ analyzed/ debated by old and new market participants. Academic literature on this topic is  predominantly based on US markets. Not surprising as US markets are considered to be one of most technologically sophisticated markets. There are a few problems when one wants to answer the AT impact in US markets, i.e.

The Art of Stillness

image

This book is a TED book, i.e. a book paired with a TED talk so that ideas mentioned in the talk are explored in a little more detail. At the same time, TED books are intended to be short so that one can comfortably read it one sitting. This book is about 75 pages. The author gives various anecdotes from his life and encourages the reader to find “Nowhere” in one’s daily/weekly schedule so as to practice “Stillness”.

Hands-On Programming with R

image

This book is mainly targeted towards R-newbies who have managed to learn some basic R syntax and are looking for some guidance on writing functions in R. The key idea that one needs to understand before writing functions is the way R organizes objects in various environments. The author explains this idea using the analogy of “file system in a computer”. The book uses two examples, 1) shuffling a deck and dealing cards from it 2) simulating the outcomes of a slot machine. The code is extensively annotated so as to make it easy for any reader to thoroughly understand each code fragment. Even though the examples used in the book are very simple, the author manages to cover quite a number of key concepts of the R language.

Quote for the day

How have we arrived, in the relatively prosperous developed world, at least, at a cultural moment which values autonomy, personal freedom, fulfillment and human rights, and above all individualism, more highly than they have ever been valued before in human history, but at the same time these autonomous, free, self-fulfilling individuals are terrified of being alone with themselves?

Think about it for a moment. It is truly very odd.

-- Sara Maitland

User vs. Programmer

Via rockchalk :

Rchaeology: The study of R programming by investigation of R source code. It is the effort to discern the programming strategies, idioms, and style of R programmers in order to better communicate with them.

Rchaeologist : One who practices Rchaeology.

There is a language gap between an R user and an R programmer. Users write “scripts" that use functions from R packages. Users don’t write (many) functions. Users don’t make packages. And many users are happy to keep it that way. For users who want to become programmers, there is usually a harsh awakening. R for development is a different language.

The End of Absence : Book Review

image

For those of us who are born before 1985, it is likely that we have seen two worlds; one, a world that wasn’t dependent on net and another, where our lives are dominated/controlled by the web and social media. The author says that that given this vantage point, we have a unique perspective of how things have changed. It is impossible to imagine a life without print. However before the 1450’s Guttenberg printing press invention, the knowledge access was primarily through oral tradition. Similarly may be a decade or two from now, our next generation would be hard-pressed to imagine a life without connectivity. There is a BIG difference between the Guttenberg’s revolution and Internet—the pace. Even though the printing press was invented around 1450’s, it was not until 19th century that enough people were literate, for the written word to influence the society. In contrast, we have seen both the offline and online world in less than one life time.

How We Learn : Book Review

image

In today’s world where access to information is being democratized like never before, “learning how to learn” is a skill that will play a key role in one’s academic and professional accomplishments. This book collates ideas from some of the recent books on learning such as, “Make it Stick”, “A Mind for Numbers”, “The Five Elements of Effective Thinking”, “Mindset”, etc. The author has added his own personal take on the various research findings mentioned in the book and has come up with a 250 page book. If one has really absorbed the concepts mentioned in the previous books, then you really DO want to read this book. Any exercise that puts you in retrieval mode of certain concepts alters your memory associated with those specific concepts. Hence even though this is book serves as a content aggregator of all the previous books, reading it from the eyes of a new person, changes the way we store and retrieve memories of the main principles behind effective learning.

Curious: Book Review

image

In a world where uncertainty is the norm, “being curious” is one of the ways to hedge volatility in our professional and personal life. By developing and maintaining a state of curiosity in whatever we do, we have a good chance of leading a productive life. The author of this book, Ian Leslie, is a journalist and it should not come as a surprise that this book’s content is essentially “annotating a set of articles and books on curiosity”. The book is a little longer than a blog post / newspaper article and falls short of a well researched book.

How Not To Be Wrong

image image

Every year there are at least a dozen pop math/stat books that get published. Most of them try to illustrate a variety of mathematical/statistical principles using analogies/anecdotes/stories that are easy to understand. It is a safe assumption to make that the authors of these books spend a considerable amount of time thinking about the apt analogies to use, those that are not too taxing on the reader but at the same time puts across the key idea. I tend to read at least one pop math/stat book in a year to whet my “analogy appetite”. It is one thing to write an equation about some principle and a completely different thing to be able to explain a math concept to somebody. Books such as these help in building one’s “analogy” database so that one can start seeing far more things from a math perspective. The author of this book, Jordan Ellenberg, is a math professor at University of Wisconsin-Madison and writes a math column for “Slate”. The book is about 450 odd pages and gives a ton of analogies. In this post, I will try to list down the analogies and some points made in the context of several mathematical principles illustrated in the book.

The Dip : Review

image

Given that there is an abundance of ideas, products, resources, technologies, experts etc. in today’s world, it is not surprising that only the best get noticed. There is a LARGE gap in the premium commanded between the best and others. Seth Godin makes an argument that in order to get noticed in this overcrowded world, nothing short of “best” works. What’s “best” is decided by the micro market you are intending to serve?

Wow!

A tea staller in Delhi, Laxman Rao has written 24 novels, moonlighting. At the age of 62, he is doing M.A in Literature ! Truly inspirational.

The Lotus Eater

image

I guess at least a few people do entertain the following thought at some point in their lives :

I want to work like crazy, earn enough money until I am X years old and then take all the hard earned money and retire in a peaceful place for the rest of the life.

The value of X is something that is variable in the above statement. For some it is late 50’s. For some it is late 40’s. Nowadays we see some instances where X happens to be late 30s/early 40s. Whatever X may be, the thought process behind such a statement is that, one would have accumulated enough money to lead a simple life far away from the hustle bustle of maddening city life.

84, Charing Cross Road

image

This is a book of letters. It contains a 20 year correspondence (1949-1969) between Helene Haff, an American freelance writer and Marks & Co., a book store on 84, Charing Cross Road at London. The author’s love for books and especially out-of-print books makes her respond to an ad placed by Marks & Co in a literary magazine. Her first letter requesting a set of books gets a prompt response from the book store and that’s how a 20 year correspondence starts.

Introduction to Bootstrap Methods with Applications to R

image

It was bootstrapping that made me start off on my statistics journey years ago. I have very fond memories of the days when I could understand simple things in statistics without resorting to complicating looking formulae. A few lines of code were all that was needed. Slowly I became more curious about many things in statistics and that’s how my love affair with stats began. There are two bibles that any newbie to bootstrap should go over; one by Efron & Tibshirani and the other by Davison & Hinkley. Any other specific topics, you can always understand by reading papers. It is always a nice feeling for me to read stuff about bootstrapping. However reading this book was an extremely unpleasant experience.

The imprecision of volatility indexes

The paper titled, “The imprecision volatility indexes”, analyzes VVIX, the vega weighted VIX, an estimate for the 30 day expected volatility. Market participants have always wanted some kind of quantitative measure for the volatility. CBOE introduced VIX based on the Black Scholes volatility of ATM options  and later changed it to a method that is based on observed option prices. The latter method in the finance literature goes by the name, “model free method”, because it uses a replicating portfolio argument of pricing a variance swap. Having said that, it is not as though it is completely “model free”, after all the risk neutral expectation of a variance swap computation assumes basic GBM with constant volatility for the stock price evolution. 

How Normal is a family of distributions

In every elementary statistics textbook on inference you will find the following question

How to draw an inference on a correlation estimate between two variables ?

An inverse hyperbolic tangent transformation is applied to the correlation coefficient, which then is shown to be distributed as a normal random variable.This transformed variable is then used to compute confidence intervals on the original scale.

If one is curious, a natural follow up question would be,

What’s wrong with VIX

The paper titled, “Extracting Model-Free Volatility from Option Prices: An Examination of the VIX Index”, is a very interesting paper that talks about the problems in the VIX index computation that is currently being used at CBOE. Other stock exchanges throughout the world are also following a similar method for disseminating VIX, called the fear index. One of the most interesting conclusions of the paper is this :

VIX underestimates the true volatility in times of panic, i.e. when we need the fear index the most, it acts as an imprecise gauge

Derman’s Berkeley MFE Commencement Speech

It’s truly a great pleasure for me to be at the University of California at Berkeley today. Not quite 50 years ago, when I was an undergraduate studying physics in Cape Town, I began applying to go to the United States for graduate school. It seemed to be the right thing to do if you were serious about your field.

So I applied to three schools: Columbia, because I knew someone in Cape Town who had just gone there, and because it was in New York City; Caltech, because Feynman was there and had recently been awarded the Nobel prize and also published the stylish and insightful Feynman lectures on physics, though I didn’t understand at the time what he had actually accomplished; and Berkeley, because it was in the news for the start of the revolts against arbitrary authority on campus. I read the other day that year is the 50th anniversary of the Berkeley Free Speech Movement that seem to me to have kicked off the Sixties. For those of you who are too young to remember that, which I suppose  is all of you graduating today and maybe much of the faculty too, take a look — it’ll make interesting reading.

More than you ever wanted to know about Volatility Swaps

The note titled,” More than you ever wanted to know about Volatility Swaps”, written by Derman, Demeterfi, Kamal and Zhou, is a fantastic fifty page write up highlighting many aspects of valuing a variance swap and a volatility swap. I love the structure followed in the note. Instead of heading right in to the math behind valuation, the paper gives starts off by giving a superb intuition into the need for variance swap and how does one go about pricing a variance swap with nothing more than common sense. In this blog post, I will summarize some of the points from the note.

The Log Contract

The article titled, “The Log Contract”, is a 20 year old article. It was first article that made a case for the need for a new instrument to hedge volatility. There is something nice about papers written in the old times. The authors give a healthy intuition about the stuff they are about to explain in the paper, use simple equations that do not require too much of “head banging” and at the end of it, the reader pretty much gets the gist of the paper.  Such papers are rare nowadays. In today’s world, pick any finance/stats/quant paper, there are at least two dozen heavy references given in the appendix and a substantial preparation is needed to understand the key idea of the paper.  Very rarely is a paper self-contained. May be that’s the way it is supposed to be.

A Simple Long Memory Model of Realized Volatility

The paper titled, “A Simple Long Memory Model of Realized Volatility”, is one of the most cited papers in the area of long memory volatility models.

One typically assumes that log prices follow an arithmetic random walk. In this kind of set up, it has been shown in the previous research that integrated volatility of Brownian motion can be approximated to any arbitrary precision using the sum of intraday squared returns. In fact this statement is applicable at a more general class of stochastic processes – finite mean semi martingales (includes Ito processes, pure jump processes, jump diffusion processes). Sum of intraday squared returns, ``Realized volatility, is a nonparametric measure that asymptotically converges to the integrated volatility as the sampling frequency increases. The flip side to this utopian scenario is the microstructure noise that one needs to contend with as the time scales become finer. Noise introduces a significant bias in the RV estimate. Hence one has to make a tradeoff between measurement noise and unbiasedness. In many papers, researchers have used anywhere between 15 min to 30 min intervals, as they might have observed that as the shortest return interval at which the resulting volatility is still not biased. Another approach that can be adopted to deal with the microstructure noise is to filter away the noise using the autocovariance structure of k tick aggregated returns. Well one might have to search a grid to get an optimal k to begin with. In an earlier paper by Corsi, one such filtering method is described.