LIFO Reserve

LIFO(Last In First Out) is a commonly used inventory recognition method, mostly in the United States. It will assume that the latest inventory will be sold first from the accounting perspective, not necessarily physically. Since the inventory cost usually varies, in that case, even for the same physical goods and same resale, different ways of recognition the cost might lead to different financial performance on the paper. LIFO is said to have positive impact on the cashflow when inventory’s cost are uptrending because recognizing expensive cost will reduce profit, hence, less tax.

This article will focus on a terminology which is called LIFO reserve. It is defined to be the difference between inventory amount recognized under two different methods LIFO and FIFO. By having LIFO reserve, inventory value and COGS under one method can be converted to another easily.

Now let’s see how to adjust some of the numbers when compare a company reported under LIFO to the ones that aren’t.

INVENTORY:

The inventory amount under LIFO will need to add the LIFO reserve in order to reach the inventory amount under FIFO

COGS:

COGS under LIFO should subtract the increase in LIFO reserve to reach COGS under FIFO

Now let’s explain why, we add a number to the end of each variable to represent the year, XXX_1 means year one, so on and so forth. Based on the definition:

LIFO_reserve_1 = inventory_FIFO_1 – inventory_LIFO_1   (Equation1)

LIFO_reserve_2 = inventory_FIFO_2 – inventory_LIFO_2   (Equation2)

inventory_FIFO_2 = inventory_FIFO_1 + Inventory Bought_FIFO – Inventory Sold_FIFO (Equation 3)

inventory_LIFO_2 = inventory_LIFO_1 + Inventory Bought_LIFO – Inventory Sold_LIFO (Equation 4)

Under different methods, inventory bought is the same because it is fixed money paid for new inventory. The wiggle room is that inventory sold can be adjusted depends on which inventory you assume to be sold.

By subtracting Equation 4 from Equation 3, we have

inventory_FIFO_2 – inventory_LIFO_2 = inventory_FIFO_1 -inventory_LIFO_1 – Inventory Sold_FIFO +Inventory Sold_LIFO

Rearrange it,

Inventory_Sold_LIFO – Inventory_Sold_FIFO = (inventory_FIFO_2 – inventory_LIFO_2) – (inventory_FIFO_1 – inventory_LIFO_1) = LIFO_reserve_2 – LIFO_reserve_1 = increment_LIFO_reserve

In one of the CFA Level1 practice problems, there is a problem which well explained how everything fits together.

Screen Shot 2018-10-20 at 11.26.06 AM

The return on assets under LIFO for 2014 is 178/5570 = 3.2%.

Under FIFO, we need to adjust (increase) not only the net income due to the decreasing profit but also increase the asset by adding up the LIFO reserve. Both the numerator and denominator will increase by to different level.

Net_Income_FIFO = Net_Income_LIFO + LIFO_reserve_change adjusted by tax

Total_asset_FIFO = Total_asset_LIFO + LIFO_reserve_2014 adjusted by tax

Net_income_FIFO/Total_asset_FIFO = Net_income_LIFO + (867-547)*(1-t) / [Total_asset_LIFO + 867 * (1-t)] = (178 +(867-547)*(1-33.3%)) / (5570 +(867)*(1-33.3%)) = 6.4%.

The return on asset pretty much doubled under FIFO.

(867-547)*(1-33.3%)) / (867)*(1-33.3%)) = 36% which is pretty high. In that case, by analyzing the LIFO reserve, especially, the change percent in the lifo reserve and how much lifo reserve relative to total asset will give you a good picture of return on assets under different methods.

 

 

 

 

A Brute Force way to Auto Detect Signs in Financial Statements

