Wednesday, December 26, 2012

Metrics for Assessing the Financial Health


It's a constant struggle for the managers from non-financial backgrounds to come to terms with various financial statements and measures and gaining insights from them. Needless to mention, I am one among that :). 

Recently I came across a small pocket size finance book released by the Harvard Business School (HBS). Still it was not easy for me, but one chapter that attracted me endlessly was the chapter about important financial metrics. I have given the same in the way I understood them. Hope it will be useful for you as well. Good thing about these metrics is almost all of these are collected from the 3 mandatory financial statements only (Balance Sheet, Income Statement and Cash Flow Statement)  

Profitability Ratios

Gross Profit Margin: This ratio tells you how profitable your goods/services are. Gross Profit includes only the direct costs like raw material and direct labour. It doesn't include any indirect cost like administrative costs or overhead business managers' cost. If you are doing a project, you need to include only the cost of the members who directly contribute to the project. It ignores the company overheads. Good Indian IT service companies are operating at 60~65% gross margin

Gross Profit = Total Revenue-Cost of Goods Sold(COGS)
Gross Profit Margin = Gross Profit/Total Revenue

Operating Margin: This ratio tell you how profitable your goods and services are after taking your operating overheads into account. This is an important metric that gives you an idea of the overheads the company is suffering.

Operating Margin = Operating Profit/Total Revenue

Net Profit Margin: This is a most widely followed metric by the industry. You can compare your net margin with your industry's net margin to compare your company with that of your competitors. This ratio tells you how profitable your goods and services are after considering the operating overheads, depreciation, interest, tax etc. (basically all the cost overheads either direct or indirect). Good Indian IT service companies are operating at 20~22% net margin

Net Profit Margin = Net Profit/Total Revenue

Return on Assets (ROA): This measure tells you how the company is best utilizing its current assets

RoA = Net Profit/Total Current Assets

Return on Equity(ROE): It tells you how the company is best utilizing the owner's or shareholder's equity investments in the company. Basically how much value the company is creating for the shareholders

RoE = Net Profit/Total Equity

Operating Ratios

Days Receivables: This metric tells the average number of days the company takes to receive the money it owed from the external entities like customers. It is assumed that a company that collects the receivables quickly will NOT have many operating capital shortages

Days Payables: This measure tells you the average number of days a company takes to pay its suppliers. It is assumed that a company that takes more days to pay will have that much operating capital for that duration

Days Inventory: It tells you how long it takes for the company to sell the finished goods inventory kept in the warehouses etc.

Liquidity Ratios 

Banker's Ratio/Current Ratio: This measure gives an indication to your lenders (like banks) whether the lender can give loans to your company with confidence. It's a very simple arithmetic, if you have more assets (properties  or collaterals), then lenders will easily give you loans because loan recovery is not a problem

Banker's Ratio = Total Current Assets/Total Current Liabilities

Quick Ratio: It's is something similar to the Banker's ratio, but discounts the assets that cannot be easily liquidated. Here the assets mainly discounted are your unsold inventory because it is assumed that the unsold inventory cannot be liquidated quickly

Quick Ratio = (Total Current Assets - Total Inventory) /Total Current Liabilities

Leverage Ratios

Here leveraging means how you are leveraging your loans to create value for the company

Interest Coverage (IC): This measure tells you how much your company makes (your operating profit) more than the interest payables.  Operating profits are called 'Earnings Before Interest and Tax (EBIT)' also

IC = Operating Profit/Interest Expenses

Debt-to-Equity Ratio (DE): This measure gives you an idea about how the company uses loans against owner's equity. I believe this ratio should be as small as possible which means you are funding your operations mostly from owner's equity and not leading the company to big debt trap

DE = Total Current Liabilities/Owner's Equity

Others

Earning Per Share (EPS): This measure gives you an indication of how much value the company has generated for the stakeholders for each unit of the shares held by them

EPS= Net Profit/Total Number of Outstanding Shares

P/E Ratio: This measure is very popular in the stock markets. It tells whether the share price of a company is high or low against the company's operating performance.

P/E = Current Price of the Share/Total EPS in the Last 12 Months


Tuesday, December 4, 2012

.NET Memory Management Primer


I thought of compiling all that we learned regarding the .NET memory management while working in one of those smart client applications that we were developing for sometime - a suspected memory leak/performance issue. The post is a result of a combination of discussions, study of web resources including MSDN and running profilers like the Red Gate Ants Memory Profiler. You might be knowing some or all of the concepts, but my idea is to keep it as a simple primer where you go and refresh your knowledge and if possible learn something new

