Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Wednesday, November 14, 2012

Calculating Pricing Probabilities and VaR using commercially available, off-the-shelf software.

B. Hathi 17th Feb 2011.


This blog contains several articles, describing various ways of calculating and modelling currencies (FX) values. So far all the work is based on my own software, written in Python. This brief article shows how to use commercially available software, in this case 'EasyFit' from Mathwave, to model pricing probability of the Pound Sterling versus the US Dollar (GBP/USD) from historical data. 

 
Before I attempt to calculate what I am calling the ‘pricing probability’ or PP for short, it is important to define what I mean by the term PP. Firstly, I could have chosen this term to be ‘valuation probability’ as in the case of the currency pair GBP/USD [as with many financial instruments], both its value and its price on any given day mean the same thing. Let me define the PP as the probability of a currency pair increasing (or decreasing) from a given entry point relative to its historical data. This definition might make the concept sound like making driving decisions on a windy road based on the views from a rear-view mirror – and indeed it is, but since value is relative, one of the main ways of valuing any traded instrument is to compare its current price relative to its historic levels. When we say “instrument x is cheap”, for example, let’s say “price of the oil company BP is cheap at 300p” – what we mean is the price at 300p is cheap relative to its historical price distribution. So clearly one of the ways of basing buy/sell decisions has to be by comparing with historical data. The reader should be aware that there are other factors such as future expectations that are used to finally arrive at a trading decision, so using historical valuation own its own might be unreliable. In mathematical terms, a well fitted probability distribution function (PDF) around a histogram spread, gives probability of finding an instrument at a value x. The area under the PDF curve equals to one, as all normalised probability calculations should. Clearly, if we partition the area under the curve by drawing a vertical line at the value of interest, e.g., an entry point or a buy/sell decision point, we get two probabilities: one in our favour and the other against.
Anyway, that’s enough of the theory and me rambling on. Now let me walk through an example of finding PP of GBP/USD. 



  • The first step is to get the historical data. In my case I have compiled my historical data, which consists of daily GBP/USD valuations, from the US Federal Reserve website. Also, we need to install the EasyFit software – follow instructions from their website. After a successful installation, you should see under Excel ‘Add-Ins’, an ‘EasyFitXL’ icon. Also, a stand-alone version of EasyFit will be installed on your computer. I learnt how to use EasyFit by watching their video. 



    •   Next, choose one of the many distributions that best fits a data set. In the case of GBP/USD, I’ve chosen the ‘Burr distribution’ as it ranks highly on the three distribution ‘goodness of fit’ tests.

    • To calculate probabilities, we need to right click on the chosen distribution and select ‘Stats Assistant’ from the options. On entering a value - in this case I’ve entered GBP/USD = 1.60 - we will get the two probabilities. If we strongly believe that the distribution is reliable, then these numbers are telling us is, the probability of the Pound rising is 67% based on the historical valuation. Clearly, the important question to ask is: “ do we believe historical indicators on a case-by-case basis?”
    • To calculate the Value at Risk (VaR), we repeat the process on a new column of data that represents daily changes. I usually find that the ‘rate of change’ of any [original] distribution is well described by the familiar normal distribution. From Figure 4, the first step is to multiply the standard deviation by a confidence factor, which for normal distribution is either 1.65 x std for 95% confidence level and 2.33 x std for 99% confidence level.
    • In the Pound’s case we see that the daily VaR(at 95%) = 1.65 x 0.01015 = 0.0173 (or 173 pips). Daily VaR(at 99%) = 2.33 x 0.01015 = 0.0237 (i.e., 237 pips). The next step of calculating the VaR over a period of forward interval - given that the uncertainty in value grows over time at the rate proportional to the SQUARE ROOT (of time) – we calculate the VaR over, say, a 3-month (~ 62 trading days). So VaR (at 95% and 3 months forward) = +/- 0.0173 x sqrt(62) = 0.1362 (or 1,362 pips) . If our entry point is at, say, GBP/USD = 1.60, then in the next three months its value should be found in the range: 1.4638 to 1.7362 .

    In cases of portfolio VaR, we need to describe the risk levels in terms of values affecting the portfolio, but the underlying principle shown above should be valid. I prefer to work in percentage changes rather than actual value change as this scales the original values even if the new value in future is significantly different from the original value.




      Source | The Currency Forecasting Blog (CFB) | http://currency-forecasting.blogspot.com/2011/02/calculating-pricing-probabilities-and.html

      Tuesday, November 13, 2012

      Using The Gaussian Kernel Density Estimator (GKDE) to assess Risk.

      B. Hathi , 18 / April/ 11

      In several walks of life, we come across the common problem of having to assess risk given certain amount of data. The word ‘risk’ can be used in many contexts and has different meanings – for example, we may refer to risk in qualitative terms as being ‘high’ or ‘low’; we may assign a quantitative measure such as some function of standard deviation (or variance) about an ‘Expectation Value’. In this case, by ‘risk’ I mean calculating probability of an unfavourable outcome.


      To calculate probability, we start off with a data set; plot normalised histogram, fit some distribution function (normal distribution is a good starting choice amongst the many distribution fits) and finally calculate the Probability Density Function (PDF) or its inverse, the Cumulative Distribution Function (CDF). However, we may find that none of the standard distributions fit our data set well enough to inspire confidence. Take the Gbp/Usd data set for instance: my previous article’s Figures 2 & 3  show that despite best attempts, none of the fits describe the data set well enough. Now there are two routes available to tackle the problem. One is to break the problem down into many components – in this case, we would assess Pound’s valuation against [US and UK] inflation, GDP, trade balances etc - and try to find relationships between them (or covariance matrix); plot univariate distributions with respect to each parameter; and combine using methods such as Copula (which basically relates a joint distribution to its individual components via the covariance matrix) . The second approach is not to try and untangle the mess and take the distribution at its face value and either apply a bimodal (or even multimodal) normal distribution, or apply the GKDE. Both methods – the Copula and the GKDE – have their merits; one difference I can see is that GKDE is a great way to quickly assess the probability, while it is limited if you want to calculate the Expectation Value using a continuous distribution assumption, since integrating a mathematically unknown equation would be a problem. I am sure some readers can add more details.

      Figure 1 below shows the GKDE fit to the same data set as in my previous article  – the Gbp/Usd. The red line shows the results of the GKDE fit and using a box integrator, we can easily compute the area under the red curve.

      Figure 1. The yellow histogram bars show Gbp/Usd valuations since 1971, while the overarching 'red' line is the GKDE fit. Since the data are normalised, the area under the curve equals 1. Probabilities can be found by taking area from current price to its left or right side by using the box integrator function. 

      Needless to say that I developed this software in Python, using Scipy’s stats module which contains the kde module. Additionally, I have introduced a functionality to calculate area under the curve that stretches equally in both directions about a current value (based on some multiple of the standard deviation) and returns the probability of both sides. Clearly, since we have a full GDKE plot, any partial computations of probability, such as current value +/- 1.std, will not add up to 1 and we need to normalise this.
      Source | The Currency Forecasting Blog (CFB) | http://currency-forecasting.blogspot.com/2011/04/using-gaussian-kernel-density-estimator.html

      Example trade using Bollinger Bands




      This picture is a chart of GJ where you can see my entry, SL and TP. It was taken right after I enter the market. I opened 2 post there.



      This picture was taken this morning after the price has moved. Its a beautiful picture and it works most of the time.



      This is a daily statement of yesterday trade. You can see that I have closed the 2 GJ post earlier than my TP target. Anyway yesterday was a good day to trade. As for today GJ continue to go uptrend with a correction coming soon. Wait for that correction and enter if the strength holds.

      Source | 24/7 UP To Date Forex News - Foreign Exchange Market | http://247forexnews.blogspot.com/2010/11/example-trade-using-bollinger-bands.html