When reading about the financial statements for any given company, or any spreadsheet in general, a situation any person constantly run into is numbers are presented in a slightly inconsistent way regarding the signs (+/-). For example, if there is an expense line item, people might assume it is an expense (outflow of cash) and will present the way as is. Sometimes, people will actually consider expense is different from income and will present it in a different way from revenue by including the numbers in a brackets like (400). Things can get really complex because there are metrics derived from a series of basic metrics like net income (bottom line on statement of operations) which should be the ultimate result after adding/subtracting the relevant gains and losses. I always have a hard time by calculating the final results because the signs for each line always confuse me. In the end, I ended up playing with signs for each line with my fingers crossed, wishing that I will be “lucky” enough to make the math work.

Screen Shot 2018-10-06 at 10.37.44 AM

Above is part of the cashflow statement from unaudited 10-Q for Arrow Electronics, Inc., a public listed company. They did a great job because the bottomline for the cash used for operations are a simple arithmetic sum of all the number, given you treat numbers in parenthesis as negative, hence to subtract.

Screen Shot 2018-10-06 at 10.42.19 AM

However, I want to use this data as an example to see how my script will be able to “auto detect” that the numbers in parenthesis should actually be subtracted. The Python script will take a brute force approach to find the right signs for each line item in order to reach to the right “bottom line”. The idea is very simple, it will switch signs for each line (positive, negative or exclusion) until it finds all the right sign and approximate to the bottomline within certain error tolerance.

Now let’s take a quick look at the implementation.

Screen Shot 2018-10-06 at 10.55.48 AM

First, we load all the data points into a data structure, since we are not sure about the signs for each line, or even should we include one line item or notat all, we will treat them all the same as positive numbers to get started. Benchmark variable is the final answer that we need to match. Base variable is 3 because for each number, it can either be treated as a positive number, a negative number or not included (for example, there could be an intermediate variable. Including the intermediate variable along with all the basic variables will lead to double count).

Screen Shot 2018-10-06 at 10.59.09 AM

baseN is a utility function that I borrowed from Stackoverflow, it can convert from a integer into a string format representation of any base. For example, baseN(4, 3) will be 11. We will use this function to help us loop through all the possibilities.

Then the next step is to try out all the possible combinations. Frankly speaking, I should have done way more research than I did but the first thought that came to my mind is to loop through all the possible combinations and represent the each state as a number of base 3. For example, in total, we have 11 elements. Then we have a number of 11 digits which each digital can have three states (negative, not included, positive). It can be represented as (0, 1, 2) for each state. In that case.

00,000,000,000 represents a possibility where all numbers should be treated as negative and clearly the total sum will not add up to our benchmark. Then next,

00,000,000,001 represents a situation all numbers except “Other assets and liabilities” 123769 will be negative, and only 123769 will be excluded. And of course, it will not add up.

00,000,000,002 means treat the last number as positive leaving the rest as negative.

00,000,000,010 means treat the second to the last as excluded and the rest of negative.

So on and so forth, when the number keep increasing till 11,111,111,111, then we should have iterated through all the possible combinations, hence, np.power(3, 11) ~ 177K.

Screen Shot 2018-10-06 at 11.08.54 AM

Weight is a variable that stores the sign for each variable. The code is pretty straightforward and I just want to clarify that the use of np.isclose is essential because all financial statements do some sort of rounding. It will be really hard to perfectly add up all the numbers and by tuning the error tolerance will be critical, something within 1% is probably a good rule of thumb.

Screen Shot 2018-10-06 at 11.14.32 AM

In the end, the final outcome will look like this, as you can see, since I am comparing using the absolute value, the script gives me two answers where it successfully identified the lines items under “changes in assets and liabilities” should be treated as a opposite sign as the rest of the items.

There are several limitations to my implementation just out of the box. The first one will be the scalability. The complexity of this brute force approach will grow exponentially as the number of variables increases.

Here are some interesting ideas for further exploration.

  1. How can you build mathematical relationship automatically within a financial statement or even across financial statement, across different years. For example, AR change in cashflow is the difference between end AR in balancesheet, ..etc.
  2. How can you solve the scalability issue by aggregating numbers to reduce number of variables, for example, now we can exclude all these 11 variables from future computation because they can be replaced as one variable – Net Cash used for operating activities.

 

