How to mitigate hangovers

Introduction

Many natural products exist that are purported to be able to prevent hangovers, but unfortunately when one talks about natural hangover remedies it is difficult to find many well funded scientific studies that validate or refute such claims. This is at least in part because few if any companies are willing to invest millions of dollars investigating and running clinical trials to validate natural products that cannot then be patented to make a profit from.

In this article, I briefly discuss the main cause of hangovers, and will then discuss two natural supplements that can mitigate the negative impacts of drinking alcohol. This article refers to scientific publications wherever possible, but like many other articles on this topic it is also partially based on pseudo-science and personal experience.

What causes a hangover

In order to understand the cause of a hangover, it is necessary to first understand at a high-level the process how alcohol is broken down. As described in this report from the National Institute of Health, alcohol is broken down in two stages:

  1. Most of the ethanol (aka alcohol) is broken down in the liver, which transforms the ethanol into a toxic compound called acetaldehyde, a known carcinogen.
  2. Then, in a second step, acetaldehyde  (from step 1) is further metabolised by the liver down to another, less active byproduct called acetate. This acetate then is broken down into water and carbon dioxide for easy elimination.

As discussed in this article from Scientific American, most hangover symptoms are linked to elevated levels of acetaldehyde, and it specifically states the following:

That dreadful feeling the next day is the condition often called a hangover, which the journal Alcohol and Alcoholism characterizes as “general misery” with symptoms of drowsiness, concentration problems, dry mouth, dizziness, gastrointestinal complaints, sweating, nausea, hyperexcitability and anxiety. Most of these symptoms have been linked to elevated levels of acetaldehyde.

If acetaldehyde is the cause of hangovers, then the natural conclusion is that in order to reduce hangovers, one should try to reduce the amount of acetaldehyde in the body.  This can be achieved in the following ways:

  1. Drink less alcohol.
  2. Improve liver function to speed up the conversion of acetaldehyde into acetate.

For the remainder of this blog, we focus on option #2.

How to reduce acetaldehyde buildup caused by heavy drinking

Given that the breakdown of alcohol occurs primarily in the liver, if one can improve liver function then one could theoretically remove acetaldehyde from one’s system faster, and therefore mitigate the resultant hangover. It turns out that a naturally occurring product that improves liver function exists, and that it is readily and cheaply available. It is called milk thistle, and it has been used for thousands of years for improving liver function.

According to this article from the National Institute of Health,  the following has been shown about milk thistle:

  1. Evidence exists that milk thistle may be hepatoprotective (protects the liver) through a number of mechanisms: antioxidant activity, toxin blockade at the membrane level, enhanced protein synthesis, antifibriotic activity, and possible anti-inflammatory or immunomodulating effects.
  2. Among six studies of milk thistle and chronic alcoholic liver disease, four reported significant improvement in at least one measurement of liver function.

Given that milk thistle has been shown to improve liver function and to protect the liver, it stands to reason that if it is taken after drinking it should help metabolise acetaldehyde. Therefore, if one takes milk thistle after drinking and before going to bed, theoretically the amount of acetaldehyde in the body should be reduced while one sleeps, and the hangover should therefore be reduced.

How to reduce that lethargic feeling after drinking

Alcohol is known to reduce vitamin B concentrations as reported in this article. Additionally, low vitamin B levels can cause anaemia as documented in this article. Therefore, taking vitamin B supplements can reduce the feelings of lethargy if one’s vitamin B levels have been depleted from excess alcohol consumption.

Conclusions

Two cheap and readily available supplements that can reduce hangovers and the effects of excessive alcohol consumption are milk thistle, and vitamin B. If these supplements are taken before going to sleep after a night of drinking, they should help mitigate the hangover that would have otherwise been experienced. It is important to note that these supplements must be taken before going to bed – by morning it may be too late.

Financial implications of exercising share options

Disclaimer

I am not an accountant and this article should not be considered as financial or tax advice. I am providing analysis and calculations which may be used at your own peril. This article is written to demonstrate basic concepts, and does not account for country-specific tax laws or company-specific share option details. Your individual situation may invalidate some or all of the arguments and/or calculations made in this blog post.

Introduction

In many jurisdictions when share options are exercised, the income from such an exercise is taxed at the normal income tax rate. On the other hand, gains on shares (not options) are generally taxed at the more favourable capital gains rate. One therefore might assume that it is beneficial from a taxation perspective to convert company-issued share options into shares. In this blog we analyse the total profit generated from different strategies related to when and how share options are exercised, and will demonstrate that holding on to share options for as long as possible is likely a better strategy than converting options to shares.