3 .NET App Memory Problems

With a managed environment like .NET, you have very little to do, good or bad, in terms of memory management because the lion's share of responsibility is taken by the Garbage Collector (GC), a component of the Common Language Runtime (CLR). Initial goal while designing GC is to completely abstract memory management from the developers. We must congratulate the GC team @ Microsoft in that they almost did that, but for some issues. I think they have done already what's humanly possible and further optimization of GC may not be possible

 It looks like there are only 3 memory related problems you may encounter in your .NET application

  1. Large object heap memory fragmentation
  1. Memory leak in the managed code
  1. Memory leak in the unmanaged code

Before going deeply into the problems, we need to know how .NET framework abstracts memory management from your application

How memory management works in .NET?

Before allocating objects onto the memory, CLR does one important determination- if the object is a large object or a small object. Any objects that is more than 85KB is a large object. If it's a large object then it's allocated in the large object heap. If it's a small object, then it's allocated in the generations based small object heap. The generations in the small object heap are

  • Generation 0 (holds the youngest objects)
  • Generation 1 (holds the older objects)
  • Generation 2 (holds the oldest objects)

The most ideal scenario is your app allocates objects to Gen 0 and de-references (abandoning) it as soon the app is done with using that object.

Large Object Heap

As already told, large objects are allocated in the large object heap by the CLR. Important differences between the large and small object heaps are

  • Unlike the small object heap, there are no generations here
  • Unlike the small object heap, 'compacting' doesn't occur during the garbage collection because it's a very costly process with large objects

What is compacting?
You can imagine a heap as something like a container in which objects are allocated one-on-the-top of the other. If a in-between object is collected by the GC, then the space held by the object is not compacted. For example assume obj A, B and C are allocated (A at the bottom, B in-between and C at the top). Assume there is some unused space on top of C. If B is de-allocated when the GC occurs, then the space held by B will remain as unused, so there will be a gap between A and C. Similar gaps between objects is called large object heap fragmentation and it's the most severe .NET memory problem. Since there is no compacting, next allocation of memory cannot be done effectively and efficiently. Some limited fragmentation may be acceptable, but if there is more fragmentation then there could be out-of-memory exceptions even when there is space in the heap, because they cannot be used due to excessive fragmentation

How to avoid large object heap fragmentation?
  • Better architecture
  • Avoiding large objects as far as possible
  • A kind of LIFO (Last-in-first-out) strategy while allocating/de-referencing objects
  • Forceful app or sub-app closure (not a good one though)

Small Object Heap

Small objects are allocated in the small object heap generations. An object is first allocated to Gen 0 by default. When Gen 0 is full, then GC is triggered. When the GC process is triggered the following happens

  • Objects that have no references are salvaged (means collected) and the memory is freed.
  • Objects that have app references are considered 'live' by the GC and promoted to Gen 1

Hence Gen 0 will be totally free, ready for fresh allocation at the end of the GC process. Same way GC process occurs for Gen 1 and Gen 2 also. Here is what the memory leak occurs

How memory leak occurs?
If an object really not needed by the app has some reference to it, then the object will be considered 'live' by the GC and promoted to Gen 1 (or for that matter Gen 2 as well) by mistake. This is called memory leak

GC Root

GC roots are special areas in memory that are always accessible by the application (like a reference to a static variable). CLR determines if an object is live or not by finding out if any of GC root has direct or indirect reference to the objects allocated by the application. If an object is not referred by any of the GC roots then that memory is identified as 'not reachable' by the application and is a garbage. Hence the GC can collect those objects when the GC process happens the next time

What a .NET developer is supposed to do to avoid memory leak?

The answer is Nothing. CLR is intelligent enough to identify if an object is live or not. But a developer may do blunders like allocating memory in a event handler like 'Timer_Elapsed' events in which case, the object will always be considered 'live' by the CLR and will be collected only when the application is closed.

But you can make your code 'GC friendly' by assigning the objects to null when you know for certain that you are done with using the object. That way GC will be efficient and hence your app too.

Other Learnings

  • Avoid finalizers
  • Avoid forceful GC process by calling GC.Collect(). It should be used only under extra-ordinary situations. Also GC.Collect() without any parameter will trigger the complete GC process from all the generations and large object heap too
  • Avoid large objects
  • Never allocate memory in the event handlers
  • Make your code GC friendly by assigning objects to null when you are done with using the object. This is not a must, but improves the efficiency of the whole system