Antidilutive in EPS calculation

EPS (earnings per share) is a very important ratio in income statement, it is calculated as earnings (net income) attributed to common shareholders divide by common shares outstanding. Actually, it is so important that it is required to include EPS on the face of the income statement.

walmart_eps_10k

As you can see, they not only show the EPS, there is also another line right below it which is the diluted EPS. The reason that diluted EPS need to be disclosed to the public is that there are different kinds of equity like preferred stock, convertible stock that has the potential of “diluting” the EPS. How big a difference is can be? Usually it is pretty small, like for Walmart, the earnings per share is only 0.01 but in some cases, the difference can be material enough that investor want to know the potential downside.

Say for example, convertible stock sometimes got paid dividend and can also be converted to certain amount of shares. If not convert, that is the simple calculation for EPS, however, the diluted EPS to evaluate if all the convertible stocks got redeemed into common stock, on one hand, the net income will increase because the earnings that used to go to dividend now can be retained, on the other hand, the number of outstanding common shares also increased due to the conversion. In this case, there is a scenario where the diluted EPS if converted can actually be higher than the basic EPS, if this happens, the diluted EPS sort of loses its meaning of providing a good projection of the potential downside. Both IFRS and GAAP require that this kind of EPS – Antidilutive Security be excluded from the diluted EPS calculation.

Now, let’s do some simple calculation and see under what situation Antidilutive security could exist.

Say a company’s net income is I, number of common shares outstanding is C and number of preferred stock is P. The term for preferred stock is that the annual dividend paid per share is D and it can also be converted to X amount of common stock if wanted.

Basic EPS = (I – P * D) / C

Diluted EPS = I / (C + P * X)

The constrain is that Basic EPS >= Diluted EPS

(I – P * D) / C >= I / (C + P * X)

After a bit transform, we got: X*I – D*C – P * X * D >= 0

I like to rearrange it into the following format:

D <= I / (P + C / X)

This is easy to interpret, P+C/X can be interpreted as if all shared got converted into preferred shares. If the dividend is smaller than if all converted to preferred stocks, then it is dilutive. If not, then it is anti-dilutive which should be excluded. So in this case you can see, if the dividend for the preferred stock is too high, or the conversion X is too small, it is highly likely that the constrain will not hold and it will be anti-dilutive. Also, if the number of preferred stock is substantial, this will also become anti-dilutive.

 

 

 

 

Shark Tank Valuation

There is this fantastic TV show Shark Tank from ABC, where startups come to pitch their business to a group of seasoned businessmen/women. The “sharks” will decide if they should invest their own money in those startups, hence, their motivation is to seek for high return and the questions they asked are usually challenging. I have always been asking myself how can the sharks invest that much amount of money, usually hundreds of thousands of money for partial ownership – equity within just a few minutes, and one step further, how can they even tell how much a business worth in the first place? Sometimes, they call out the entrepreneurs “crazy” valuation and sometimes they take the offer the way it is, and sometimes even go beyond what was originally asked.

sharktank

After watch it for a few seasons, you started to see patterns where they pretty much want to understand their income from revenue, margin (in order to calculate gross profit) and net earnings (take home). Relatively speaking, not that much questions about balance sheet or cashflow. Clearly, their valuation are based on those key financial metrics, but the question is how do they go from those metrics to how much a company worth? Thanks to some of the heated conversations every now and then, the sharks will make similar comments like “you are asking for a valuation X multiple of your earnings, you know that will never happen in Y industry, right?”.

Then you have been told the secret, the next question will be WHY a company’s worth is a multiple their earnings and why that ratio is different across industries?

To determine how much anything worth, there are usually several ways, what is the cost, what is the worth of similar product that have been sold recently, and if you ask someone in finance, they probably will threw you off by saying “the current worth of an asset is the sum of all its future cashflows discounted to today”.

Lots of buzz words, right, “cashflow”, “discount”, “asset”..etc. Do not worry, everything should be pretty straightforward after we go through a every day example.

