# LINQPad, an essential tool for .Net programmers

Good evening everyone, Since I started this blog I wrote a few posts about computer science and programming in particular, but I recently realized that I hardly ever discuss which tools I recommend. The reason why I thought it was a waste of time is because most of the time, blogger will talk about a given tool because the editor contacted them and gave them a free license against a review. With proper disclosure of the arrangement and an objective point of view of the product, I don’t see any problem with that, but I though there was already enough material available online to discuss well-known tools. However, I think some of them remain unknown and in some instances quite unfairly so. The tool I want to talk quickly about in this post is a perfect example: it’s call LINQPad. First, I want to say that I did not have any contact with the editor, and that I bought my license (which enables more options, I’ll come back to this, but the main features are free).  Hence, this “review” is totally objective. LINQPad is a lightweight software which can be run as a single .exe (whithout any installation required except the .net framework). It has mainly two purposes:
• It is a C# and F# Scratchpad
• It helps browse and mine data sources easily

Basically, LINQPad allows you to write a snippet of code in C# or F# and to display some output without having to create and compile a Visual Studio project. This is really incredibly useful. In a previous post, I discussed the advantages of functional programming. If you wanted to try my example, you would have to open Visual Studio, create a C# console project, write the code in the Main method, compile and see the result in the console. Using LINQPad as a scratchpad, I can simply copy and paste the code, use the Dump() built-in extension method for any object to display it as output and hit F5. I made a little screenshot of the screen’s important parts:

This example is fairly basic, but the cool thing is that you can access almost anything in the .Net framework and, if you need to, even reference some of your own DLLs or a even a Nuget package.

## Data browsing and mining

Another power feature of LINQPad is its ability to allow you to “import” data source and interact with them easily. As a matter of fact, it comes with several built-in or third party providers which will help you through a simple wizard to configure the access to a given data source which you will then be able to query using LINQ. These data sources can be various: SQL, MySQL, RavenDB, Web Services and so on. Once the wizard is complete, you can access just as you would browse any type of collection which supports LINQ. Again, you can write some scripts to retrieve some records, process them and display what you need. This is extremely useful if you have a database with a lot of data and you want to try different ways of displaying the information for example. It’s also very useful if you built some software but you didn’t have the time to write the administration part, you will still be able to extract the data and use it before you get the chance to create beautiful grid and everything -or before you actually give up because LINQPad might be enough if you don’t need to be over user-friendly. That’s it, have a look at it, and buy it if you want to have some nice features like the intellisense and helpers of the sort. It really helps me a lot and avoids me creating a lot of useless visual studio projects. Cheers, Jeremie

# CFA Level II: Valuating Bonds with Embedded Options

Good evening everybody, Tonight’s focus will be dedicated to valuing bonds with embedded options. I chose this topic because it involves binomial trees, which is an important an very testable point of the Level II curriculum.  Binomial trees are encountered in two different topics: Fixed Income and Derivatives. Although the concept is the same for the two instances,  the main difference is the fact that the interest rate tree is given, whereas you have to construct the tree for stock values yourself. Besides, in interest rate trees, the probability of going to up or down nodes is 0.5. For options on stocks, you have to determine the risk-neutral probability value. For simple bonds with no embedded options, in each node, you write:
• The current price of the bond for the remaining payments (including face value)
• The coupon at that node
• The interest rate (more specifically the forward rate) at that not (which is given).
You use the interest rate tree using backward induction, i.e. you start by the node at the right of the tree (the ones the further away from now) where you know the price: the face value. It’s the only place where you know what the price will be. At a given node before the final layer, you have to compute the price of the bond which is given by computing the average (because the probability of ups and downs is 0.5) of the present value of the prices at the two following nodes. To compute the present value, you use the forward rate given at the current nodes. Therefore, there are no forward rates given for nodes at the final layer. Using this process sequentially for each node from the right to the left of the tree, you end up computing the initial node’s value: the price of the bond today. Because the interest rate trees are built to be arbitrage trees, they are computed such that the benchmark security’s price you get using the tree is the market price. So if you compute the price of a bond which is different from the benchmark, you will get a different value. This is where spreads come into play. Nominal spreads are computed using YTM. You compute the constant yield implied by the market price of the bond and its benchmark, and you compute the difference between them. However, this is not a good measure as it assumes the yield curve is flat. The Z-spread, for zero-volatility spread, is the spread that is added to each of the term structure’s rate to make its price equal to the benchmark’s price. You can do exactly this by adding the Z-spread to each of the nodes’ rates (you use a value to add to each node’s rate until you find the right value, by trial and error). For bonds with embedded options, you do exactly the same as for the option-free bond, but the price at the nodes where the call can be exercised you compute the price using the option’s criteria. For example, for a bond callable at 100 in 2 years, if you compute that the price at the second node is 101.5, then you have to use the price which is equal to $\min(101.5,100)=100$. Recall the following for bonds with embedded options: $$V_\text{callable}=V_\text{option-free bond} – V_\text{call}$$ $$V_\text{putable}=V_\text{option-free bond} + V_\text{put}$$ The thing is, the market value of the bond with the embedded option will often be different than is theoretical, arbitrage-free, value.  The reason for this comes mainly from the fact that the interest rate tree assumes some interest rate volatility. Remember the following very important facts:
• Option-free bonds prices are unaffected by interest rate volatility, they are priced as of today and that’s it.
• The price of the embedded option (call or put) is positively related to interest rate volatility.
When we make the valuation of the bond with the embedded option, we essentially compute the value of the cash flow assuming the interest rate volatility. In a sense, we price the option-feature of the bond, assuming the interest rate volatility of the tree. However, market can change its expectation on the volatility of the bond, and hence, the price is not the same anymore, because although the option-free bond value has not changed, the value of the embedded option is different. Similarly to the Z-spread, if you find the value you have to add to each node’s rate to get the same value from the tree as the market value, you get the OAS, the option-adjusted spread, which is the spread of the bond “removing” its option feature. You have to use this  spread to compare bonds with embedded option with bonds without embedded options (such as their relative benchmark) or even bonds with embedded options with each other. The price of the option is relative to the volatility of interest rate, not to the credit risk and liquidity risk of the bond; it shall hence be remove to compare inherent quality of the fixed income security. That’s it for this post.

# CFA Level II: Forward Markets and Contracts

Good evening, A few days away from the exam, I am taking a bit of time to post the main picture of some topics on the curriculum, which I think can be simply explained. This post is dedicated to forwards. The rationale behind forwards is very simple. Assume there is an asset $S$ which is worth $S_0$ today. You want to enter a contract with somebody to agree to buy the asset at time $T$ at the forward price $FP$. This might seem a bit complicated at first glance for people not familiar with finance mainly because you do not know what $S_T$ (the price of $S$ at time $T$) will be. Well, the truth in the matter is that… it doesn’t matter. Indeed, there is a way you can replicate the action of buying a stock at time $T$ by doing the following:
1. At time $t=0$:
1. Borrow $S_0$ at the current rate $S_0$
2. Buy the asset at $S_0$
2. At time $t=T$:
1. Repay what you borrowed at time 0 with interest for $S_0 \cdot (1+R)^T$
2. Keep the stock at the value $S_T$.