The purpose of this blog is to demonstrate a thought process and methodology that can then be extended to account for country-specific tax rates, and country-specific tax benefits. It does not claim to give a universal answer on whether share options should be exercised to convert into shares.

What is a share option

A share option (aka stock option) is the right to buy  shares in a company at a fixed price. For example, if one has been issued 1000 share options with a strike price of $10, this means that at some point in the future one can buy up to 1000 shares for $10 each. If those shares are then trading at $100, then each share option would be worth $90, as determined by the market price at that time minus strike price. Another way of thinking about this is if someone can buy something for $10 that they can immediately sell for $100, then whatever it is that they are buying is worth $90. In our example, the 1000 share options would therefore have a value of $90,000.

Assumptions

In the remainder of this blog there are some simplifying assumptions made:

  1. The value of shares of the company that you have share options for will continue to increase.
  2. Tax is incurred when a share option is exercised.
  3. The rate of taxation on gains from a share exercise is higher than the rate of taxation on capital gains.

Country-specific tax considerations and/or benefits are out of scope of this blog.

What does it mean to exercise a share option

Exercising a share option refers to the act of paying the strike price to convert the share option into a share. Continuing with the previous example, we saw that 1000 options to buy shares for $10 would have a value of $90,00, assuming that the shares are currently worth $100 each. However, if we go ahead and actually exercise the shares, then we have triggered a taxable event of $90,000.

The $90,000 benefit from exercising the share options would generally considered income, and will normally be taxed at one’s standard income tax rate.  For example, if one is in the 40% income tax bracket then one would have to pay $36,000 in tax in order to be allowed to hold on to one’s shares. In order to convert these share options into shares, the total cost is the strike price of $10,000 plus the $36,000 of income tax. After paying $46,000 one would have shares worth $100,000. One is therefore $54,000 ahead compared to if one had not been granted the stock options.

In order to avoid having to pay cash out-of-pocket in order to exercise a share, one also has the option of a cashless exercise – this is where the money to pay the tax and the exercise price is paid by exercising and immediately selling a portion of one’s share options to cover the strike price and taxes. In the above example, one would pay $46,000  to cover the exercise price plus tax, which can be paid by selling $46,000/$100=460 shares. In this approach, one would be left with 540 shares worth $100 each. As expected, in this scenario one is also $54,000 ahead than if one had not been granted stock options.

Is it a good idea to exercise share options as soon as possible?

If one expects the share price to continue to rise, then one may be tempted to exercise all share options to convert into shares, to take advantage of the lower tax rate applied to capital gains. In this section, we consider why this is unlikely to be a good strategy.

Let’s imagine a scenario where the share price continues to rise to $1000, and we are still employed by the same company. Would we be farther ahead financially if we had exercised our shares at $100 and later sell the shares at $1000, or just held on to the original share options and finally exercise and sell at $1000? The table below shows the difference between the two scenarios. The original formulas can be seen in the first tab of this spreadsheet.

Assumed income tax rate 40%
<– Assumes that taxes are due on exercise (may be country specific)
Assumed capital gains tax rate 18%
<– Even if zero, in the calculations below, holding options until sale is preferable.
Assumed number of share options 1000
Cashless exercise and hold Hold and exercise at time of final sale
Per share exercise price 10 10
Per share value at exercise 100 1,000
Per share value at sale 1,000 1,000
Taxable income at exercise 90,000 990,000
Exercise cost (strike price * number shares) 10,000 10,000
Tax on exercise (income tax rate * taxable income) 36,000 396,000
Cost of cashless exercise (tax + exercise price) 46,000 406,000
Number of shares to sell to pay cost of exercise 460 406
Number of shares owned after exercise 540 594
Capital gain 486,000 0
Tax on capital gain 87,480 0
Pre-tax gain 576,000 990,000
Total tax per share (income tax + capital gain tax) 123,480 396,000
Total profit after tax 452,520 594,000

Notice that holding onto the share options for as long as possible has resulted in a greater profit than exercising the share options earlier and benefitting from a lower capital gains rate. In-fact, even if the capital gains rate is set to zero, in a scenario where the future value of the shares is $1000, it is still more profitable to hold on to share options rather than exercising to convert to shares.