First is to make sure that we are all on the same page that “one dollar tomorrow is not the same as one dollar today”. This is called the time value of money and can be explained using your interest paying saving account. Say you have a very good bank with an interest rate of 10%. There are lots of details go into how actual interest (yield) could different based on when interest are paid and how often are paid, let’s put it on the side and assume $10 is paid the end of the year if you put $100 at the beginning of the year. The you will have $110 at the beginning of next year and 10%*110 = $11 worth of interest will be paid end of the next year, interest will get higher and higher thanks to the interest built on top of earned interest, everyone favorite compounding. So your $100 dollar today look like “worth more” in the future.

Year 0: $100
Year 1: $110
Year 2: $121

Year N: $100*(1+10%)^N

However, in nature, they are same because you take no risk in this investment since it is the bank (I did not go through 2008 so bear with my naiveness here), you do not have to do any work other than providing capital, last, this kind of investment is open to pretty much everyone. Therefore, any reasonable investor shall “take this for granted” if they decide to park their money somewhere else.

If someone is going to ask you to invest or borrow your money, you should expect they pay you back higher than what they borrow you today, or vice versa, you should expect to lend out lower if they promise to pay you back a fixed amount in the future.

From another perspective, $100 next year will equal to $91 today, the same as $110 to $100 in the previous example; $100 two years will equal to $83 today, the same as $121 to $100. Now, we are ready to look at how a company will generate money for its investors.

A company will bear the goal of making profit, making profit to keep its day to day operations (if not, they will not live long), sometimes even to have some profit after paying for all kinds of expenses which is called the net income / earnings. Earnings sometime are reinvested back to the business to scale up its success and sometimes those extra money will be given back to its investors. Of course, depending on the stage of the company and its potential based on various reasons (industry, business model, environment, ..etc), investors will expect different use of those earnings, that is also why some companies pay dividend up to 10% and some tech companies pay literally no dividend. Let’s say the business that go to shark tank is already operating, has already attracted a fixed group of the customer with returning business, the revenue pay for everything with extra. If I am the owner of this business, we can start by assuming all earnings go to our pocket. Let’s even fixed everything else assuming that from now on, they company will make same amount of earnings ($100K) every year for the future. In that case, it is a pretty good way of collecting cash in the future. Using the idea we mentioned, let’s try to convert all those future annal net income to today’s worth. Shall we use the interest rate above? I will say yes for now, for in reality it is probably not this simple, the risk of running a small business is high, you probably will need to put into effort, so you probably should expect an return rate higher than bank interest.

Year1 -> today: $100K / (1+10%)
Year2 -> today: $100K / (1+10%)^2
Year3 -> today: $100K / (1+10%)^3

YearN -> today: $100K / (1+10%)^N

In order to give away this cashcow to you, the entrepreneur probably will trade you fairly at the price of receiving the same amount of the money in the future.

So sum will be a very simple geometric series where the sum can be represented in the following equation:

valuation = $100K/(1+10%) * (1-q^n) / (1-q) where q=1/1.1=1/(1+rate)

Now that we know the magical multiple is pretty much

valution/earning = (1+r)(1-1/(1+r)^n)/(1-1/(1+r))

I plot out a heatmap based on “multiple” using the number of years and IRR (internal rate of return). The interesting pattern is that as the rate increases, the multiple caps at certain value, the higher the rate, the sooner it flattens and the lower its cap is.

Screen Shot 2018-09-16 at 10.48.44 PM

I also expanded the limits of each variable from 1 to 100 and here is the bird view.

Screen Shot 2018-09-16 at 10.50.29 PM.png

As an investor, I might ask myself the question of how long this business might keep making money for me (dividend or capital gain due to reinvested earnings), what will be my required rate that I will expect taking the market interest rate and the premium that I want to add on top of that.

Screen Shot 2018-09-16 at 10.56.45 PM

