Rich Newman

December 9, 2007

Business Modules and Interfaces in the SCSF Smart Client Solution (Introduction to CAB/SCSF Part 19)

Introduction

Part 18 gave a brief introduction to the Smart Client Software Factory. This article continues that discussion by looking at business modules, and also examining how the various modules in a Smart Client solution are expected to interact.

Recap on the Smart Client Application

In part 18 we saw that a ‘Guidance Automation’ package in the Smart Client Software Factory lets you create a base solution for a smart client program. It sets up four projects, three of which are infrastructure projects.

One of the projects is an empty ‘Infrastructure.Module’ project. Infrastructure.Module is a CAB module as described earlier in this series of articles: it isn’t directly referenced by the other projects in the solution but can be used to write infrastructural code for the solution without any tight-coupling with the rest of the solution. We’ll examine this in a little more detail below.

Business Modules

It isn’t intended that we put business logic into the Infrastructure projects discussed above. Instead we are meant to create ‘business modules’.

To create a business module we use another of the Guidance Automation packages: we right-click the solution in Solution Explorer, select Smart Client Factory/Add Business Module (C#), click ‘OK’ in the ‘Add New Project’ window and then click ‘Finish’ in the ‘Add Business Module’ window.

This gives us two new projects in the solution with default names Module1 and Interface.Module1 as below:

scsfprojectmodule.jpg

Once again here Module1 is a Composite Application Block module, and is not referenced by any other project in the solution. However, Module1.dll IS added to the ProfileCatalog (which is in Shell). This means that the Load method of a class inheriting ModuleInit in Module1 will get called by the CAB at start up, as described in part 1 of this series of articles. The class with the Load method in Module1 is called ‘Module’. We’ll look at what the Load method is doing in the next article in this series.

Note here that the Module and ModuleController classes are identical to those in Infrastructure.Module. Note also that there’s really no code at all in Module1.Interface: there are just some empty classes in a folder called Constants.

Business Module Interaction with the Rest of the Smart Client Project

As discussed in part 1 of this series, a ‘module’ is a standalone project to be used in a composite user interface. So our business module here is intended to be a slice of business functionality that can potentially be developed independently of the other modules in the application. Because the business module isn’t directly referenced by other modules a separate development team could potentially work on it and change it. It can then in theory be plugged in to the containing framework without the need for code changes in the framework. The other project’s libraries might not even need to be recompiled since they don’t actually reference the business module directly.

Clearly in practice it’s likely that the business module will have to interact with the rest of the Smart Client solution on some level. There will be a need for:

  1. The business module to use the infrastructure components: for example it might need to put a toolstrip into the Shell form.
  2. Other components in the Smart Client solution to use some of the business module functionality. As a simple example we might have a business module that deals with customers and a back-end customer database. It might have screens to show customer data and allow updates. Another business module might want to display these screens in response to a request: an Orders module might allow a double-click on a customer name to show the customer.

We want to achieve the interaction described above in a way that’s as loosely-coupled as possible, so that we can change the system easily. To do this we make sure that all interaction is through the Interface projects.

We now examine each of these possible scenarios in more detail:

1. The Business Module Using Infrastructure Components

For this scenario in our example solution Module1 references Infrastructure.Interface directly. It is set up to do this by default when you add the business module to the solution. Note that Infrastructure.Interface is intended to (mainly) contain .NET interfaces: it is not meant to contain large amounts of code.

Note that Module1 does not reference Infrastructure.Module or Infrastructure.Library directly, nor should it under any circumstances. These projects may well be under the control of a separate development team from our business module team, and they may need to be updated independently of the business modules. So we reference the interface project, and that handles our interaction with the Infrastructure libraries.

This seems to be a concept that developers working on these projects have difficulty with: almost every member of my development team at work has added one of these libraries to a business module at some stage.

I think the confusion arises because it’s not necessarily obvious how we do this. If my module just references an interface how can I actually call any functionality using just the interface? The answer is that we are once again using the dependency inversion and dependency injection concepts described in part 3 and part 4 of this series of articles.

An example here may help.

Example

We’ll use the WorkspaceLocator service that the SCSF adds into the Infrastructure.Library component when we create a Smart Client solution. The WorkspaceLocator service lets you find the Workspace a SmartPart is being displayed in, although this isn’t relevant for this discussion: all we’re interested in is how to invoke the service from a business module.

There’s a class called WorkspaceLocator that actually does the work in SmartClientDevelopmentSolution.Infrastructure.Library.Services. There’s also an interface in Infrastructure.Interface as below:

namespace SmartClientDevelopmentSolution.Infrastructure.Interface.Services
{
    public interface IWorkspaceLocatorService
    {
        IWorkspace FindContainingWorkspace(WorkItem workItem, object smartPart);
    }
}

Note that Infrastructure.Library references Infrastructure.Interface and so WorkspaceLocator can implement this interface. Note also that our business module, Module1, also references Infrastructure.Interface but NOT Infrastructure.Library. So it can’t see the WorkspaceLocator class directly and thus can’t call FindContainingWorkspace on it directly. So how do we use the service?

The answer is that this is the standard CAB dependency inversion pattern using WorkItem containers to access objects.

At start up the solution creates an instance of the WorkspaceLocator service and adds it into the Services collection of the root WorkItem, referencing it by the type of the interface:

RootWorkItem.Services.AddNew<WorkspaceLocatorService, IWorkspaceLocatorService>();

This actually happens in the new SmartClientApplication class mentioned in part 18, but all we really need to know is that the service will be available on the root WorkItem.

Now, in our module we know we can get a reference to the root WorkItem in our new module by dependency injection in a class:

        private WorkItem _rootWorkItem;
 
        [InjectionConstructor]
        public Module([ServiceDependency] WorkItem rootWorkItem)
        {
            _rootWorkItem = rootWorkItem;
        }

Our module also knows about the IWorkspaceLocator interface since it references Infrastructure.Interface. So it can retrieve the WorkspaceLocator service object from the root WorkItem using the interface, and can then call the FindContainingWorkspace method on that object:

            IWorkspaceLocatorService locator = _rootWorkItem.Services.Get<IWorkspaceLocatorService>();
            IWorkspace wks = locator.FindContainingWorkspace(_rootWorkItem, control);
            MessageBox.Show("Workspace located: " + wks.ToString());

In summary, as long as our module knows the interface to the functionality it needs, and knows how to retrieve an object that implements that interface from a WorkItem collection of some kind, it doesn’t need to have direct access to the underlying class to use the object. This was explained in more detail in earlier articles in this series.

2. Other Components Using the Business Module Functionality

For other components to use our business module functionality we are expected to work out what functionality our business module should expose to the rest of the solution. We should then define interfaces that allow access to that functionality and put them into our Module1.Interface component.

Other components in the solution can then reference Module1.Interface and call the functionality. Note that to allow them to do this we need to ensure that the correct objects are available in a WorkItem, as described above. Once again other components should NOT reference Module1. We can then change Module1 without impacting the other components.

We may of course need to change the interfaces. In this case it may be sensible to retain the old version of the interface component itself so not all other components have to upgrade, and to add a new version with the changed interfaces in as well. The old interface can then be disabled when everyone has upgraded.

Conclusion

This article has examined modules in a Smart Client solution, and discussed how they should interact.

Part 20 of this series of articles will look in a little more detail at some of the new code structures in modules in a Smart Client solution.

A Beginner’s Guide to Credit Default Swaps (Part 1)

Introduction

On our team at work we occasionally employ developers who know nothing about derivatives. It usually falls to me to give these guys a general introduction to the credit derivatives business. As part of that we usually have a session on what a credit default swap is and why it’s important. This article is based on what I say in that session, and as such is an attempt to explain the product to someone who knows very little about the financial services industry.


Government Bonds

It isn’t really possible to understand a credit default swap without having a basic understanding of bonds, so we’ll start with a discussion of what bonds are and why someone might invest in one.

Imagine I have some cash and I want to invest it for a long period. Furthermore assume that interest rates are high and I want to ensure I get a high rate of interest for the period. I would ideally like a fixed interest rate. One way of doing this would be to go to my bank and see what they have on offer. However, most banks don’t offer very generous fixed rate deposits, especially over long periods. They prefer to offer you a variable rate.

An alternative is to buy a bond from the government. To raise money almost all governments periodically issue these bonds. The way they work is that you give your money to the government. The government then pays a fixed rate of interest periodically (usually every six months) on the money you give them. The government does this for a fixed period, usually of several years. At the end of the fixed period they will give you your money back. The end of the fixed period is called the ‘maturity’ of the bond. The amount they pay interest on is called the ‘face value’, the ‘notional value’ or the ‘principal’ of the bond.

What makes this even more attractive as an option is the fact that there is a ‘secondary market’ for bonds. What that means is that there is someone who will buy the bond from me should I not want to hold it to maturity. This is like the stock market. You can buy stocks from individual companies when they issue them, and then (usually) sell them on a stock exchange when you no longer wish to hold the stock. In both cases the price you get will depend on market conditions at the time. Clearly the current level of interest rates will have a major impact on the price you can get when you come to sell your bond. Of course you can buy your bond in the secondary market in the first place, rather than buying it directly from the government.

Should you actually want to do this most of the major stockbrokers will also allow you to trade government bonds, although some cheap online brokers won’t.

So for example, if I look on the US TreasuryDirect site right now I can see that on the 15th August 2007 the US government issued a bond that has a maturity of 15th May 2037 with an interest rate of 5% per year. This is paid every six months (so I get 2.5% of the face value of the bond every six months).

Note that in the United States government bonds issued with a period to maturity of between ten and thirty years are called ‘Treasury bonds’, whilst government bonds issued with a period to maturity of two to ten years are called ‘Treasury notes’. However, these instruments all behave as described above, and are often just referred to as ‘government bonds’.


Corporate Bonds

It’s not only governments that issue bonds, companies do so as well. This is a way of raising money for them, the other alternative being to issue stock. These corporate bonds are typically very like the government bonds discussed above: the company will pay you a fixed interest rate on your money for a fixed period. There’s also a secondary market for these bonds as described above for government bonds.

If you are given the choice between a 10-year corporate bond issued by, say, General Motors (a car company) and a US government bond, which one would you prefer? If the interest rates were the same you’d be wise to go for the US government bond. This is because there’s almost no chance that the US government won’t pay you back your money. It’s going to take a world war or something similar for the US government to be in such trouble that it can’t repay (and in that case you’d probably have bigger worries than your bonds). However, companies can get into financial trouble, even big ones (think of WorldCom, or Enron). If a company goes bankrupt there’s a chance you won’t get all the money you’ve given them for the bond back.

For this reason companies are forced to pay a higher rate of interest on their bonds than the US government. Otherwise no-one will give them the money for their bonds. How much bigger the rate of interest has to be depends on how risky the company is perceived to be.

For example General Motors has issued a bond that matures on the 15th July 2033 paying 8.375%. Whilst this interest rate isn’t directly comparable with that on the US Treasury bond discussed above, if you do work out the numbers you will find that you are getting much more interest from the General Motors bond. This article isn’t going to go into the details of how to do this, as it isn’t strictly relevant to understanding credit default swaps.

Further Reading on Bonds

The sections above have given a very simple overview of bonds. These sections have not described how the secondary markets work, how we price bonds, what a yield is or what yield curves are. If you are interested in such things there are some more details at the links below:

http://www.investopedia.com/university/bonds/
http://www.riskworx.com/resources/Yield%20Curves_RiskWorX.pdf

Credit Default Swaps (CDS)

Suppose that we have invested in the General Motors bond mentioned above. Suppose our investment is $10,000,000. Suppose also that we have become worried that General Motors may be getting into financial trouble. What can we do about it? Obviously we could just sell our bond position in the secondary market. However, we can also enter into a credit default swap. The easiest way to think of a credit default swap is as an insurance contract. We are insuring against the possibility that a company might get into financial trouble and cause us to lose money on our bond position.

To enter into this insurance contract we have to find someone prepared to insure us. Note that this is NOT General Motors. The big banks are usually the people to go to.

What we can do is to pay the bank a periodic small amount of money known as a ‘premium’ (which is like an insurance premium). This is calculated as a percentage of the face value of the bond we are insuring against, which is $10m in our case. This amount (the $10m) is known as the ‘notional principal’. The premium is paid every few months (usually every three or six months) throughout the life of the contract.

In return for the premium the bank does nothing unless General Motors gets into financial difficulty. In that case the bank will pay us an amount equal to the amount we have lost on our bond position. This is likely to be a big sum relative to the small premiums that we will pay. Once this happens the contract will terminate. Otherwise the contract carries on for an agreed period (usually five years). In picture form this looks a bit as below:

cds.jpg

Here the Big Bank is the ‘protection seller’: it’s receiving money in return for providing protection against our bonds falling in value. Similarly we are ‘protection buyers’.

Clearly there are a few things that need to be sorted out before we enter into this contract. Since the Big Bank is going to make us a large payment if General Motors gets into financial difficulty we’d better define what ‘financial difficulty’ means very clearly. We’d also better sort out exactly how we’re going to calculate the amount that will be paid.

Physical Settlement and Cash Settlement

The amount to be paid is slightly the easier of the two to define. We know which bond we want insurance on (the one we are holding), and we know we want to get the reduction in its value as a result of General Motors getting into trouble. There are two ways of handling this. The first is known as ‘physical settlement’. Here we give the bond to the Big Bank, and the Big Bank gives us the full face value of the bond in return (i.e. the amount that was originally paid to General Motors for it). The bank will then try to dispose of the bond in the market. Note that it will be worth much less than the full face value. This is because General Motors is in difficulty and hence unlikely to pay back the full face value at maturity. So from our point of view we’ve given up our bond but been paid face value for it: we’ve been compensated for the reduction in the value.

The second method is known as ‘cash settlement’. Here we try to work out the reduction in value of the bond, and this is just paid from the Big Bank to us in cash. To work out the reduction in value usually a ‘calculation agent’ is appointed in the CDS contract. The calculation agent will go into the market and get a selection of quotes for the bond from which a price for settlement will be calculated in an agreed way. Often the calculation agent is the seller of protection (the Big Bank in our example).

Credit Events

Defining ‘financial difficulty’ is more problematic, and indeed has led to several lawsuits already. We don’t usually call it ‘financial difficulty’, by the way. It’s referred to as a ‘credit event’, or a ‘default’. We say a credit default swap contract is ‘triggered’ if a credit event occurs, meaning the Big Bank has to pay up in our example.

There are three broad categories of credit events that are put into the documentation of credit default swap contracts:

  1. Bankruptcy
    If a company goes into Chapter 11 (in the US) then that is a clear indicator that the company is in serious financial difficulty and that the bondholders may not get all their money back. This is an obvious thing to have trigger the payment in a CDS contract.
  2. Failure to Pay
    If a company fails to make payments it should be making, including coupon payments on the bonds, then this can be documented as a credit event.
  3. Restructuring
    This is where a company changes the payment schedules it makes on its bonds, usually with the agreement of the bondholders. It’s usually not to the bondholders advantage when this happens, and hence CDS contracts can be documented to cover this kind of restructuring as a credit event.

Of these, restructuring is the one that has proved the most problematic for the market. There are now four separate standard definitions for restructuring that can be used in CDS contracts.

Size of Premium Payment is Bigger if the Company is More Likely to Default

One question that has been asked is how large the premium will be in general (see the comments).

The Big Bank in our example is providing us with protection against the default of a company (General Motors).  We are paying them the premium for this protection.  Clearly if the company being referred to is more likely to default the Big Bank will want us to pay them more money.  So the premium rate is higher for riskier companies than for safe ones.

The Big Bank will decide which companies it thinks are risky, and hence what premium it should charge, based on a number of factors.  However, there’s already a market that reflects how risky a company is.  This is the bond market as described earlier in this article.  In the example there General Motors had to pay a higher interest rate on its bonds than the US Government because of the risk that the investor wouldn’t get their money back if General Motors defaulted.

Size of Premium Payment and How it Relates to Bond Prices 

Now consider the case where we buy a General Motors bond.  We then enter into a credit default swap to the maturity of the bond as well.  This acts as insurance against General Motors defaulting on the bond.  We receive interest from the General Motors bond, but pay some of it away in insurance on the credit default swap.

In simple terms we now have overall a bond position where we don’t lose anything if General Motors defaults.  If a default occurs we get our money back from the credit default swap.  We can then invest in another bond.

We can think of this as a risk-free bond position.  This is in many ways equivalent to a position in US Government bonds (which we can assume won’t default at all).  We’d expect our overall interest rate to be similar to that of a US Government bond.  Our overall interest rate is the rate on the General Motors bond less the premium on the credit default swap.

Now suppose the interest rate on a US Government bond is 5% and the interest rate on a General Motors bond of the same maturity is 8%.  We’d expect the premium on a credit default swap on General Motors for the same period to be about 3%.  Note that the 3% premium is also called the ‘spread’ on a credit default swap, since it is the spread between the government bond and the corporate bond interest rates.

Note that this is a very simplistic analysis.  It is broadly accurate but there are reasons why it doesn’t work exactly in practice.

Some Other Terminology Relating to Credit Default Swaps

(i) Reference Entity and Reference Obligation

Note above that General Motors is not directly involved in the credit default swap contract. General Motors as a company will not even know the contract exists. The contract is between us and the Big Bank. General Motors is just an entity that is referred to in the contract, and hence is known as the ‘reference entity’.

Similarly the contract refers to the specific bond we are insuring (General Motors 8.375% maturing 15th July 2033 in our example). However the bond isn’t directly involved in the contract. Indeed if the contract is cash settled we don’t even have to be holding the bond at any time: we can just enter into the CDS contract without it. The bond is just an obligation being referred to in the contract, and hence is known as the ‘reference obligation’.

You should know that, at least in technology, everyone’s favourite interview question about credit default swaps is ‘what’s the difference between a reference entity and a reference obligation?’

(ii) Bond Seniority

Bonds have a hierarchy of importance when a company is unable to pay its debts. Some bondholders will get their money back before others. (They ALL get their money back before the shareholders.) The exact place in the pecking order depends on the documentation of the bonds. Typically bonds are classified according to ‘seniority’. They are assigned to one of senior secured, senior unsecured, senior subordinated, subordinated and junior subordinated seniority categories. The list is in order of seniority: senior secured is the highest, junior subordinated the lowest. This means if we hold a senior secured bond we are more likely to get our money back if the company goes bankrupt than if we hold a junior subordinated bond.

When a company is being wound up the bondholders get paid in seniority order out of the cash that is remaining to the company. The bondholders with the highest seniority debt get paid first, then the bondholders with the next level of seniority debt, and so on. Bondholders will get paid in full in each seniority category until the money runs out. If at any stage the money is insufficient to pay the current seniority of bondholder in full, every bondholder of that seniority gets paid the same percentage of the face value of their bond.  So, for example, the most senior bondholders may get paid in full, one category of more junior bondholders will only get a percentage payout, and the most junior bondholders may get nothing.


(iii) Recovery Rates

The ‘recovery rate’ is the percentage of the face value of our bond that we get back if there’s a credit event. For example, suppose we hold $10m of bonds in a company, and it goes bankrupt. Assume we get $4m back for our bonds from the company after the bankruptcy. We would say our ‘recovery rate’ is 40% (4m/10m as a percentage).

Recovery rates are also one of the inputs into pricing a CDS contract (working out its value to either counterparty) prior to maturity. To price a CDS one of the things we need to know is how much the bond we are insuring will reduce in value if a credit event occurs. This is obviously important since it determines the size of the payment made as a result of the credit event. Clearly we can’t know exactly how much the bond will be worth after a credit event before the credit event has happened, so we estimate a recovery rate.

Most pricing methodologies estimate recovery rates in a very simplistic way: a percentage is assigned to the seniority of the debt of a company. So we might say General Motors Senior Unsecured debt has a recovery rate of 40%, and then use that number for pricing all GM senior unsecured credit default swaps.

Uses of Credit Default Swaps

As described above it sounds like the credit default swap is a very niche product since its primary use is to hedge bond positions against default. However, the credit default swap market has taken off and is huge. The reason is that there is a wide range of ways CDS can be used. In recent years pure speculation, largely by hedge funds, seems to have been the main driver of the market.

Geoff Chaplin’s excellent book ‘Credit Derivatives: Risk Management, Trading and Investing’ cites the following uses of CDS:

  • Directional Trading/Relative Trades (speculation on individual companies)
  • Debt Hedging (hedging bond positions as described above)
  • Sector/Portfolio Trades (speculation on groups of companies)
  • Income Generation (we can just sell protection and receive premium, provided we’re confident we won’t face defaults (credit events))
  • Regulatory Capital Reduction (if a bank has lent to a company that uses regulatory capital which can be reduced by buying CDS protection)

Issues

Below are a few further issues relating to credit default swaps:

  • The description of CDS as ‘insurance’ is not technically accurate. Insurance contracts are regulated in a different way, the documentation is different, and usually an insurance contract would require us to actually own the bond to be valid for a claim, which is not the case for a CDS.
  • As mentioned above, there’s no reason for either party to a CDS contract to actually be holding a bond (reference obligation) of the reference entity. CDS can be entered into purely as speculative positions. Even with physical settlement the buyer of protection can just go into the market and buy the appropriate bond at the time of a credit event, and doesn’t need to hold it through the life of the contract.
  • CDS contracts are usually not entered into with retail investors. You or I couldn’t actually execute a CDS on our bond position; we don’t have big enough positions to make it worthwhile in general. Hedge funds, pension funds, fund managers and insurance companies tend to be the counterparties to the banks on these contracts (as well as other banks).
  • Credit default swaps are usually documented such that a range of bonds can be ‘delivered’ (handed over in physical settlement or used to calculate losses in cash settlement). The text above implied that only one bond was ever relevant. The reference obligation cited in the contract simply defines the type of bond that can be delivered (its seniority). Usually any bond of the same seniority or higher seniority can be delivered. CDS can be traded without any reference obligation being cited: usually this means that any senior unsecured debt can be delivered.
  • This is a zero-cost instrument. The two parties to the contract just agree the details up front, and the contract starts without any initial payment being necessary. If you are a seller of protection you just get premium in without having to do anything, which can be attractive.

Summary

In summary, a credit default swap is a contract where one party to the contract pays a small periodic premium to the other, in return for protection against a credit event (financial difficulty) of a known reference entity (company).

This article was written in 2007.  Since then there have been a few developments in the credit default swap market.  A discussion of these developments can be found in part 2 of this series of articles.

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 80 other followers