This happens because in many countries, at the moment that one exercises shares, one incurs an immediate tax liability. Additionally, one also has to pay the strike price. In our example of a cashless exercise of 1000 shares at $100, the number of shares left after paying for exercise costs is only 540 – and therefore instead of enjoying growth on 1000 share options, one would instead only enjoy growth on 540 shares. Because of this reduction in the number of shares after a cashless exercise, the amount of growth is dramatically reduced versus the growth that would have been experienced if original options had been held.

On the other hand, the tax has indeed been dramatically reduced by performing a cashless exercise at $100 rather than waiting and exercising at $1000. However, the amount of tax savings does not compensate for the lost growth.

The above may lead one to conclude that they should therefore use cash to exercise their share options. We will investigate this in the next section.

Should share options be exercised with cash

If one has extra cash around, they may believe it would be a good idea to use cash to pay the cost of exercising their share options, rather than executing a cashless exercise and hold. This is likely true, and if the share price continues to rise then it would result in more profit than a cashless exercise and hold.

However, if one believes in their company enough to wish to invest cash, then they should consider if it is best to use that cash to exercise their existing share options to convert them to shares, or if it would instead be better to just buy additional shares on the open market with that cash. We therefore compare these two scenarios in the table below. Original calculations can be seen in the second tab of this spreadsheet.

Assumed income tax rate 40%
<– Assumes that taxes are due on exercise (may be country specific)
Assumed capital gains tax rate 18%
<– Even if zero, in the calculations below, using cash to buy more is better than using it to exercise
Assumed number of share options 1000
Pay cash to exercise Wait until sale to exercise, and instead buy more shares
Per share exercise price 10 10
Per share value at exercise 100 1000
Per share value at sale 1000 1000
Taxable income at exercise 90,000 990,000
Exercise cost (strike price * number shares) 10,000 10,000
Tax on exercise (income tax rate * taxable income) 36,000 396,000
Cost of cash exercise (tax + exercise price) 46,000 0
Cash paid (purchase more shares) 0 46,000
Sale value of additional shares (purchased in lieu of cash-exercise) 0 460,000
Capital gain 900,000 414,000
Tax on capital gain 162,000 74,520
Pre-tax gain 990,000 1,404,000
Total tax (income tax + capital gain tax) 198,000 470,520
Total profit after tax 792,000 933,480

Notice that the above calculations demonstrate that it is more beneficial to buy shares on the open market rather than using that same cash to exercise and hold shares. This is true even if the capital gains rate is zero. Again, this is due to the loss of future growth on any amount that has been paid in tax as well as any future growth on the cash that was used to pay the strike price.

Caveats

In pre-IPO companies where it is not possible to allocate cash to buying additional shares, it is likely beneficial from a tax perspective to early exercise such share options to convert them to shares. This is because the alternative of buying additional shares on the open market is not an option.

Share options generally expire if one leaves their employer. Therefore share options should be exercised before they expire and become worthless.

Share options likely expire a certain number of years after their grant, and should be exercised before they expire. The following article provides additional information related to exercising stock options: https://kellblog.com/2019/08/18/avoiding-the-ten-year-stock-option-trap/.

Conclusions

Based on the above calculations, if one wants to maintain their investment in their publicly listed company, and have the expectation that their company stock price will go up, then it would generally be financially beneficial to hold on to stock options as long as possible rather than exercising those options to convert them to stock. If one wishes to invest additional cash, then it is likely better allocated buying additional shares rather than to exercise options.

Disclaimer: this should not be considered as financial or tax advice, and your individual tax circumstances may differ. In the above calculations we disregard any country-specific tax laws that may increase the attractiveness of exercising share options.

 

Counting unique beats agents sending data into Elasticsearch

Introduction

When using Beats with Elasticsearch, it may be useful to keep track of how many unique agents are sending data into an Elasticsearch cluster, and how many documents each agent is submitting. Such information for example could be useful for detecting if beats agents are behaving as expected.

In this blog post, I first discuss how to efficiently specify a filter for documents corresponding to a particular time range, followed by several methods for detecting how many beats agents are sending documents to Elasticsearch within the specified time range.

How to filter for documents in a specific time range

This section describes how to efficiently filter for documents from a particular time range. In the following example, we filter for documents that were received yesterday:

GET filebeat-*/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d/d",
            "lt" : "now/d"
          }
        }
      }
    }
  },
  "sort": [{"@timestamp": "desc"}]
}

