Here theoretical notes on finance are placed. This is the theoretical base for the development of the finance package.
This a presentation of basic concepts underlying financial risk. It is mainly about the concepts of time, daycount method and value. The concepts are implemented as python code.
First we have a basic observation. It is possible to go into a bank and set up a simple loan or deposit.
A simple loan or deposit is getting or placing an amount now and then at some future time repay or receive the same amount plus accumulated interest. Either way a present value is set equal to a future payment. So we have our first basic but very important modelling concept: The present value of a future cash flow.
This concept actually implies 2 new concepts: Time and value.
In finance the basic time measure is days or dates. On a specific date one part delivers something to the other part. This date can be specified in 2 ways:
- As a specific date
- As a period from a starting point, typically today
In the Python package finance there is an implementation of both banking day calculations and period calculations.
This module contains a subclass bankdate implementing the typical banking day type calculations, i.e.
- adding a number (integer) of years, month or days to a bankdate
- finding the difference in years, month or days for 2 bankdates
- comparing 2 bankdates
- finding the previous or next valid bankdate taking into account weekends and holidays
Wikipedia on Value: ...value is how much a desired object or condition is worth relative to other objects or conditions
Wikipedia on Money: Money is anything that is generally accepted as payment for goods and services and repayment of debts. The main functions of money are distinguished as:
So in this context anything with value is defined as money.
Wikipedia on Store of Value: Storage of value is one of several distinct functions of money. ... It is also distinct from the medium of exchange function which requires durability when used in trade and to minimize fraud opportunities. ... While these items (common alternatives for storing value, the author) may be inconvenient to trade daily or store, and may vary in value quite significantly, they rarely or never lose all value. This is the point of any store of value, to impose a natural risk management simply due to inherent stable demand for the underlying asset.
Wikipedia on Risk Management: Risk management is the identification, assessment, and prioritization of risks (defined in ISO 31000 as the effect of uncertainty on objectives, whether positive or negative) followed by coordinated and economical application of resources to minimize, monitor, and control the probability and/or impact of unfortunate events or to maximize the realization of opportunities.
Basically there are 2 opposite needs driving the price process:
In the following it assumes that 1 sort of money (A currency like EUR, a stock like IBM, commodities like wheat etc) is selected.
If 2 similar loan offers are presented from 2 different banks it would be expected that the present value for the 2 offers to be allmost similar as well. Otherwise the cheapest would be chosen. This is a consequence of the informed market. Hence the law of one price.
Even better, if it is possible to borrow to the cheap rate and invest to the expensive rate. That way an arbitrage is made. In theory an arbitrage is often assumed not to exist.
A dateflow is a set of future T ordered (after time) payments at times expressed as dates. These payments can be considered vectors. Ie. dateflows that be added and multiplied like normal vectors after filling with zeroes at missing times so that the 2 vectors have the same set of times. So in the following there will be no difference between vectors with ordered keys and dateflows.
The maturity of a dateflow is the biggest time with a non-zero payment.
The concept of dateflows are implemented in the Python module dateflow. The times in the dateflow are based of concept banking day described above.
The class dateflow is a set of 1 or more pairs of a bankdate and and a (float) value. The operations are
Consider a time vector at times and a time vector at times .
In order to add, subtract or multiply and they must first have the same set of times, ie. . Then eg.
Definition, positive vector:
A vector is a row vector and ie all vector values are nonnegative ie all vector values are nonzero and at least one vector value is positive ie all vector values are positive
Off course the definition for negative values is similar, ie:
It is possible to sell dateflows in order to recieve a (positive) price now and vice versa.
Definition, financial market:
Consider a selection of N dateflows (dateflow). Every dateflow can be traded at a price .
A financial market is the set of where is a columnvector of nonzero prices.
And is a matrix where each row is a dateflow and all dateflows has been filled with the necessary zeroes so that all dateflows has a value for all dateflow times.
A financial market can be considered as a set of related dateflow instruments, eg in the same currency and/or in a specified timespan.
A portfolio is a set of amounts of dateflows from a financial market. A portfolio , has dateflow and price or .
Lemma (Stiemke’s Lemma):
Let be a matrix. Then exactly one of the following statements are true:
Assume they both are true. Then
This can’t be true because and
means that .
Hence the two statements can’t be true at the same time.
Now assume that they are both false, ie
And again since and means that .
But every vector in the orthogonal subspace of will give .
Contradiction again, meaning that at precisely one of the statements must be true.
An portfolio is an arbitrage if either the price of the portfolio is zero, ie and the dateflow is positive at at least one future point, ie or if the price is negative (giving money to the owner right away) ie. and maybe also gives the owner a future dateflow, ie. .
In short a portfolio is an arbitrage iff .
A financial market is arbitragefree iff there is no arbitrage portfolio in the market.
Theorem, arbitragefree financial market:
A financial market is arbitragefree iff there exists a strict positive price vector such that . Here is refered to as the discount vector.
From definition of an arbitrage we have:
A financial market is arbitragefree iff there is no arbitrage portfolio in the market.
A portfolio is an arbitrage iff .
So there can be no portfolio such that . According to Stiemke’s lemma .
Definition, complete financial market
A financial market is complete iff for all discount vectors there exists a vector such that .
From linear algebra it is known that a necessary condition for a market market to be complete is that , ie the number of dateflow in the financial market must exceed the number of time points to discount.
A mathematical definition a financial market being complete is that the function is surjective.
In words completeness happens when there are more instruments than prices.
Theorem, existence of discount factors
Let a financial market be arbitrage free. Then it is complete iff there exists a unique vector of discount factors.
Assume first completeness.
First find the vectors that has the unity vector , ie . They exist due to completeness.
is a matrix having as row vectors and rank T, .
Then we have and and hence that there can be only 1 vector of discount factors.
Now assume the uniqueness of the vector of discount factors.
Further assume that the market is not complete. Then there exists a nonzero vector such that . Choose a number a such . This is a second vector of discount factors which is a contradiction.
Definition, zero bonds:
The dateflow of a zero bond at time t has value 1 at time t. Hence in a financial market the dateflow of a zero bond is a unit vector where the only nonzero value, 1, is at the place reserved for time t.
Theorem, discount factor base for a financial market
Assume an arbitrage free and complete financial market. Let be the unique discount vector. Then the price of a zero bond at time t is , the discount factor reserved for time t.
First find the portfolio that has the dateflow , ie . It exist due to completeness.
The price for the dateflow is:
A consquence of the theorem is that every instrument is to be considered as a portfolio of zero bonds thus making a financial market and portfolios herein to portfolios of zero bonds.
It is possible theoretically to carry on with the concept of a financial market . The problem is that soon becomes very big. But ussually the market is not complete.
The number of columns (T) might correspond to every day in mayby 30 or 50 years and the problem is to find at least the same amount of trades in order to calculate the discount factors.
The essence of the above theorem is that there is a close connection between zero bonds and discount factors. That prices are only dependent on duration before repayment.
Therefore it would be far better to consider a function which gives a discount factor given a time t. The function would typically have a few parameters and this makes the estimation based on trades much easier.
Definition, discount (factor) function
A discount (factor) function returns the price for every future zero bonds when there is a zero bond for every future date.
From the previous chapter the building stones for modeling a discount function is presented.
First the notion of a financial market, ie. the model is limited to a set of dateflows. These dateflows stems from a set of comparable trades, a notion not yet defined.
It is reasonable to assume that there are no arbitrage in a system since no one wants to give away money. This implies a strict positive price function.
Also even though the markets typically aren’t complete the zero bonds will be used as a base for developing a discount function. This function is assumed to be unique for a market.
In the model above it is assumed that there is a zero bond for each minimum period in the future. This means that the market is complete, so this assumption needs to be relaxed at some point.
Spot rate is the rate observed this very minut. Typically some compounded spot rate or a compounded forward rate.
Definition, scalable discount function:
A discount function is scalable if where is the future discount factor for the minimum period number i. When observed in the market is the discrete time compounded spot price for a zero bond.
A consequence is that the future discount factor for a period from time to time can be expressed as . Note that . When observed in the market is the discrete time compounded forward price for a zero bond.
The minimum period might be a day. Sometimes it make more sense to use minimum periods like a month, a quarter or a year.
In the special case where all the ‘s are equal the discrete time compounded forward price for a zero bond is
When borrowing or lending it is expected at least to repay the amount borrowed or lended. Futher it is expected that there is an earning and/or a cost coverage for having excessive liquidity now. This earning is called the rate and is the price for borrowing.
It is quite easy to see that
where is the price for borrowing one day at day i from now. Since prices usually are positive, it means that usually .
In the special case discrete time compounded forward price for a zero bond is
which the standard textbook formula for discounting using the Bond rate convention.
The rate can be formulated in different ways:
- discrete time versus continuous time
- Continuously compounded discrete rate
- Forward rate
Instantaneous rate occurs when the minimum period converges to zero for the bond rate ie:
which can be seen from
So the right way to combine discount factors and rates are though the exponential function and instantaneous rates.
Further scalability implies that
which means that a discount factor can be described though the summation or integration of the instantaneous rate.
Here is a very short presentation of the problem of using different time at at the same time in finance. More information on this subject will be added in time.
The problem with daily rates is that they are close to zero and especially in the old days it meant problems with rounding errors.
Further if someone is lending or borrowing over a longer periods they would prefer quotes on years, quarters or months etc.
To be able to compare rates they are typically quoted per year. To get the rate per quarter is a matter of dividing the rate quote per year with 4, the monthly rate by dividing by 12 etc.
Since days, months and year aren’t fully comparable it leads to the notion of day count conventions.
In order to do calculations it is necessary to look at time differences and the differences has to be a number. That would not cause any troubles if it weren’t for the fact that price quotes for borrowing are specified pr year, pr half a year, pr quarter of a year or pr month etc.
Days, months and years are measures of time differences of incompatible definitions, i.e. a month is the time elapsing between successive new moons (about 29.53 average days) and a year is the time required for the Earth to travel once around the Sun (about 365 1/4 average days).
Therefore it is not possible to move from one time differences measure to another, and hence the need for Day Count Conventions, see eg
QUOTES PER YEAR implies timeconversion to year fractions in order to do calculations
A class DateToTime is introduced to implement the most important day count conventions and date rolling. Also a valuationday that is chosen.
What it does is given a calculation date and the name of a day count convention it returns the time in years and fractions of years
In the presentation on Time and value the key subject was unique price function. Instead of talking of prices of the cashflows it is customary to talk of the price of lending, i.e. the rate or yield. Here we will look into several different types of yield curve definitions. These yield curves will be implemented in the finance package.
There no implementation of calibration at this point.
Since most yieldcurve models are specified as a sum of one or more simple yield curve functions.
A yieldcurve function must be a callable class. Also a string representation must be defined showing name and used parameters.
Here is the design and the definitions of the functionality of yieldcurve base class in the finance package.
First of all there are some generel functionality:
And then there are the pure calculation functionality which are defined in the subsections below.
This is the base function from which everything else is derived. At time t it is the average rate from now till then.
Since this is the base a future estimation/calibration procedure must also be based on continous_forward_rate. I.e. this is the function that needs to be optimized.
The continous_rate_timeslope is the first order derivative with regard to time. It is used in others calculations. The formula is:
Actually in all textbooks and articles the continous_forward_rate is defined by as the average over time of the instantanious_forward_rate.
But for computational purposes it is better to reverse it. So by definition:
And then it follows:
The discount_factor is giving the present value of the amount of 1 unit at a future time t, P(t). And the formula is:
When a yieldcurve is called as a python function the yieldcurve will return the discount_factor.
The definition of zero_coupon_rate comes from the bond and deposit market. It is a bit like the continous_forward_rate except for how the discounting is done. Here the discount_factor is:
Combining the definition of the discount_factor and the zero_coupon_rate one gets:
So there is a simple relation between the continous_forward_rate and the zero_coupon_rate. The reverse for is:
The discrete_forward_rate is the average rate between 2 future times and . The forward rate is defined as (using no arbitrage):
Taking the log gives:
This way the discrete_forward_rate is the descretized time weighted average of the continous_forward_rate.
If one of the times are zero then formula reduces to the formula for the zero_coupon_rate
Since quotes typically are for the zero_coupon_rate then it makes most sence to define a parallel shift, additive_shift to the zero_coupon_rate giving:
On the other the uses of shift often requires one to find the shift that gives a cashflow a certain target value. In that case it is more feasable to add a shift to the continous_forward_rate. This type will be called a multiplicative shift. It is worth noting that in many textbooks and articles where the authors uses a continous compounding then a shift will be multiplicative.
The reason for the name multiplicative_shift is:
So now it becomes obvious why the multiplicative shift is mathematically more feasable than the additive. This is because the multiplicative_shift_rate is independent of the original yieldcurve when discounting or compounding.
In other words the discounting can be done in 2 steps, first discount the cashflows with regard to yieldcurve and discount the discount the discounted cashflows with regard to a simple yieldcurve with a constant rate (the multiplicative_shift_rate).
Anyway the additive_shift cannot be ignored since there are quotes related to it.
The relationship between the additive_shift and the multiplicative_shift_rate can be seen from looking at the discount factors for a specific future time t expressed though the zero_coupon_rate:
Note however that when additive_shift and multiplicative_shift_rate are calculated for more complex cashflows (ie more than 1 payment) then the relation isn’t that simple.