One can easily tell that the bank rate for investors is usually the big index funds and S&P 500 has already achieved an annual return of ~ 11%. If we double that benchmark to 22% as the required rate of return. Then we can see that by holding the company forever will earn no more than 7 times the original investment. Again, the power of compounding, $100 in 7 years will only worth $25, $5 in 15 years and roughly $1 in 23 years.

As you can see, if your business is attractive enough that your investor believe whatever you do will keep existing forever, also, if you can convince your investors that your business is less risky and at the same time, there is no good equivalent on the open market for investors (low interest), then you will position yourself to the top right of the chart. Of course, this article is based on a strong assumption that the earnings is fixed which it is never, it either can operate only for a few years (less than half of the small business survive the first 5 years), or the earnings could be volatile upwards and downwards for various reasons.

But in the end, hopefully this article is helpful to understand how a company worth from the most basic perspective and what are some of the factors investors and entrepreneurs need to pay attention to fairly evaluate and determine a company’s worth.

Part words from Shark Tank again “in sales, we trust”

Credits:

  1. SharkTank from ABC, screenshot, comments, copyright reserved to the original author.
  2. Yahoo Finance

Degree of * Leverage

Within Corporate Finance, there is a focus area where management optimize their cost structure. There are several key measurement to identify business risk under the name of leverage. They use the term elasticity of one percent change in one variable with regard to unit percentage change in another variable. The most commonly used degree of operating leverage and degree of financial leverage.

Attached is a screenshot of how I derived the equation based on the definition.

Screen Shot 2018-08-19 at 7.54.02 PM

In the end, the term degree of total leverage is defined as %change in net income over %change in units sold. Once should reach to the conclusion easily that DTL = DOL * DFL

Return-Generating Models: The market Model Beta

R_i = alpha_i + beta_i * R_m + e_i

where the R_m is the return of the market. You can simply get the monthly return for a given stock and the S&P 500 as the market. Run a linear regression and the slope will be your beta.

google_beta

Based on this post from Quantitative Finance from Stackexchange, the Beta calculated was based on the monthly return for the past three years. Comparing with our calculation in Python, the number lines up pretty well.

Note: I was using the close price, when using the open price, it was pretty close too. However, the beta calculated using high and low is pretty different from Yahoo Finance.

yahoo_finance_google_beta

 

Portfolio Risk – Diversification and Correlation

This article is a visualization of a portfolio of two assets where we see how portfolio return and risk changes as the weight changes and the correlation between the two underlying assets changes.

relationship_between_risk_and_return

This is a very typical risk return plot where the horizontal axis represent the risk – standard deviation of the portfolio where the vertical axis represent the expected return of the portfolio. All the data points are color coded by the correlation between the two assets (eg. purple +1, 100% positive correlated). It might not be that obvious, but I set the size of each data point to be the weight for asset 1 where the biggest represent all the capital is allocated to the asset one, and vice versa.

Here is a screenshot of the R code to generate the graph above.

r_code_relationship_between_risk_and_return

The key takeaway is that given same expected return, you want to diversify your portfolio in a way where underlying assets are more negatively correlated to each other to reduce the risk. This might sounds magical but the math did serve the purpose of proof. However, it is easier to say than doing, if you have an asset that has a good return, but might correlate positively which you will like to replace, in real life, it will be hard to find some alternative with the same return because if a stock is negatively correlated to what you already have, it probably has a subpar return rate (hedging is another thing if that is what you want to achieve).

Imagine – OMAX Binocular Compound Microscope

Just bought a microscope from Omax and this is a link to that model.

I do not have any professional biomedic education other than the one classes taken in high school and that was a moment where several students share a microscope so did not spend any quality time at all, I guess. Now I have my own 🙂

This model support a 1.3MP Digital camera and you only need to use a regular USB cable to connect it to your computer and you are good to go. Based on the description, the software functionality is highly limited on the MacOS platform but for a newbie like me, it is sufficient! The microscope does not come with any slide so I ordered some preprocessed slide from Amscope, now everything is ready, let’s show you a few photos that I have taken.