Notice that we use the filter context for the range query. Using the filter context is efficient for two reasons:

  1. Operations inside a filter context must answer a yes/no question – either documents fall into the time range or they do not. Because this is a yes/no question, a _score is not computed when filtering documents like this.
  2. The data inside a filter can be efficiently cached by the Node Query Cache, which “caches queries which are being used in a filter context”.

It is worth highlighting that if the parameters inside the filter are different on each query, then the results of the filter cannot be efficiently cached. This would be the case if the range that is being queried is continually changing. This may unintentionally occur if “now” is used inside a range query without any rounding.

In the above example we ensure that the filter can cache documents by using date math to round the range that we are searching in to the nearest day (as indicated by the “/d”). Compare this to the following which would give us all documents in the 24 hours prior to the current moment.

GET filebeat-*/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d",
            "lt" : "now"
          }
        }
      }
    }
  },
  "sort": [{"@timestamp": "desc"}]
}

Note that the above filter cannot be cached because “now” is changing at every millisecond.

A middle-ground may be to round to the nearest hour to allow the filter to be cached most of the time, except once per hour when the range is modified. Rounding to the nearest hour could be done as follows:

GET filebeat-*/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d/h",
            "lt" : "now/h"
          }
        }
      }
    }
  },
  "sort": [{"@timestamp": "desc"}]
}

Now that we have covered how to efficiently query for a documents in a particular time range, we are ready to demonstrate how to count the number of unique beats agents that are submitting documents to Elasticsearch.

A basic query to get a count of unique agents

To get a count of unique beats agents we can use a cardinality aggregation as shown below.

POST filebeat-*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d/d",
            "lt" : "now/d"          
          }
        }
      }
    }
  },
  "aggs" : {
      "unique_agent_id_count" : {
          "cardinality" : {
              "field" : "agent.id.keyword",
              "precision_threshold": 500 
          }
      }
  }
}

Note that we first filter documents by time (in this case documents from yesterday), and then execute the  cardinality aggregation on the filtered set of documents . Also notice that the size is set to 0 – this tells ES that we are not interested in seeing the actual documents that match the range query, we just want to see the results of the cardinality aggregation done across those documents.

Get an example document from each agent using field collapsing

The example below demonstrates how to use field collapsing to return the _source of a single document corresponding to each beats agent that submitted a document yesterday. Be aware that by default a search will only return 10 hits. In order to see all documents that match a given query the size should be increased, or if a large number of results are expected then pagination techniques should be used. In the example below we have set the size to 100, which will return up to 100 unique agents.

GET filebeat-*/_search
{
  "size" : 100,
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d/d",
            "lt": "now/d"
          }
        }
      }
    }
  },
  "collapse": {
    "field": "agent.id.keyword"
  },
  "sort": [
    {
      "@timestamp": "desc"
    }
  ]
}

Get an example document from each agent using a terms aggregation and top hits

We can use a terms aggregation and top hits aggregation to get each unique agent as well as a count of the number of documents submitted from each unique agent. Be aware that this code is likely less efficient than the above and may not be practical if a very large number of agents are reporting into Elasticsearch.

GET filebeat-*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
            "gte": "now-1d/d",
            "lt" : "now/d"
          }
        }
      }
    }
  },
  "aggs": {
    "unique_agents": {
      "terms": {
        "field": "agent.id.keyword",
        "size": 500,
      },
      "aggs": {
        "get_a_single_doc_for_each_unique_id": {
          "top_hits": {
            "sort": [
              {
                "@timestamp": {
                  "order": "desc"
                }
              }
            ],
            "size": 1
          }
        }
      }
    }
  }
}

There are three “size” settings in the code above:

  1. We have set the size to 0 for the query results – this just means that we don’t return the documents that match the range query, as we are only interested in the results of the aggregation.
  2. A terms aggregation by default will only return the top 10 hits. In the example above we have increased the size of the terms aggregation to 500. Be careful, as setting this to a very large value to handle a very large number of agents may be slow. For a very large number of agents, terms aggregations may become infeasible.
  3. Inside the top hits aggregations, we have specified a size of 1, meaning that a single document will be returned for each term.

Conclusion

In this blog, we have demonstrated how to ensure the best performance when filtering for documents, followed by several methods for detecting how many unique beats agents are submitting documents into an Elasticsearch cluster.