The first photo is a bee leg and second is actually a piece of napkin, the following are the pine leaf under different resolution.

 
Image recognition has already been very helpful in facial recognition, object detection and recognition in order to enable cool things like auto tagging, auto driving cars, .etc however, there is also applications at the macro and micro cell. Here is an interesting post from Google explaining how dermatologist use deep learning to detect skin cancer.

ML Demo – Drag&Drop

Context

When I started my career, two things that I kind of shy away from are Excel and Tableau. It is a shame that how much extra effort that I have put into exploring options in Python and R by writing tens of lines of code to implement a pivot in Excel. However, on the bright side, you did become more proficient with the programming method and probably had a much deeper understanding of the underlying implementation of “pivot” because you know “reshape” could be much more powerful and predictable. The con is also very clear, now very few people can use your work. Only the coders now, and what is even worse, many coders do not read/use other people code and prefer do it themselves :). Given that, sometime you might think it is probably a good idea to put a user interface on your hardcore but beautiful applications because it is reusable, and now much accessible to a broader audience. In a series of blog posts, I am trying to build a machine learning demo that people can build a “hidden rule”, a “secret”, a “customized pattern” that we are trying to reveal by using machine learning. A key first step is how to help users easily build some rule. You can definitely ask the user to enter some rule like “if attribute_1 > 1000 then …”. However, you might be surprised at how hard it will be even to let average human being to enter that logic into computer (talk to your grandparents and give it a try). A good starting point is probably to have some drag and drop.

I am by no means a front-end developer, in this blog post, I am trying to explore some options and equip myself with some basic knowledge of the existing options out there. If I can build some drag and drop user friendly solution to build a if statement, I will declare a victory. So let’s get started.

0. Requirements

1. HTML5 Drag&Drop

W3Schools

A quick Google search says drag and drop is a built-in attribute in HTML5. Here is an example from W3schools showing how you can drag and drop an image in/out of an empty box.

There are a few key attributes related to drag and drop we need to highlight:

source

  1. draggable=”true”: the object need to be configured in order to move it
  2. ondragSTART=”drag(event)”: ev.dataTransfer.setData(, )

target

  1. ondragOVER=”allowDrop(event)”: preventDefault() will now show a green plus sign indicating that you can drop now
  2. ondrop=”drop(event)”: what do you expect to happen on the drop (mouse release). preventDefault() + ev.dataTransfer.getData() + ev.target.appendChild() will add certain content to the target object.

The example from W3Schools is very helpful, I also added a few more boxes with attributes configured to be different value so that you can understand how the objects will react accordingly. You can see my modified version here.

MDN Web Docs

At the same time, there is a much more comprehensive documentation about everything drag and drop from MDN Web Docs. They introduced the attributes above in further depth and at the same time, mentioned many other concepts like define the drag image, effect, etc.

They also included a few demos here and the one that I like the most is the parking demo, a game where you can park certain car during certain time by dragging and dropping. You can find the source code here.

2. Existing Library

jQuery Query Builder looks like a very promising library that a non-technical user will be able to build pretty sophisticated logic.

You can with with Query Builder in jsfillder by clicking here.

Screen Shot 2018-05-19 at 11.59.27 AM

 

Feature Construction for LM – Polynomials

In Sutton’s book “Reinforcement Learning – An introduction” draft 2017 Nov Chapter 9.5.1. The Author discussed a scenario where one can construct features for a linear model using “interactions” between different dimensions of a state.

Screen Shot 2018-02-10 at 10.43.40 AM

It is a very short math equation but not quite straightforward to fully comprehend. Let’s raise a few examples to help understand this equation more intuitively and hopefully we can understand why there are (n+1)^k different features.

Let’s assume that we have three dimensions in the state space, like the physical spatial position of an object. In this case, k=3. Let’s assign different values to n starting from value 0 and see how that math equation unfolds as we grown n.

Screen Shot 2018-02-10 at 11.00.40 AM