<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Quantitative Finance Collector]]></title> 
<link>http://www.mathfinance.cn/index.php</link> 
<description><![CDATA[Quantitative Finance Collector is a blog on Quantitative finance analysis, financial engineering methods in mathematical finance focusing on derivative pricing, quantitative trading and quantitative risk management.]]></description> 
<language>en-US</language> 
<copyright><![CDATA[Quantitative Finance Collector]]></copyright>
<item>
<link>http://www.mathfinance.cn/european-option-price-with-excess-skewness-kurtosis/</link>
<title><![CDATA[European Option Price with Excess Skewness and Kurtosis]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 10 May 2013 11:57:37 +0000</pubDate> 
<guid>http://www.mathfinance.cn/european-option-price-with-excess-skewness-kurtosis/</guid> 
<description>
<![CDATA[Stock returns however exhibit nonormal skewness and kurtosis as pointed out by Hull (1993) and Nattenburg (1994). Moreover, the volatility skews are a consequence of the empirical normality assumption violation. For this reason, Corrado and Su (1996) extend the Black-Scholes formula to account for nonnormal skewness and kurtosis in stock returns.<br/><br/>This package calculates the European put and call option prices using the Corrado and Su (1996) model. This method explicitly allows for excess skewness and kurtosis in an expanded Black-Scholes option pricing formula. The approach adapts a Gram-Charlier series expansions of the standard normal density function to yield an option price formula that is the sum of a <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black–Scholes option price</a> plus adjustment terms for nonnormal skewness and kurtosis (Corrado and Su, 1997).<br/>For skewness = 0 and kurtosis = 3, the Corrado-Su option prices are equal to the prices obtained using the Black and Scholes (1973) model.<br/><br/>You can download the Matlab code at <a href="http://www.mathworks.nl/matlabcentral/fileexchange/41551-corrado-and-su-1996-european-option-prices" target="_blank" rel="nofollow">Corrado and Su (1996) European Option Prices</a>.<br/><br/>References: <br/>Corrado, C.J., and Su T. Skewness and kurtosis in S&P 500 Index returns implied by option prices. Financial Research 19:175–92, 1996.<br/><br/>Corrado, C.J., and Su T. Implied volatility skews and stock return skewness and kurtosis implied by stock option prices. European Journal of Finance 3:73–85, 1997.<br/><br/>Hull, J.C., "Options, Futures, and Other Derivatives", Prentice Hall, 5th edition, 2003.<br/><br/>Luenberger, D.G., "Investment Science", Oxford Press, 1998.<br/>Tags - <a href="http://www.mathfinance.cn/tags/black_scholes/" rel="tag">black scholes</a> , <a href="http://www.mathfinance.cn/tags/skewness/" rel="tag">skewness</a> , <a href="http://www.mathfinance.cn/tags/kurtosis/" rel="tag">kurtosis</a> , <a href="http://www.mathfinance.cn/tags/option/" rel="tag">option</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/european-option-price-with-excess-skewness-kurtosis/">European Option Price with Excess Skewness and Kurtosis</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/an-implementation-markov-regime-switching-model-time-varying-transition-probabilities/</link>
<title><![CDATA[An Implementation of Markov Regime Switching Model with Time Varying Transition Probabilities in Matlab]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 27 Jun 2012 08:52:36 +0000</pubDate> 
<guid>http://www.mathfinance.cn/an-implementation-markov-regime-switching-model-time-varying-transition-probabilities/</guid> 
<description>
<![CDATA[This memo explains how to use the MATLAB code for estimating a Markov Regime Switching Model with time varying transition probabilities. The code is developed by Zhuanxin Ding based on the original code by Marcelo Perlin for estimating a <a href="http://www.mathfinance.cn/markov-regime-switching-models/" target="_blank">Markov<br/>Regime Switching Model</a> with constant transition probability matrix.<br/><br/>Click <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2083332&" target="_blank" rel="nofollow">here</a> for an introduction paper and Matlab codes are <a href="http://www.mathworks.com/matlabcentral/fileexchange/37144" target="_blank" rel="nofollow">here</a>.<br/>Tags - <a href="http://www.mathfinance.cn/tags/markov/" rel="tag">markov</a> , <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/regime/" rel="tag">regime</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/an-implementation-markov-regime-switching-model-time-varying-transition-probabilities/">An Implementation of Markov Regime Switching Model with Time Varying Transition Probabilities in Matlab</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/free-historical-intra-daily-data/</link>
<title><![CDATA[Free Historical Intra-Daily Data]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 16 Apr 2012 09:24:39 +0000</pubDate> 
<guid>http://www.mathfinance.cn/free-historical-intra-daily-data/</guid> 
<description>
<![CDATA[The last decade we have seen a significant increase in the demand for high frequency data. This is explained for a large part by an increased attention of the academic world in algoritmic trading. Moreover, as lot of papers suggest, the profitability has been shifted to an intra-daily format. In this segment, speed is what counts. For instance, Scholtus and Van Dijk (2012) state that strategies that yield a positive return when they experience no delay, a delay of 200 milliseconds is enough to lower their performance significanlty. Given the competition on the market from large institutions, such as JP Morgan and Morgan Stanley, a private investor has always a competative disadvantage due to its lack of the required technology. Nevertheless, there is always room for improvement in the modelling of stochastic intra-daily processes such as the VWAP and <a href="http://www.mathfinance.cn/historical-volatility-estimation/" target="_blank">daily volatility</a>.<br/> <br/>A key ingredient in these research areas is proper and clean (historical and up-to-date) intra-daily data. On the web there are various resources available, but most of them require a relatively high fee. Other solutions require the use of a specific software. However, there are ways to retrieve intra-daily data for free using <a href="http://www.google.com/finance" target="_blank" rel="nofollow">Google Finance</a> and also without any software.<br/> <br/><h3>Using Matlab</h3><br/>If you are familiar with MatLab you can use parts of the package '<a href="http://qoppasociety.org/compendium/programming.html" target="_blank" rel="nofollow">Volume Weighted Average Price from Intra-Daily Data</a>' by Semin Ibisevic referenced at Qoppa Investment Society. This package allows you to<br/>(1) retrieve intra-daily stock price data from Google Finance; (2) calculate the VWAP at the end of each trading day; and (3) transform intra-daily data to a daily format. It is a relatively flexible function as it only requires the user to input the ticker symbol and the exchange where the security is listed on. Additionally, the user can define the frequency of the data (1 second or higher) and the period (for instance past 10 days).<br/> <br/><h3>Without software</h3><br/>If you don't have Matlab you can replicate parts of the code manually. The package above connects with Google Finance and downloads a spreadsheet of intra-daily data consisting of the prices high, open, low, close and volume from: <a href="http://www.google.com/finance/getprices?q=.DJI&x=INDEXDJX&i=60&p=10d&f=d,c,h,l,o,v" target="_blank" rel="nofollow">Google Finance get price 1</a>.&nbsp;&nbsp;<br/> <br/>You can adjust this to your own preferences by 'seeing' the address as: <a href="http://www.google.com/finance/getprices?q=TICKER&x=EXCHANGE&i=INTERVAL&p=PERIOD&f=d,c,h,l,o,v" target="_blank" rel="nofollow">Google Finance get price 2</a>, where<br/>&nbsp;&nbsp;&nbsp;&nbsp;<strong>TICKER</strong> refers to the ticker symbol of the security at Google Finance;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<strong>EXCHANGE</strong> is where the security is listed on;<br/>Hint: to track these inputs, for instance for the Dow Jones Industrial Average, you search the security of interest at Google Finance and then you can find at the top: (INDEXDJX:.DJI) which obviously refers to (EXCHANGE:TICKER).<br/>&nbsp;&nbsp;&nbsp;&nbsp;<strong>INTERVAL</strong> defines the frequency (60 = 60 seconds).<br/>&nbsp;&nbsp;&nbsp;&nbsp;<strong>PERIOD</strong> is the historical data period (see also Google Finance), here 10d refers to the past 10 days (up to current time).<br/><br/>In a world with increasing competition, such solutions are an handy tool to easier the life of a researcher.<br/>&nbsp;&nbsp;<br/><h3>References</h3><br/>Scholtus, Martin L. and Van Dijk, Dick J. C., High-Frequency Technical Trading: The Importance of Speed (February 28, 2012). Tinbergen Institute Discussion Paper 12-018/4. Available at SSRN: <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2013789" target="_blank" rel="nofollow">http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2013789</a>.<br/><br/>Ibisevic, Semin. Volume Weighted Average Price from Intra-Daily Data, 2012, MatLab File Exchange. Available online at: <a href="http://www.mathworks.com/matlabcentral/fileexchange/36115-volume-weighted-average-price-from-intra-daily-data" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/36115-volume-weighted-average-price-from-intra-daily-data</a>.<br/><br/><em>This is a guest post by an anonymous.</em><br/>Tags - <a href="http://www.mathfinance.cn/tags/data/" rel="tag">data</a> , <a href="http://www.mathfinance.cn/tags/historical/" rel="tag">historical</a> , <a href="http://www.mathfinance.cn/tags/google/" rel="tag">google</a> , <a href="http://www.mathfinance.cn/tags/intraday/" rel="tag">intraday</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/free-historical-intra-daily-data/">Free Historical Intra-Daily Data</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/numerical-simulation-stochastic-differential-equations/</link>
<title><![CDATA[Numerical Simulation of Stochastic Differential Equations]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 16 Mar 2011 16:47:39 +0000</pubDate> 
<guid>http://www.mathfinance.cn/numerical-simulation-stochastic-differential-equations/</guid> 
<description>
<![CDATA[Often we have to face the problem of <strong>solving a stochastic differential equation</strong>, and even more often there is no analytic solution, in another words, <strong>numerical monte carlo simulation</strong> is applied. I don't need to write much about this topic as here is a fantastic paper on it already: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.137.6375&rep=rep1&type=pdf" target="_blank" rel="nofollow">An Algorithmic Introduction to Numerical Simulation of Stochastic Differential Equations</a>, in which the author builds around 10 MATLAB programs, and the topics covered include stochastic integration, the Euler–Maruyama method, Milstein’s method, strong and weak convergence, linear stability, and the stochastic chain rule.<br/><br/>M files:<br/><strong>Euler–Maruyama method</strong>: <a href="http://personal.strath.ac.uk/d.j.higham/em.m" target="_blank" rel="nofollow">http://personal.strath.ac.uk/d.j.higham/em.m</a><br/><br/><strong>Milstein’s method</strong>: <a href="http://personal.strath.ac.uk/d.j.higham/milstrong.m" target="_blank" rel="nofollow">http://personal.strath.ac.uk/d.j.higham/milstrong.m</a><br/><br/>more can be downloaded at <a href="http://personal.strath.ac.uk/d.j.higham/algfiles.html" target="_blank" rel="nofollow">here</a>.<br/>Tags - <a href="http://www.mathfinance.cn/tags/simulation/" rel="tag">simulation</a> , <a href="http://www.mathfinance.cn/tags/sde/" rel="tag">sde</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/numerical-simulation-stochastic-differential-equations/">Numerical Simulation of Stochastic Differential Equations</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/markov-regime-switching-models/</link>
<title><![CDATA[Markov Regime Switching Models]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 25 Feb 2011 19:46:41 +0000</pubDate> 
<guid>http://www.mathfinance.cn/markov-regime-switching-models/</guid> 
<description>
<![CDATA[I am not a fan of Markov Regime switching model, it is hard for me to really define how high is a high regime, or how low is a low regime, let alone the method to detect the regime switch. In case you like it, here is a good package for <a href="https://sites.google.com/site/marceloperlin/matlab-code/ms_regress---a-package-for-markov-regime-switching-models-in-matlab" target="_blank" rel="nofollow"><strong>Markov Regime Switching Models in Matlab</strong></a>, it provides functions for estimation, simulation and forecasting of a general Markov Regime Switching Regression. <br/>&nbsp;&nbsp;<br/>Features of the package: <br/>- Support for univariate and multivariate models. <br/>- Support of any number of states and any number of explanatory variables. <br/>- Estimation, by maximum likelihood, of any type of switching setup for the model. This means that you can choose which coefficients in the model, including distribution parameters, are switching states over time. <br/>- A wrapper function for the estimation of regime switching autoregressive models, including multivariate case (MS-VAR) is included in the package. <br/>- The values of standard error for the estimated coefficients can be calculated with 2 different methods. <br/>- Includes a C version of hamilton’s filter that may be used for speeding up the estimation function (see pdf for details). <br/>- Possibility of three distinct distribution assumptions for residual vector (Normal, t or GED). <br/>- Support for reduced/constrained estimation (see pdf document for details). <br/><br/>For instance, as demonstrated <a href="http://blogs.mathworks.com/pick/2011/02/25/markov-regime-switching-models-in-matlab/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+mathworks/pick+(File+Exchange+Pick+of+the+Week)" target="_blank" rel="nofollow">here</a>, 3 regimes are simulated as bull, bear and bull markets as<br/><div class="code">bull1 = normrnd( 0.10, 0.15, 100, 1);<br/>bear&nbsp;&nbsp;= normrnd(-0.01, 0.20, 100, 1);<br/>bull2 = normrnd( 0.10, 0.15, 100, 1);<br/>returns = &#91;bull1; bear; bull2&#93;;</div><br/><br/>it is not easy to tell from the return series graph below whether there is regime switch or if yes, when or which part is bear<br/><a href="http://blogs.mathworks.com/images/pick/michael/potw_ms_regress/potw_ms_regress_01.png" target="_blank"><img src="http://blogs.mathworks.com/images/pick/michael/potw_ms_regress/potw_ms_regress_01.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>it is, however, possible by looking at the output of the package, (again, here is one of the reasons I don't buy it, I have to specify how many regimes we expect, how can I know it?)<br/><a href="http://blogs.mathworks.com/images/pick/michael/potw_ms_regress/potw_ms_regress_02.png" target="_blank"><img src="http://blogs.mathworks.com/images/pick/michael/potw_ms_regress/potw_ms_regress_02.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>the graph shows clearly when the regime switching starts. <br/><br/>Overall the package is excellent if you are a lover of the model, check it out yourself. For GAUSS users, I shared a <a href="http://www.mathfinance.cn/regime-switching-model-library-gauss/" target="_blank">regime switching model library in Gauss</a>before. <br/>Tags - <a href="http://www.mathfinance.cn/tags/regime/" rel="tag">regime</a> , <a href="http://www.mathfinance.cn/tags/switch/" rel="tag">switch</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/markov-regime-switching-models/">Markov Regime Switching Models</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/download-multiple-stock-quotes/</link>
<title><![CDATA[Download Multiple Stock Quotes]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 06 Jan 2011 09:07:25 +0000</pubDate> 
<guid>http://www.mathfinance.cn/download-multiple-stock-quotes/</guid> 
<description>
<![CDATA[I once wrote a small VBA function to <a href="http://www.mathfinance.cn/download-multiple-stock-quotes-from-yahoo-finance" target="_blank">download multiple stock quotes from Yahoo finance</a>, here is another Matlab file pointed out by <a href="http://matlab-trading.blogspot.com/2011/01/yahoo-quote-downloader.html" target="_blank" rel="nofollow">sjev</a>, you can download the M file @ <a href="http://quantum.meplaza.nl/get_yahoo_quote.m" target="_blank" rel="nofollow">http://quantum.meplaza.nl/get_yahoo_quote.m</a>, it downloads quotes from yahoo and returns the data in a struct. The function supports a bunch of symbols and special tags, however, unlike the VBA function, returns the latest record only.<br/><br/>For instance, data = get_yahoo_quote(&#123;'MSFT','IBM','GOOG','GE'&#125;) returns<br/><div class="code">1x4 struct array with fields:<br/>&nbsp;&nbsp;&nbsp;&nbsp;symbol<br/>&nbsp;&nbsp;&nbsp;&nbsp;desc<br/>&nbsp;&nbsp;&nbsp;&nbsp;lastTrade<br/>&nbsp;&nbsp;&nbsp;&nbsp;lastTradeTime<br/>&nbsp;&nbsp;&nbsp;&nbsp;dividendDate<br/>&nbsp;&nbsp;&nbsp;&nbsp;open<br/>&nbsp;&nbsp;&nbsp;&nbsp;lastClose</div><br/><br/>Tags - <a href="http://www.mathfinance.cn/tags/data/" rel="tag">data</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/download-multiple-stock-quotes/">Download Multiple Stock Quotes</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/happy-new-year-2011/</link>
<title><![CDATA[Happy New Year 2011]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 31 Dec 2010 09:20:55 +0000</pubDate> 
<guid>http://www.mathfinance.cn/happy-new-year-2011/</guid> 
<description>
<![CDATA[Happy New Year. The firework movie is generated with Matlab by <a href="http://www.mathworks.com/matlabcentral/fileexchange/authors/15007" target="_blank" rel="nofollow">Joro</a> @ <a href="http://blogs.mathworks.com/images/pick/jiro/potw_fireworks/FireworksGUI.zip" target="_blank" rel="nofollow">http://blogs.mathworks.com/images/pick/jiro/potw_fireworks/FireworksGUI.zip</a>.<br/><br/>Nice.<br/><br/><a href="http://blogs.mathworks.com/images/pick/jiro/potw_fireworks/fireworks_movie.gif" target="_blank"><img src="http://blogs.mathworks.com/images/pick/jiro/potw_fireworks/fireworks_movie.gif" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>Tags - <a href="http://www.mathfinance.cn/tags/blog/" rel="tag">blog</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/happy-new-year-2011/">Happy New Year 2011</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/nearest-correlation-matrix-code/</link>
<title><![CDATA[Nearest Correlation Matrix Code]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 10 Nov 2010 16:07:16 +0000</pubDate> 
<guid>http://www.mathfinance.cn/nearest-correlation-matrix-code/</guid> 
<description>
<![CDATA[Long ago I shared a post for <a href="http://www.mathfinance.cn/nearest-correlation-matrix/" target="_blank">nearest correlation matrix</a> calculation, with the main aim to compute the nearest correlation matrix to an approximate correlation matrix when i.e. the correlation matrix is not positive semidefinite. However, the Matlab codes in that post requires a call of C++ function, specifically, eig_mex(), which brings a problem for some users.<br/><br/>Therefore I re-introduce a Matlab-only file for <strong>nearest correlation matrix</strong> in case you are interested @ <a href="http://www.math.nus.edu.sg/~matsundf/#Codes" target="_blank" rel="nofollow">http://www.math.nus.edu.sg/~matsundf/#Codes</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/correlation/" rel="tag">correlation</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/nearest-correlation-matrix-code/">Nearest Correlation Matrix Code</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/quantitative-finance-co-uk/</link>
<title><![CDATA[Quantitativefinance.co.uk]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 18 Oct 2010 14:14:27 +0000</pubDate> 
<guid>http://www.mathfinance.cn/quantitative-finance-co-uk/</guid> 
<description>
<![CDATA[Quantitativefinance.co.uk is a personal site developed with the aim of sharing some basic knowledge on risk management principles. At the moment it has only a few documents & files, including:<br/><br/><strong>Using OLS regression to estimate alfa and beta of CAMP</strong>: Those routines estimats alfa, beta, R2 coefficient, Jarque-Bera statistic, Durbin-Watson statistic and more.<br/><strong><a href="http://www.mathfinance.cn/maximum-likelihood-estimation-cir-interest-rate-process/" target="_blank">CIR</a> and <a href="http://www.mathfinance.cn/vasicek-model-estimation/" target="_blank">Vasicek</a> 1 FACTOR model for estimating the term structure</strong>&nbsp;&nbsp; This routine calculate the term structure parameters according to the CIR and Vasicek models. You can't parametrize the data source for estimating the model's parametrs but you can easly do that by changing the source code.<br/><strong>CIR and Vasicek 2 FACTORS models for estimating the term structure</strong>&nbsp;&nbsp; The routine is the same of the previous one but use a 2 FACTORS model.&nbsp;&nbsp; <br/><strong>Pricing an europen option</strong>&nbsp;&nbsp; This is a very simple routine that calculate the value of an european option using both <a href="http://www.mathfinance.cn/tags/monte_carlo/" target="_blank">monte carlo simulation</a> and BS metohd. <br/><strong>Calculating market <a href="http://www.mathfinance.cn/value-at-risk/" target="_blank">value at risk</a></strong>&nbsp;&nbsp; This is a complex routine that allows to calculate the market value at risk using different approaches: asset normal, port normal, beta normal.&nbsp;&nbsp; <br/><strong>The <a href="http://www.mathfinance.cn/creditmetrics-spreadsheet/" target="_blank">creditmetrics</a>© model</strong>&nbsp;&nbsp; This spreadsheet calculates a credit VaR using credit spreads of traded corporate bonds (Credit Metrics). The term structure is estimated using a CIR approach.<br/><br/>Visit <a href="http://www.quantitativefinance.co.uk/" target="_blank" rel="nofollow">Quantitativefinance.co.uk</a> for detail.<br/>Tags - <a href="http://www.mathfinance.cn/tags/quant/" rel="tag">quant</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/quantitative-finance-co-uk/">Quantitativefinance.co.uk</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve-part-II/</link>
<title><![CDATA[Is NAG Toolbox Faster Than MATLABs Fsolve Part II]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 06 Oct 2010 11:13:35 +0000</pubDate> 
<guid>http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve-part-II/</guid> 
<description>
<![CDATA[This is a follow-up of my post <a href="http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve/" target="_blank">Is NAG Toolbox Faster Than MATLAB's Fsolve</a>? I got a few reply immediately after that, <strong>here is a short summary</strong>:<br/><br/><strong>1, NAG's c05nb is faster than Matlab's fsolve with almost the same accuracy, but at the cost of additional programming.</strong> As mentioned by Michael at <a href="http://www.walkingrandomly.com/?p=2907" target="_blank" rel="nofollow">his replied post</a>, c05nb speeds up overall computation time by a factor of 3 from 6.5 seconds to 2.32 seconds on average, which is excellent, but he also realizes "It’s pretty clear that the NAG function isn’t as easy to use as MATLAB’s fsolve function", such as transposition problems and the necessity to set global variables. Luckily, Michael confirms it is currently with NAG technical support and should be updated soon.<br/><br/><strong>2, there are other ways to speed up</strong>, for example, two vectorization method proposed by Michael at <a href="http://rationalize-this.blogspot.com/2010/10/is-nag-toolbox-faster-than-matlabs.html" target="_blank" rel="nofollow">http://www.walkingrandomly.com/?p=2907</a> and VoR at <a href="http://rationalize-this.blogspot.com/2010/10/is-nag-toolbox-faster-than-matlabs.html" target="_blank" rel="nofollow">http://rationalize-this.blogspot.com/2010/10/is-nag-toolbox-faster-than-matlabs.html</a>. It is perfectly fine to use vectorization in Matlab, I didn't pay attention to that since the solo purpose of my original post was to compare the performance of c05nb and fsolve, with the same codes except replacing one command with the other.<br/><br/>Thanks for all your reply and attention, testing process is fun.<br/>Tags - <a href="http://www.mathfinance.cn/tags/nag/" rel="tag">nag</a> , <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/fsolve/" rel="tag">fsolve</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve-part-II/">Is NAG Toolbox Faster Than MATLABs Fsolve Part II</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve/</link>
<title><![CDATA[Is NAG Toolbox Faster Than MATLABs Fsolve?]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 05 Oct 2010 10:36:32 +0000</pubDate> 
<guid>http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve/</guid> 
<description>
<![CDATA[<a href="http://www.walkingrandomly.com/" target="_blank" rel="nofollow">Walking Randomly</a> is a blog I visit frequently devoting to share some fun stuff like how to use things like Matlab, Mathematica, Python, Condor, Beowulf clusters etc. Recently, I was reading a blog post on how to replace <a href="http://www.walkingrandomly.com/?p=1488" target="_blank" rel="nofollow">MATLAB's fsolve function with the NAG Toolbox</a> for MATLAB&nbsp;&nbsp;in order to get quite dramatic speed gains and thought I'd try it out for myself with a practical example in finance.<br/><br/>To make good use of fsolve, the example is to solve the <a href="http://www.mathfinance.cn/markowitz-efficient-frontier/" target="_blank">Markowitz problem</a> by finding an optimal portfolio with minimum variance for a targeted return, mathematically, for a portfolio of n risky assets we want to find the solution to:<br/><img width=352 height=67 src="http://www.mathfinance.cn/attachment/1286188326_1987f3cc.jpg"></img><br/>subject to<br/><img width=110 height=115 src="http://www.mathfinance.cn/attachment/1286188326_95711560.jpg"></img><br/>here r-bar is a fixed pre-desired level for expected rate of return, and a solution is any portfolio that minimizes the objective function (variance) and offers expected rate r-bar. This is an example of what is called a quadratic program, an optimization problem with a quadratic objective function, and linear constraints. By introducing Lagrange multipliers and taking the first&nbsp;&nbsp;derivative a solution to our Markowitz problem is found by finding a solution to the set of n + 2 linear equations<br/><img width=372 height=182 src="http://www.mathfinance.cn/attachment/1286188326_7853799b.jpg"></img><br/>In the end, the problem falls into the standard framework of linear algebra, and amounts to computing the inverse of a matrix: solve Ax = b, and finally fsolve can be used directly.<br/><br/>To make the problem bigger, I set up a pool with 500 assets, randomly simulate 5-year return and optimize my portfolio under a given target return. 500 assets may be too many for most applications but the set-up of this example is fair enough as we usually have to impose other constraints in reality such as the maximum or minimum weights allocated to a certain industry, etc.<br/><br/><div class="code">function MarkowitzWeight = fsolve_markowitz_MATLAB()<br/>RandStream.setDefaultStream (RandStream(&#039;mt19937ar&#039;,&#039;seed&#039;,1));<br/>% simulate 500 stocks return<br/>SimR = randn(1000,500);<br/>r = mean(SimR); % use mean return as expected return<br/>targetR = 0.02;<br/>rCOV = cov(SimR); % covariance matrix<br/>NumAsset = length(r);<br/><br/>options=optimset(&#039;Display&#039;,&#039;off&#039;);<br/>startX = &#91;1/NumAsset*ones(1, NumAsset), 1, 1&#93;;<br/>x = fsolve(@fsolve_markowitz,startX,options, r, targetR, rCOV);<br/>MarkowitzWeight = x(1:NumAsset);<br/>end<br/><br/>function F = fsolve_markowitz(x, r, targetR, rCOV)<br/>NumAsset = length(r);<br/>F = zeros(1,NumAsset+2);<br/>weight = x(1:NumAsset); % for asset weights<br/>lambda = x(NumAsset+1);<br/>mu = x(NumAsset+2);<br/><br/>for i = 1:NumAsset<br/>&nbsp;&nbsp;&nbsp;&nbsp;F(i) = sum(weight.*rCOV(i,:))-lambda*r(i)-mu;<br/>end<br/>F(NumAsset+1) = sum(weight.*r)-targetR;<br/>F(NumAsset+2) = sum(weight)-1;<br/>end</div><br/><br/>I performed the calculations tic; fsolve_markowitz_MATLAB(); toc on a computer running Windows XP, MATLAB 2008b and got the following timings (averaged over 10 runs): 3.35 seconds. <br/><br/>So Michael, are you able to speed up my example for 19.7 times faster?<br/>Tags - <a href="http://www.mathfinance.cn/tags/nag/" rel="tag">nag</a> , <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/markowitz/" rel="tag">markowitz</a> , <a href="http://www.mathfinance.cn/tags/fsolve/" rel="tag">fsolve</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/is-NAG-toolbox-faster-than-MATLAB-fsolve/">Is NAG Toolbox Faster Than MATLABs Fsolve?</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-conference-2010-at-wembley-stadium-london/</link>
<title><![CDATA[Matlab Conference 2010 at Wembley Stadium London]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 29 Sep 2010 14:30:22 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-conference-2010-at-wembley-stadium-london/</guid> 
<description>
<![CDATA[<strong>The Matlab conference this year will be host at Wembley Stadium in London on September 30.</strong> If you happen to be in London that day, this is great chance to join hundreds of engineers, financial professionals, and scientists from leading companies and financial institutions to learn about the newest features and latest functionality of the MATLAB® product family. The conference is free, but registration is required.<br/><br/>You can view the agenda and register online at <a href="http://www.mathworks.com/company/events/conferences/mc2010-linkedin/index.html" target="_blank" rel="nofollow">http://www.mathworks.com/company/events/conferences/mc2010-linkedin/index.html</a>, a few possible interesting events are:<br/><br/><strong>Incorporating Symbolic Calculations into MATLAB with Symbolic Math Toolbox</strong><br/>This master class will show how you can take advantage of symbolic calculations within the MATLAB environment for modelling, simulation, and design tasks. Using the latest features in Symbolic Math Toolbox™, including the new MuPAD notebook interface, two case studies will be examined. A wind turbine model will be developed, documented, and integrated with MATLAB as part of a design optimization study. We will also examine the use of MathWorks tools for symbolic and numeric calculations using an example from the BLOODHOUND Project, which involves a World Land Speed Record attempt and aims to inspire young people to pursue careers in science, technology, engineering, and mathematics.<br/><br/><strong>Parallel Computing with MATLAB</strong><br/>In this master class, you'll see how you can use MATLAB and MathWorks parallel computing tools to solve computationally and data-intensive problems taking advantage of recent advances in computer hardware, from multiprocessor machines to computer clusters. You will learn how to utilise multiple cores in your desktop machine through the new capabilities of MATLAB and Parallel Computing Toolbox. We will also show how to scale applications to computer clusters without changing the code.<br/><br/><strong>Using MATLAB to Scale Index Calculations Through Grids</strong><br/>FTSE Group is a world leader in the creation and management of over 120,000 equity, bond, and alternative asset class indices. Index creation is FTSE's sole business, and the demand for new indices to support more sophisticated investment strategies is growing. FTSE uses MATLAB to enable analysts to work closely with clients while developing algorithms for customised index solutions.<br/><br/>This presentation will describe the results of a proof-of-concept project to demonstrate how MATLAB can be used in a grid to maintain and improve service delivery times while satisfying demand and shortening product development life cycles. <br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/conference/" rel="tag">conference</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-conference-2010-at-wembley-stadium-london/">Matlab Conference 2010 at Wembley Stadium London</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/nonlinear-PCA-toolbox/</link>
<title><![CDATA[Nonlinear PCA Toolbox]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 14 Sep 2010 16:24:12 +0000</pubDate> 
<guid>http://www.mathfinance.cn/nonlinear-PCA-toolbox/</guid> 
<description>
<![CDATA[<div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">Nonlinear principal component analysis (NLPCA) is commonly seen as a nonlinear generalization of standard principal component analysis (PCA). It generalizes the principal components from straight lines to curves (nonlinear). Thus, the subspace in the original data space which is described by all nonlinear components is also curved. <br/>Nonlinear PCA can be achieved by using a neural network with an autoassociative architecture also known as autoencoder, replicator network, bottleneck or sandglass type network. Such autoassociative neural network is a multi-layer perceptron that performs an identity mapping, meaning that the output of the network is required to be identical to the input. However, in the middle of the network is a layer that works as a bottleneck in which a reduction of the dimension of the data is enforced. This bottleneck-layer provides the desired component values (scores).</div></div><br/><br/><img src="http://www.mathfinance.cn/attachment/1284222109_64141876.png" align=left width=240 height=181></img> Interested readers shall download the <strong>Nonlinear PCA Matlab Toolbox</strong> at <a href="http://www.nlpca.de/matlab.html" target="_blank" rel="nofollow">http://www.nlpca.de/matlab.html</a><br/><br/>Tags - <a href="http://www.mathfinance.cn/tags/pca/" rel="tag">pca</a> , <a href="http://www.mathfinance.cn/tags/toolbox/" rel="tag">toolbox</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/nonlinear-PCA-toolbox/">Nonlinear PCA Toolbox</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/reading-csv-in-matlab/</link>
<title><![CDATA[Reading CSV in Matlab]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 09 Sep 2010 15:43:04 +0000</pubDate> 
<guid>http://www.mathfinance.cn/reading-csv-in-matlab/</guid> 
<description>
<![CDATA[I always believe R is better than Matlab in terms of data loading, for example, <strong>read.table</strong>() is able to read a large tab-deliminated file (such as CSV file) easily. You may argue there is also <strong>csvread</strong>() function in Matlab, but don't forget, <strong>csvread() works only with all numeric, or all text data, but not for multiple format file</strong>, which is often used in practice, for instance, a file containing both bond coupon rate and bond issuer name, etc.<br/><br/>Let's say you have a csv file with structure like below<br/><img src="http://www.mathfinance.cn/attachment/1283441304_52136958.png" alt="csv file to import in Matlab" width=500 height=220></img><br/>How to import it in Matlab? csvread() obviously doesn't work as this file has mixed format, and it returns error <br/><div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">??? Error using ==> dlmread at 145<br/>Mismatch between file and format string.<br/>Trouble reading number from file (row 1, field 1) ==> CUSIP<br/><br/>Error in ==> csvread at 52<br/>&nbsp;&nbsp;&nbsp;&nbsp;m=dlmread(filename, ',', r, c);</div></div><br/><strong>dlmread</strong>() does not, either. <strong>textscan</strong>() may work at the cost of inflexibility.<br/><br/>Luckily I found a function called <strong>readtext</strong>(), it can read whatever text (file) you give it, and return an array of the contents, no matter what the format your file is at. Using the same csv file above yields&nbsp;&nbsp;&#123;13*5&#125; cell for further data handling.<br/><br/><strong>Perfect</strong>, download & test yourself at <a href="http://www.mathworks.com/matlabcentral/fileexchange/10946-readtext" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/10946-readtext</a><br/><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/csv/" rel="tag">csv</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/reading-csv-in-matlab/">Reading CSV in Matlab</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-mobile-for-iphone/</link>
<title><![CDATA[Matlab Mobile for Iphone]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 31 Aug 2010 21:43:11 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-mobile-for-iphone/</guid> 
<description>
<![CDATA[Heard of this app few weeks ago but never tried as I am using Gphone (Indeed there is an app for android Gphone, however I didn't download it as it is not developed by MathWorks and received bad feedbacks). So if you happen to have an i-toy, try to connect to your MATLAB remotely from your iPhone, iPad, or iPod touch. <br/><br/><img src="http://www.mathfinance.cn/attachment/1283290737_18388030.jpg" align=left alt="matlab iphone" width=320 height=480></img><br/><strong>Features</strong><br/>Command-line access to MATLAB running on your computer<br/>Access to your MATLAB workspace<br/>Ability to view MATLAB figures on your iPhone<br/>Record of commands typed on the iPhone in your command history<br/>Custom keyboard<br/>Ability to connect to MATLAB running on Windows, Mac, and Linux<br/><br/>Download the free app <strong>Matlab Mobile for Iphone</strong> at <a href="http://itunes.apple.com/us/app/matlab-mobile/id370976661?mt=8" target="_blank" rel="nofollow">http://itunes.apple.com/us/app/matlab-mobile/id370976661?mt=8</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/iphone/" rel="tag">iphone</a> , <a href="http://www.mathfinance.cn/tags/gphone/" rel="tag">gphone</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-mobile-for-iphone/">Matlab Mobile for Iphone</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/send-SMS-in-Matlab/</link>
<title><![CDATA[Send SMS in Matlab]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 06 Jul 2010 13:17:51 +0000</pubDate> 
<guid>http://www.mathfinance.cn/send-SMS-in-Matlab/</guid> 
<description>
<![CDATA[Ros is a colleague of mine in the same office, his main research is empirical analysis of different option pricing models, and as a result, he often use several computers on different desks to run his matlab codes, which is time-consuming and not rare to last 2 or 3 days. So he has to come back office frequently to check which computer has finished the task. It sounds boring, <strong>why not write a small script to send SMS message to you automatically when your matlab stops running</strong>? <br/><br/>Send Text Message to Cell Phone is such a great file I found recently, bascially what it does is to send email via sendmail function of Matlab from your gmail box to your cell phone carrier, and then your cell phone carrier forwards the email to you as a text message. <br/><br/><strong>Problem</strong><br/>However, it works for US based cell phones only, I have tried on my UK T-mobile phone and it seems UK T-mobile doesn't support such a mail to SMS service (correct me if I am wrong). <br/><br/><strong>Solution</strong><br/>Fortunately, I came across SMS service website which allows people to send up to 3 free email to SMS per day, it should be enough for our use in Matlab. Add the following line in the switch case after line 55<br/><div class="code">case &#039;uk&#039;;&nbsp;&nbsp;&nbsp;&nbsp;emailto = strcat(number,&#039;@x-onsms.com&#039;);</div><br/>that's it, the email will be delivered as an SMS to your mobile. Do let me know if you are aware of a better alternative. <br/><br/>So what you need to do is to put the function send_text_message at the end of your file, it will then send you a message automatically, for example<br/><div class="code">send_text_message(&#039;079-123-456&#039;,&#039;UK&#039;, &#039;Desk 12 Calculation Done&#039;,&#039;Now you can shut down the computer&#039;)</div><br/>What else can it be used? stock price alert? profit threshold alarm? <strong>you name it</strong>.<br/><strong><br/>Possible error</strong><br/>Depends on your Matlab version and firewall setting, you may notice the following errors:<br/><strong>1, ??? Error using ==> sendmail<br/>530 5.7.0 Must issue a STARTTLS command first</strong><br/>This could happen for MATLAB 7.1 (R14SP3) and before, you may have to upgrade your version.<br/><br/><strong>2, Could not connect to SMTP host: smtp.gmail.com, port: 25;<br/>Connection timed out: connect</strong><br/>This is due to your firewall or anti-virus software setting. you are not allowed to send email from port 25. What you shall do is too add an exception and let your computer know this action is safe. For instance, I have McAfee, to add an exception, open its <strong>control console</strong> -> double click <strong>access protection</strong> -> anti-virus standard protection -> prevent mass mailing worms from sending mails -> Edit<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/access-protection.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/access-protection.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/><br/>add Matlab.exe as a process to be excluded, save it, done.<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/access-protection-email.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/access-protection-email.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><br/>Ros, you don't have to check computers one by one. Sounds useful? download the file at <a href="http://www.mathworks.com/matlabcentral/fileexchange/16649" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/16649</a>, don't forget to change the email address and password at the beginning of the file.<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/sms/" rel="tag">sms</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/send-SMS-in-Matlab/">Send SMS in Matlab</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/debugging-your-thinking/</link>
<title><![CDATA[Debugging Your Thinking]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 24 Jun 2010 09:24:54 +0000</pubDate> 
<guid>http://www.mathfinance.cn/debugging-your-thinking/</guid> 
<description>
<![CDATA[<div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">Writing program code is a good way of debugging your thinking - Bill Venables</div></div><br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/debug.jpg" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/debug.jpg" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="280" height="190"/></a><br/>Believe it or not, on average programmers spend 70% of their working time in debugging (I don't know where this number is from but I do believe so). A good debug tool, command or even habit will definitely improve your work efficiency, shorten working hour, and enjoy more the world cup. When it comes to Matlab and R, I have to say the debugging in Matlab is straightforward but is more comprehensive in R. Here is an introductory video demonstrating how to debug and understand Matlab codes:<br/><embed src="http://blogs.mathworks.com/images/pick//FlashVideos/FlowPlayer.swf?config=%7BautoPlay%3Afalse%2CmenuItems%3A%5Bfalse%2Cfalse%2Cfalse%2Cfalse%2Cfalse%2Ctrue%5D%2CautoBuffering%3Afalse%2CshowFullScreenButton%3Afalse%2CinitialScale%3A%27fit%27%2Cloop%3Afalse%2CsplashImageFile%3A%2755%20Basics%20Parsing%20code%2Ejpg%27%2CbaseURL%3A%27http%3A%2F%2Fblogs%2Emathworks%2Ecom%2Fimages%2Fpick%2FFlashVideos%2F%27%2CplayList%3A%5B%7Burl%3A%2755%20Basics%20Parsing%20code%2Eflv%27%2CsuggestedClipsInfoUrl%3A%2755%20see%20also%2Etxt%27%7D%5D%2Cembedded%3Atrue%7D" width="500" height="400" scale="noscale" bgcolor="111111" type="application/x-shockwave-flash" allowScriptAccess="always" allowNetworking="all" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed><br/><br/>Also a very good PDF document for debugging in R with detailed examples at <a href="http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf" target="_blank" rel="nofollow">http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf</a>. Enjoy.<br/>Tags - <a href="http://www.mathfinance.cn/tags/debug/" rel="tag">debug</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/debugging-your-thinking/">Debugging Your Thinking</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-file-style/</link>
<title><![CDATA[Matlab File Style]]></title> 
<author>bo &lt;tigerguob@hotmail.com&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 31 May 2010 18:29:19 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-file-style/</guid> 
<description>
<![CDATA[Programming style, a set of rules or guidelines used when writing the source code for a computer program, is important for a programmer, it not only allows the reviewers to know the date and author of the file, but also helps the programmer himself to track the file version and improve work efficiency. Nevertheless, repetitive comments, especially for the header part are boring. Uncomment is even more boring, read <a href="http://www.mathfinance.cn/matlab-comment-stripping/" target="_blank">Matlab comment stripping</a> for a lazy way for that.<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/programmingformat.jpg" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/programmingformat.jpg" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="411" height="334"/></a><br/><br/>NEWFCN is a good function I always use when creating new files, basically it creates a M-File having the entered filename and a specific structure which helps for creating the main function structure. The actual working MATLAB Version will be also captured. For example, running <strong>newfcn('testnewfcn')</strong> generates a file named testnewfcn.m at a pre-defined style, the new file looks like<br/><div class="code">function testnewfcn()<br/>% TESTNEWFCN ... <br/>%&nbsp;&nbsp;<br/>%&nbsp;&nbsp; ... <br/><br/>%% AUTHOR&nbsp;&nbsp;&nbsp;&nbsp;: aBiao @ mathfinance.cn <br/>%% $DATE&nbsp;&nbsp;&nbsp;&nbsp; : 28-May-2010 18:55:27 $ <br/>%% $Revision : 1.00 $ <br/>%% DEVELOPED : 7.1.0.246 (R14) Service Pack 3 <br/>%% FILENAME&nbsp;&nbsp;: testnewfcn.m <br/><br/>disp(&#039; !!!&nbsp;&nbsp;You must enter code into this file &lt; testnewfcn.m &gt; !!!&#039;) <br/>% ===== EOF ====== &#91;testnewfcn.m&#93; ======&nbsp;&nbsp;<br/></div><br/><br/>Did I mention you can customize the exact style by modifying newfcn.m to the appearance you like? just that simple!<br/><br/>Download at <a href="http://www.mathworks.com/matlabcentral/fileexchange/6408" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/6408</a>&nbsp;&nbsp; <br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-file-style/">Matlab File Style</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/finmetrics/</link>
<title><![CDATA[FinMetrics]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 28 May 2010 11:21:44 +0000</pubDate> 
<guid>http://www.mathfinance.cn/finmetrics/</guid> 
<description>
<![CDATA[I came across a toolbox - FinMetrics this morning, it sounds good from the introduction of help document, plus highly relevant to our topic <a href="http://www.mathfinance.cn" target="_blank">quantitative finance</a>, so I am eager to share it here. However, I am unable to get access to Matlab and check it in detail at the moment, please help me test and leave a comment about your thoughts then. <br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/Matlabfinance.gif" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/Matlabfinance.gif" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><br/><div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">FinMetrics is MATLAB based, open source quantitative portfolio management environment. Built on concepts of bottom-up approach to application design, it allows users to define most basic, low level building blocks, e.g. assets and transactions, to be further pieced together in a higher level objects, e.g. positions or portfolios. Data analysis and statistics function, implemented within the environment and native to MATLAB, enable users to conduct scenario analysis, stress testing, performance measurement and attribution, risk measurement and attribution, design hedge strategies, etc. Open architecture of the environment allows users to work with objects of any level, depending on their requirements and expertise. The object structure and data types are specifically designed to make integration with MATLAB and native FinMetrics functions as easy as possible. FinMetrics user interface application and MATLAB scripting may be utilized to facilitate or automate complex and repetitive tasks, as well as extend functionality of the environment.</div></div><br/><br/>Download it at <a href="http://www.mathworks.com/matlabcentral/fileexchange/27778-finmetrics" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/27778-finmetrics</a> if interested.<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/finmetrics/">FinMetrics</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/how-to-generate-report-automatically-from-matlab/</link>
<title><![CDATA[How to Generate Report Automatically From Matlab]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 24 May 2010 15:39:25 +0000</pubDate> 
<guid>http://www.mathfinance.cn/how-to-generate-report-automatically-from-matlab/</guid> 
<description>
<![CDATA[Often we have to generate reports to our boss, colleagues, and clients, etc. Generally those reports include Matlab source codes, maths equations, and possibly graphs. How do you generate your reports? writing down your equations in Word, running your matlab codes, copying and pasting the results? <br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabcell.jpg" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabcell.jpg" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><br/>It is all right to do like that, but the whole process becomes extremely simple with the cell mode in Matlab, it generates report automatically for us, any change you make regarding description, codes and results will be updated by clicking a simple button: <strong>Publish to HTML</strong>. <br/><br/>The following steps outline the procedure,<br/><div class="code">First, opening an editor in Matlab by choosing File -&gt; New -&gt; M-file;<br/>Second, selecting cell and enable cell mode in the editor;<br/>Third, inserting cell divider under cell window, it allows you to type a name for each section, similar with the title for chapters in Word;<br/>Fourth, depending on your reports, inserting Text Markup, where you are able to insert description text, bold text, etc. most importantly, it supports TeX equations;<br/>Finally, clicking &quot;Publish to HTML&quot;, a nice-looking report is generated, and if necessary, changing the codes and re-running to update the report.</div><br/><br/>For a simple demonstration, I write the files as follows.<br/><div class="code">%% Cell mode publish demonstration<br/>% abiao @ mathfinance.cn<br/><br/>%% Using Black Scholes formula as an example<br/>% The value of a call and put options in terms of the Black–Scholes parameters<br/>% is:<br/>% <br/>% $$C(S,t) = SN(d_1) - Ke^&#123;-r(T - t)&#125;N(d_2) &#92;,$$<br/>% <br/>% $$P(S,t) = Ke^&#123;-r(T-t)&#125; - S + (SN(d_1) - Ke^&#123;-r(T - t)&#125;N(d_2)) = Ke^&#123;-r(T-t)&#125; - S + C(S,t)$$<br/>% <br/>% $$d_1 = &#92;frac&#123;&#92;ln(&#92;frac&#123;S&#125;&#123;K&#125;) + (r + &#92;frac&#123;&#92;sigma^2&#125;&#123;2&#125;)(T - t)&#125;&#123;&#92;sigma&#92;sqrt&#123;T - t&#125;&#125;$$<br/>%<br/>% $$d_2 = d_1 - &#92;sigma&#92;sqrt&#123;T - t&#125;$$<br/><br/>%% Sample code, for simplicity, I use the embedded command<br/>&#91;call, put&#93; = blsprice(10,9,0.02,2,0.3);<br/>fprintf(&#039;Call option value is %g. &#92;n&#039;,call)<br/>fprintf(&#039;Put option value is %g. &#92;n&#039;,put)<br/>call1 = &#91;&#93;;<br/>put1 = &#91;&#93;;<br/>for i = 1:10<br/>&nbsp;&nbsp;&nbsp;&nbsp;call1(i) = blsprice(5+i,9,0.02,2,0.3);<br/>end<br/><br/>%% Sample plot for demonstration only<br/>plot(5+(1:10), call1)<br/></div><br/><br/>The final report is shown at <a href="http://www.mathfinance.cn/attachment/CellPublishDemo.html" target="_blank" rel="nofollow">http://www.mathfinance.cn/attachment/CellPublishDemo.html</a>, looks fantastic.<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/how-to-generate-report-automatically-from-matlab/">How to Generate Report Automatically From Matlab</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-comment-stripping/</link>
<title><![CDATA[Matlab Comment Stripping]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Sat, 22 May 2010 10:49:58 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-comment-stripping/</guid> 
<description>
<![CDATA[I have been doing an internship in London since last week and haven't got enough time to write new posts, sorry for that. So I plan to write a few posts to summarize the old Matlab functions I personally like a lot.&nbsp;&nbsp;The one for today is Matlab comment stripping.<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabcommentstripping.jpg" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabcommentstripping.jpg" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><br/>Needless to say, comment is crucial for programming, it helps ourselves to debug our thoughts and other colleagues to understand the codes efficiently, which is especially indispensable as each programmer has his own coding style. However, under certain circumstances <strong>we may have to remove those comments</strong>, for instance, for the sake of confidential, etc. How do you do that then? delete the comments line by line? it is OK for a small file, but generally we may end up with a file with dozens, if not hundreds, lines of&nbsp;&nbsp;comments, what's worse is those comments intersect and we have to be carefully to find them out. <br/><br/><strong>Here is a clever way, MATLAB Comment Stripping Toolbox</strong> (it indeed has only 3 short files if you are afraid by "Toolbox" ). Basically it is a small collection of utilities for stripping MATLAB comments from MATLAB code. The code may be given in strings, cell arrays of strings, or read from a file or file identifier. There is full support for stripping comments from multi-line strings, that is strings with embedded newlines, which typically appear when an entire file is read in one go. For example, I wrote a simple test.m file and prefer to remove the comments and rename it as test-client.m:<br/><div class="code">% test the comment strip command using mlstripcommentsfile(infile, outfile)<br/>% by abiao @ mathfinance.cn<br/>a = rnorm(10,1); % check if you can remove me<br/>% one more line<br/>b = rnorm(5,5);<br/>c = rnorm(3,3)...<br/>&nbsp;&nbsp;&nbsp;&nbsp;+ rnorm(3,3); %now i am here<br/>% test finished</div><br/><br/>after running the command mlstripcommentsfile('test.m', 'test-client.m'), I got the file test-client.m to send to others<br/><div class="code"><br/><br/>a = rnorm(10,1);<br/><br/>b = rnorm(5,5);<br/>c = rnorm(3,3)...<br/>&nbsp;&nbsp;&nbsp;&nbsp;+ rnorm(3,3);<br/><br/></div><br/><br/>Nice, isn't it? you can download the toolbox at <a href="http://www.mathworks.com/matlabcentral/fileexchange/4645" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/4645</a>.<br/>PS: the original codes use old Matlab version so you will get the warning "Warning: The 'tokenize' option for regexprep is now the default behavior." You may choose to modify the codes by deleting 'tokenize'.<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-comment-stripping/">Matlab Comment Stripping</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/black-litterman-model-II/</link>
<title><![CDATA[Black Litterman Model (II)]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 11 May 2010 09:07:05 +0000</pubDate> 
<guid>http://www.mathfinance.cn/black-litterman-model-II/</guid> 
<description>
<![CDATA[This is the second part of Black Litterman Model, check the first part at <a href="http://www.mathfinance.cn/black-litterman-model-I/" target="_blank">Black Litterman Model (I)</a>.<br/><br/>I skip the technical section, which can be found in the original paper Beyond Black-Litterman in Practice: <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=872577" target="_blank" rel="nofollow">A Five-Step Recipe to Input Views on Non-Normal Markets</a>, and the Matlab codes can be downloaded at <a href="http://www.mathworks.com/matlabcentral/fileexchange/9061" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/9061</a>, in the Extra->COP folder. Suppose we would like to invest in the US treasury market at a weekly investment horizon, and we are interested into the following six key interest rates: 6 month, 2 year, 5 year, 10 year, 20 year and 30 year. For illustration, we use Monte Carlo simulation to generate 100,000 scenarios based on a t Copula with skew t marginal distribution, the sample mean, standard deviation, skewness and kurtosis of the six key rates are shown in table 1.<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/blacklitterman.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/blacklitterman.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>(table 1)<br/>We can easily see from the table 1 that all of the key rates, in particular the short period rates, are non-normally distributed as the kurtosis is significantly larger than 3, which corresponds to normal distribution. <br/><br/><strong>Case 1: </strong>Based on the simulated data, we consider a practitioner who has a 10 bp steepening view on the 2-20 spread and a 5 bp bullish view on the 2-5-10 butterfly, Further, we assume that those views are uniform distributed, and the confidence level is 25% in both views. The results are:<br/><a href="http://www.mathfinance.cn/attachment.php?fid=102" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=102" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>Compared with table 1, we notice the means of 2y and 10y are decreased significantly, and the means of 5y and 20y are increased, which are consistent with our assumed views, since we are bearish on 2y and 10y, and bullish on 5y and 20y. <br/><br/><strong>Case 2: </strong>Contrary to case 1, we express a 10 bp bullish view on the 2-20 spread and a 5 bp bearish view on the 2-5-10 butterfly, other things being equal. We expect that the means of 2y, 5y, 10y and 20y change another way around.<br/><a href="http://www.mathfinance.cn/attachment.php?fid=103" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=103" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>as expected, the means of 2y and 10y are increased significantly, the means of 5y and 20y are increased, and the means of 6m and 30y are again the same as those of prior market. <br/><br/><strong>Case 3: </strong>The views are the same as for case 1, but we increase the confidence for both view from 25% to 75%. We expect the distribution of posterior market alters more significantly.<br/><a href="http://www.mathfinance.cn/attachment.php?fid=104" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=104" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>identical with what we expected, when compared with the results of case 1, the means of 2y and 10y are decreased more significantly, and the means of 5y and 20y are increased more pronounced. For all views, the even moments are only marginally affected. Our robust analysis demonstrates the strong consistence of the COP approach.<br/><br/>Based on the posterior market values we are able to do return mapping and portfolio optimization. <br/><br/>These two posts are a short summary of the original paper and Matlab implementation, please read the source for detail.<br/>Tags - <a href="http://www.mathfinance.cn/tags/black-litterman/" rel="tag">black-litterman</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/black-litterman-model-II/">Black Litterman Model (II)</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/black-litterman-model-I/</link>
<title><![CDATA[Black Litterman Model (I)]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 10 May 2010 15:57:19 +0000</pubDate> 
<guid>http://www.mathfinance.cn/black-litterman-model-I/</guid> 
<description>
<![CDATA[Black-Litterman model is widely used for asset allocation, however, most of its applications are based on the assumption of normally distributed markets and views. In this paper <em><a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=872577" target="_blank" rel="nofollow">Beyond Black-Litterman in Practice: A Five-Step Recipe to Input Views on Non-Normal Markets</a></em>, the author Attilio Meucci extent the Black-Litterman model to allow non-normal distribution assumption, specifically, skew t distribution is used for markets and uniform distribution is for investors views as examples. The author also present general steps to implement the approach in practice. As a fan of this model, I plan to write two posts on the paper, the pros and cons of Black litterman will be discussed, and a robust analysis will be shown to demonstrate its consistence.<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/blacklitterman1.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/blacklitterman1.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><a href="http://www.mathfinance.cn/markowitz-efficient-frontier/" target="_blank">Markowitz mean-variance model</a> is the foundation of modern portfolio theory, it tries to maximize return and minimize risk by carefully choosing different assets. Although Markowitz model is widely used in practice in the financial industry, it has at least the following shortcomings. First, in principle the Markowitz model offers a solution once the expected returns and covariance of the assets are known. Although the covariance of a few assets can be adequately estimated, it is difficult to come up with reasonable estimates of expected returns. Initial estimates often lead to extreme portfolio solutions and have to be adjusted many times before they can be considered acceptable by the decision makers. Second, Markowitz model assumes the future distribution of assets returns will be exactly the same as that of historical returns, therefore it does not allow an investor to have views on the direction of assets growth.&nbsp;&nbsp;<br/><br/>Black-Litterman model bypasses these problems by not requiring the user to input estimates of expected return; instead it assumes that the initial expected returns are whatever is required so that the equilibrium asset allocation is equal to what we observe in the markets. The user is only required to state how his assumptions about expected returns differ from the market's and to state his degree of confidence in the alternative assumptions. From this, the Black-Litterman model computes the desired mean-variance efficient asset allocation. It is right because of this character that makes Black-Litterman model be popular both in industry and academia since it was initially developed in 1990.<br/><br/>However, the original Black-Litterman model helps portfolio managers to compute the distribution of the posterior market that incorporates their subjective views with respect to the prior distribution. All these assumptions are being made considering the entire scenario is normally distributed. In fact, it is frequently observed that returns in equity and other markets are not normally distributed. At the same time, you would expect a practitioner to input his views in a less informative manner. For instance, instead of a view like ‘I am 90% sure that stock A will have a 2% expected return’, he may have a more accurate view such as ‘I am 90% sure that the return of stock A will stay between -1% and 1% with equal chance’, or for an Asian option Trader, his views may be a set of prices at several specific monitoring times, when the option is supposed to be exercised.<br/> <br/>Meucci (2006) solves the above-mentioned issues of the original Black-Litterman model by developing an approach called Copula-Opinion Pooling (COP), the author relaxes the normal distribution assumption and in principle allows any distribution. However, the proposed implementation in the paper has a distinct distribution under certain assumptions. Indeed, the market has been assumed to be skew-t distributed, this strong assumption makes the application of the approach less evident, although the implementation is pretty straightforward for any distribution by Monte Carlo simulation, because Monte Carlo simulation can be applied for almost any distribution and is suitable for any dimension (at least in theory), COP approach can handle a portfolio with any number of risk factors.<br/><br/>The second part will be about the Matlab implementation and results analysis.<br/>Tags - <a href="http://www.mathfinance.cn/tags/black-litterman/" rel="tag">black-litterman</a> , <a href="http://www.mathfinance.cn/tags/allocation/" rel="tag">allocation</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/black-litterman-model-I/">Black Litterman Model (I)</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/dealing-with-excel-date-in-matlab/</link>
<title><![CDATA[Dealing with Excel Date in Matlab]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 05 May 2010 10:21:06 +0000</pubDate> 
<guid>http://www.mathfinance.cn/dealing-with-excel-date-in-matlab/</guid> 
<description>
<![CDATA[I was drived crazy yesterday by dealing with the date in Matlab. I have to download data from different sources, some from datastream, and the others from <a href="http://wrds.wharton.upenn.edu/" target="_blank" rel="nofollow">Wharton Research Data Services</a>, unfortunately, the date is in different format, either in a double format as 20081125, or in a cell format as '25/11/2008' (or something similar) after I import the data with xlsread() command in Matlab. <br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabexcel.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/matlabexcel.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><br/>those different formats really bring a problem, as I need to match the dates and compare the prices, it is easy to convert a cell format date to what matlab recognizes using cell2mat() and then datenum(), for instance, matlab returns a number 733737 for '25/11/2008', however, how can I compare that with 20081125 then?<br/><br/>what I am thinking is:<br/><strong>first</strong>, convert the cell format to string using cell2mat(), it becomes a string 25/11/2008;<br/><strong>second</strong>, reformat the string using datestr(,26), it becomes a string 2008/11/25;<br/><strong>third</strong>, remove '/' by using find(b~='/'), it becomes a string 20081125;<br/><strong>finally</strong>, convert the string to number using str2num(), it is eventually a double number I need 20081125, then I am able to use and match the date from different sources.<br/><br/>It sounds lengthy, do you have a better idea? please share with us by leaving a comment, cheers.<br/><strong><br/>Stanley suggests to use the following code: datenum(datevec(num2str(dates),'yyyymmdd')), here dates is double number, perfect, it is much better than my method as it allows us not only for date comparison but also for calculation, what's more, it is more efficient. many thanks, stanley.</strong><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/excel/" rel="tag">excel</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/dealing-with-excel-date-in-matlab/">Dealing with Excel Date in Matlab</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/kalman-filter-finance-revisited/</link>
<title><![CDATA[Kalman Filter Finance Revisited]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 28 Apr 2010 22:21:16 +0000</pubDate> 
<guid>http://www.mathfinance.cn/kalman-filter-finance-revisited/</guid> 
<description>
<![CDATA[Inspired by @MichaelRW at Twitter, I decide to continue the topic on Kalman Filter following posts <a href="http://www.mathfinance.cn/kalman-filter-example/" target="_blank">Kalman Filter Example</a> and <a href="http://www.mathfinance.cn/kalman-filter-finance/" target="_blank">Kalman Filter Finance</a>. <br/><br/>Specifically, Kalman Filter is applied to estimate the parameters of a <a href="http://www.mathfinance.cn/Cox_Ingersoll_Ross/" target="_blank">Cox Ingersoll Ross (CIR)</a> one factor interest rate model, (Vasicek model is simplier than CIR, so the latter is chosen as an example), it is a widely used mean-reverting process with SDE<br/><a href="http://www.mathfinance.cn/attachment.php?fid=89" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=89" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>A three-factor CIR model has a measurement equation<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/measurementequation.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/measurementequation.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/>and a transition equation<br/><a href="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/transitionequation.png" target="_blank"><img src="http://i795.photobucket.com/albums/yy232/tigergb/mathfinance/transitionequation.png" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/>source from the paper "affine term structure models: theory and implementation" downloaded at <a href="http://www.bankofcanada.ca/en/res/wp/2001/wp01-15a.pdf" target="_blank"rel="nofollow">www.bankofcanada.ca/en/res/wp/2001/wp01-15a.pdf</a><br/><br/><iframe align="right" src="http://rcm.amazon.com/e/cm?t=quanfinacodei-20&o=1&p=8&l=as1&asins=0470173661&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>I skip the derivation part and recommend the following two papers: "estimating and testing exponential-affine term structure models by kalman filter " and "affine term structure models: theory and implementation" to understand the transition and measurement equations. Below are the sample Matlab implementation:<br/><div class="code">function &#91;para, sumll&#93; = TreasuryYieldKF()<br/>% author: biao from www.mathfinance.cn<br/><br/>%%CIR parameter estimation using Kalman Filter for given treasury bonds yields<br/>% check paper &quot;&quot;estimating and testing exponential-affine term structure<br/>% models by kalman filter &quot; and &quot;affine term structure models: theory and<br/>% implementation&quot; for detail<br/>% S(t+1) = mu + F S(t) + noise(Q)<br/>% Y(t) = A + H S(t) + noise(R)<br/><br/>% read data Y<br/>Y = xlsread(&#039;ir.xls&#039;);<br/>&#91;nrow, ncol&#93; = size(Y);<br/>tau = &#91;1/4 1/2 1 5&#93;; % stand for 3M, 6M, 1Y, 5Y yield<br/><br/>para0 = &#91;0.05, 0.1, 0.1, -0.1, 0.01*rand(1,ncol).*ones(1,ncol)&#93;;<br/>&#91;x, fval&#93; = fmincon(@loglik, para0,&#91;&#93;,&#91;&#93;,&#91;&#93;,&#91;&#93;,&#91;0.0001,0.0001,0.0001, -1, 0.00001*ones(1,ncol)&#93;,&#91;ones(1,length(para0))&#93;,&#91;&#93;,&#91;&#93;,Y, tau, nrow, ncol);<br/>para = x;<br/>sumll = fval;<br/>end<br/></div><br/>flip over to next page...<br/><br/><div class="code">function sumll = loglik(para,Y, tau, nrow, ncol) %calculate log likelihood<br/>% initialize the parameter for CIR model<br/>theta = para(1); kappa = para(2); sigma = para(3); lambda = para(4);<br/>%volatility of measurement error<br/>sigmai = para(5:end);<br/>R = eye(ncol);<br/>for i = 1:ncol<br/>&nbsp;&nbsp;&nbsp;&nbsp;R(i,i) = sigmai(i)^2;<br/>end<br/>dt = 1/12; %monthly data<br/>initx = theta;<br/>initV = sigma^2*theta/(2*kappa);<br/><br/>% parameter setting for transition equation<br/>mu = theta*(1-exp(-kappa*dt));<br/>F = exp(-kappa*dt);<br/><br/>% parameter setting for measurement equation<br/>A = zeros(1, ncol);<br/>H = A;<br/>for i = 1:ncol<br/>&nbsp;&nbsp;&nbsp;&nbsp;AffineGamma = sqrt((kappa+lambda)^2+2*sigma^2);<br/>&nbsp;&nbsp;&nbsp;&nbsp;AffineBeta = 2*(exp(AffineGamma*tau(i))-1)/((AffineGamma+kappa+lambda)*(exp(AffineGamma*tau(i))-1)+2*AffineGamma);<br/>&nbsp;&nbsp;&nbsp;&nbsp;AffineAlpha = 2*kappa*theta/(sigma^2)*log(2*AffineGamma*exp((AffineGamma+kappa+lambda)*tau(i)/2)/((AffineGamma+kappa+lambda)*...<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(exp(AffineGamma*tau(i))-1)+2*AffineGamma));<br/>&nbsp;&nbsp;&nbsp;&nbsp;A(i) = -AffineAlpha/tau(i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;H(i) = AffineBeta/tau(i);<br/>end<br/><br/>%now recursive steps<br/>AdjS = initx;<br/>VarS = initV;<br/>ll = zeros(nrow,1); %log-likelihood<br/>for i = 1:nrow<br/>&nbsp;&nbsp;&nbsp;&nbsp;PredS = mu+F*AdjS; %predict values for S and Y<br/>&nbsp;&nbsp;&nbsp;&nbsp;Q = theta*sigma*sigma*(1-exp(-kappa*dt))^2/(2*kappa)+sigma*sigma/kappa*(exp(-kappa*dt)-exp(-2*kappa*dt))*AdjS;<br/>&nbsp;&nbsp;&nbsp;&nbsp;VarS = F*VarS*F&#039;+Q;<br/>&nbsp;&nbsp;&nbsp;&nbsp;PredY = A+H*PredS;<br/>&nbsp;&nbsp;&nbsp;&nbsp;PredError = Y(i,:)-PredY;<br/>&nbsp;&nbsp;&nbsp;&nbsp;VarY = H&#039;*VarS*H+R;<br/>&nbsp;&nbsp;&nbsp;&nbsp;InvVarY = inv(VarY);<br/>&nbsp;&nbsp;&nbsp;&nbsp;DetY = det(VarY);<br/>&nbsp;&nbsp;&nbsp;&nbsp;%updating<br/>&nbsp;&nbsp;&nbsp;&nbsp;KalmanGain = VarS*H*InvVarY;<br/>&nbsp;&nbsp;&nbsp;&nbsp;AdjS = PredS+KalmanGain*PredError&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;VarS = VarS*(1-KalmanGain*H&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;ll(i) = -(ncol/2)*log(2*pi)-0.5*log(DetY)-0.5*PredError*InvVarY*PredError&#039;;<br/>end<br/>sumll = -sum(ll);<br/>end</div><br/><br/>I also attach the ir.xls file to test the codes, you should get the parameters values as:<br/>theta: 0.0613<br/>kappa: 0.2249<br/>sigma: 0.0700<br/>lambda: -0.1110<br/><a href="attachment.php?fid=93">Click to download</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/filter/" rel="tag">filter</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/kalman-filter-finance-revisited/">Kalman Filter Finance Revisited</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/binomial-tree-option-pricing-with-discrete-dividends/</link>
<title><![CDATA[Binomial Tree Option Pricing with Discrete Dividends]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 18 Mar 2010 21:26:22 +0000</pubDate> 
<guid>http://www.mathfinance.cn/binomial-tree-option-pricing-with-discrete-dividends/</guid> 
<description>
<![CDATA[How to value a stock option with discrete dividend was briefly introduced at <a href="http://www.mathfinance.cn/valuation-of-stock-option-with-discrete-dividend/" target="_blank">http://www.mathfinance.cn/valuation-of-stock-option-with-discrete-dividend/</a>, where the main goal is to compare the performance of different methods, namely, Escrowed dividend model, Chriss volatility adjustment model, Haug & Haug volatility adjustment model, Bos volatility adjustment model, and Haug, Haug and Lewis method. I didn't include lattice method for comparison because non-recombining binomial tree is computer intensive, especially when the number of dividends is large. <br/><br/>In the book <em>Options, futures and other derivatives</em> by John Hull, how to deal with discrete dividend with a <a href="http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/" target="_blank">binomial tree</a> is explained in detail, see page 402, fifth version, where future discrete dividend is divided into two types:<br/>1, known dividend yield. For instance, there will be a 3% dividend 3 months later (3% of the stock price), it is straightforward to handle it as the binomial tree is recombined when the nodes are multiplied by a percentage, so basically what we need to do is to construct a tree like usual before ex-dividend date, and then shift all the left tree nodes down by (1-dividend yield), that's it, the number of nodes are the same as for non-dividend binomial tree;<br/><a href="http://www.mathfinance.cn/attachment.php?fid=76" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=76" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/>(source from <em>Options, futures and other derivatives</em>)<br/><br/>2, known dollar dividend. For instance, there will be a 2.5 dollar dividend 3 months later, so before ex-dividend date the binomial tree is constructed as usual but exactly at the date after ex-dividend, the whole nodes are shifted down by 2.5 dollar, and then a new binomial tree is constructed, because the nodes are shifted by an absolute amount number, the new binomial tree is not recombined any more, which means much more nodes than the non-dividend case. Specifically, as pointed by Hull, when i = k+m, there are m(k+2) rather than k+m+1 nodes. The issue becomes more challenging when we increase the number of dividends. Fortunately, there is a simpler way to get around of this difficulty by dividing the stock price into two components: an uncertain part and a part that is the present value of all future dividends during the life of the option. Please check the book for detail <a href="http://www.amazon.com/gp/product/B002E5C87M?ie=UTF8&tag=quanfinacodei-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=B002E5C87M">Options, Futures, and Other Derivatives, 7th&nbsp;&nbsp;Economy Edition with CD</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=as2&o=1&a=B002E5C87M" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.<br/><a href="http://www.mathfinance.cn/attachment.php?fid=77" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=77" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/>(source from <em>Options, futures and other derivatives</em>)<br/>Should you are interested into a sample implementation in Matlab of Binomial Tree Option Pricing with Discrete Dividends, take a look at the file <a href="http://www.ualberta.ca/dept/aict/bluejay/usr/local/matlab-6.5/toolbox/finance/finance/binprice.m" target="_blank" rel="nofollow">http://www.ualberta.ca/dept/aict/bluejay/usr/local/matlab-6.5/toolbox/finance/finance/binprice.m</a>.<br/>Tags - <a href="http://www.mathfinance.cn/tags/dividend/" rel="tag">dividend</a> , <a href="http://www.mathfinance.cn/tags/option/" rel="tag">option</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/binomial-tree-option-pricing-with-discrete-dividends/">Binomial Tree Option Pricing with Discrete Dividends</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/calibrating-stochastic-volatility-models-with-heuristic-techniques/</link>
<title><![CDATA[Calibrating Stochastic Volatility Models with Heuristic Techniques]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 09 Mar 2010 10:45:22 +0000</pubDate> 
<guid>http://www.mathfinance.cn/calibrating-stochastic-volatility-models-with-heuristic-techniques/</guid> 
<description>
<![CDATA[Stochastic volatility models, specifically, <a href="http://www.mathfinance.cn/heston-pricing-calibration/" target="_blank">Heston model</a>, <a href="http://www.mathfinance.cn/sabr-stochastic-volatility/" target="_blank">SABR model</a>, are introduced before and become the widely used among academia and industry. However, the calibration process is difficult because generally the pricing requires numerical integration, and calibration requires to find five and eight parameters instead of only one for <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black Scholes model</a>.<br/><br/>Found a paper <em>Calibrating Option Pricing Models with Heuristics</em>, where the author look into the calibration of Heston (1993) and Bates (1996) models. Finding parameters that make the models consistent with market prices means solving a non-convex optimisation problem. Optimisation heuristics is suggested for this issue, more specifically they show that Differential Evolution and Particle Swarm Optimisation are both able to give good solutions to the problem. <br/><br/>Take a look if you are interested, in the Appendix the R and Matlab codes are given for a better understanding. <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1566975" target="_blank" rel="nofollow">http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1566975</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/stochastic/" rel="tag">stochastic</a> , <a href="http://www.mathfinance.cn/tags/heuristic/" rel="tag">heuristic</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/calibrating-stochastic-volatility-models-with-heuristic-techniques/">Calibrating Stochastic Volatility Models with Heuristic Techniques</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/sudoku-spreadsheet-example-matlab-excel-link/</link>
<title><![CDATA[Sudoku Spreadsheet Example of Matlab Excel Link]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Sun, 28 Feb 2010 11:52:22 +0000</pubDate> 
<guid>http://www.mathfinance.cn/sudoku-spreadsheet-example-matlab-excel-link/</guid> 
<description>
<![CDATA[Sudoku is one of my favorite small games I often have fun with, I save one copy at my gphone and play it whenever I want to take a rest. (most of us may have a wrong impression that Sudoku originated in Japan, no, in America.)<br/><br/>I happened to find Cleve Moler solved Sudoku using recursive backtracking method and the speed is fast, the minor error is it doesn't report an error when the initial 9*9 matrix you give violates Sudoku rules (you can test it later, the code starts to run and returns a result even you give repetitive numbers along a same row or column). Since building a GUI in matlab isn't easy, I choose to build a <strong>Sudoku spreadsheet</strong> using Matlab Excel link for an example.<br/><br/>Once you install Excel Link module and turn it on, you will notice the short-cuts on the excel menu bar looking like<br/><a href="http://www.mathfinance.cn/attachment.php?fid=63" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=63" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a>&nbsp;&nbsp;<br/>intuitively, those buttons stand for "start matlab", "send data to matlab", "retrieve data from matlab", and "execute the matlab command", respectively. <br/><br/>For my case, I first download the Sudoku M code at <a href="http://www.mathworks.co.uk/company/newsletters/news_notes/2009/clevescorner.html?s_cid=ACD0210ukTA2&s_v1=8728847_1-BR7DSN" target="_blank" rel="nofollow">http://www.mathworks.co.uk/company/newsletters/news_notes/2009/clevescorner.html?s_cid=ACD0210ukTA2&s_v1=8728847_1-BR7DSN</a>, then open an excel file, write down a 9*9 matrix "X"<br/><a href="http://www.mathfinance.cn/attachment.php?fid=64" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=64" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/>then define a zone to fetch the calculation result, which should also be 9*9<br/><a href="http://www.mathfinance.cn/attachment.php?fid=65" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=65" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a><br/><br/>finally do steps:<br/><- put data to matlab, MLPutmatrix("X",X)<br/><- solve the problem in matlab, MLEvalString("X=sudoku(X)")<br/><- get results from matlab, MLGetMatrix("X","NewX")<br/><br/>result is then retrieved immediately to Sudoku Spreadsheet from matlab<br/><a href="http://www.mathfinance.cn/attachment.php?fid=67" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=67" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500"/></a> <br/><br/>Straightforward to run your Matlab function in excel, isn't it? alternatively you can use Matlab builder for excel.<br/><a href="attachment.php?fid=68">Click to download</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/excel/" rel="tag">excel</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/sudoku-spreadsheet-example-matlab-excel-link/">Sudoku Spreadsheet Example of Matlab Excel Link</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/valuation-of-stock-option-with-discrete-dividend/</link>
<title><![CDATA[Valuation of stock option with discrete dividend]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 03 Feb 2010 14:41:56 +0000</pubDate> 
<guid>http://www.mathfinance.cn/valuation-of-stock-option-with-discrete-dividend/</guid> 
<description>
<![CDATA[When asked how to value a stock option without dividend or with continuous dividend, many people would refer to <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black Scholes formula</a>, but how to price an option with discrete dividend then? certainly Black Scholes model can't be used directly since one of its assumptions is continuous payout. Paper <em>Back to Basics: a new approach to the discrete dividend problem</em> by Haug, Haug and Lewis summarizes the following ways:<br/>1, <strong>Escrowed dividend model</strong>, which is the simplist and the least accurate way as a result. The basic idea of Escrowed dividend model is to adjust the current stock price by deducting the present value of future dividends, and plug in the replaced stock price to Black Scholes formula;<br/>2, <strong>Chriss volatility adjustment model</strong>, besides replacing current stock price, this model adjusts volatility as well because the Escrowed dividend model alone decreases the absolute price standard deviation, hence underestimates an option's value. However, Chriss model yields too high volatility if the dividend is paid out early in the option’s lifetime, which generally overprices call options;<br/>3, <strong>Haug & Haug volatility adjustment model</strong>; which is more sophisticated than Chriss model and takes into account the timing of the dividend, unfortunately, the authors show this method performs particularly poorly for multiple dividends stock option;<br/>4, <strong>Bos volatility adjustment model</strong>, a even more sophiscated model than Haug & Haug, but still, it performs poorly for large dividends or long term options;<br/>5, <strong>Lattice method</strong>, for example, non-recombining binomial tree introduced in the bible book <a href="http://www.amazon.com/gp/product/0136015867?ie=UTF8&tag=quanfinacodei-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0136015867">Options, Futures, and Other Derivatives with Derivagem CD (7th Edition)</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=as2&o=1&a=0136015867" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, we all know it is time-consuming;<br/>6, <strong>Haug, Haug and Lewis method</strong> introduced in the above-mentioned paper, the basic idea is to calculate first the ex-dividend option price by Black Scholes model, then discount back the ex-dividend value under equivalent martingale measure. The authors demonstrate the high accuracy of their model with several examples afterwards.<br/><br/>Below is sample Matlab codes I wrote for comparision, a single dividend is used for simplicity, results similar to the table listed in the paper<br/><br/><div class="code">function callprice = DiscreteDividend(s,k,r,t,vol,d,dt)<br/>%compare different methods for a single discrete dividend adjustments,<br/>%read paper by Haug for detail;<br/>%dt: dividend time<br/>BSprice = blsprice(s,k,r,t,vol,0);<br/>AdjS = s-exp(-r*dt)*d;<br/>Escrowed = blsprice(AdjS,k,r,t,vol,0);<br/>%%%%%%%%%Chriss, 1997%%%%%%%%%%<br/>vol1 = vol*s/(s-d*exp(-r*dt));<br/>Chriss = blsprice(AdjS,k,r,t,vol1,0);<br/>%%%%%%%%%Haug, 1998%%%%%%%%%%<br/>vol2 = sqrt(vol^2*dt+vol1^2*(t-dt)/t);<br/>OldHaug = blsprice(AdjS,k,r,t,vol2,0);<br/>%%%%%%%%Bos et al. (2003)%%%%%%%%%%<br/>lns = log(s);<br/>lnk = log((k+d*exp(-r*dt))*exp(-r*t));<br/>z1 = (lns-lnk)/(vol*sqrt(t))+vol*sqrt(t)/2;<br/>z2 = z1+vol*sqrt(t)/2;<br/>vol3 = sqrt(vol^2+vol*sqrt(pi/(2*t))*(4*exp(z1^2/2-lns)*d*exp(-r*dt)*...<br/>&nbsp;&nbsp;&nbsp;&nbsp;(normcdf(z1)-normcdf(z1-vol*dt/sqrt(t)))+exp(z2^2/2-2*lns)*d^2*...<br/>&nbsp;&nbsp;&nbsp;&nbsp;exp(-r*2*dt)*(normcdf(z2)-normcdf(z2-2*vol*dt/sqrt(t)))));<br/>Bos = blsprice(AdjS,k,r,t,vol3,0);<br/>%%%%%%%%%Haug, 2003%%%%%%%%%%%%%%%<br/>NewHaug = exp(-r*dt)*(quad(@(x)blsprice(x-d,k,r,t-dt,vol,0).*lognpdf(x,lns+(r-0.5*vol^2)*dt,vol*sqrt(dt)), d, k+d)...<br/>&nbsp;&nbsp;&nbsp;&nbsp;+quad(@(x)blsprice(x-d,k,r,t-dt,vol,0).*lognpdf(x,lns+(r-0.5*vol^2)*dt,vol*sqrt(dt)), k+d, 20*s));<br/>callprice = &#91;BSprice, Escrowed, Chriss, OldHaug, Bos, NewHaug&#93;;<br/></div><br/><br/>For example, the results of a $7 dividend after 0.5 year are (DiscreteDividend(100, 100,0.06,1,0.3,7,0.5)): 14.7171&nbsp;&nbsp; 10.6932&nbsp;&nbsp; 11.5001&nbsp;&nbsp; 11.1039&nbsp;&nbsp; 11.0781&nbsp;&nbsp; 11.1062, respectively.<br/><br/>Reading the original paper <em>Back to Basics: a new approach to the discrete dividend problem</em> if interested, <a href="http://www.nccr-finrisk.uzh.ch/media/pdf/ODD.pdf" target="_blank" rel="nofollow">http://www.nccr-finrisk.uzh.ch/media/pdf/ODD.pdf</a>, or the book <a href="http://www.amazon.com/gp/product/0071389970?ie=UTF8&tag=quanfinacodei-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0071389970">The Complete Guide to Option Pricing Formulas</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=as2&o=1&a=0071389970" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> by Haug for more detail.<br/>Tags - <a href="http://www.mathfinance.cn/tags/dividend/" rel="tag">dividend</a> , <a href="http://www.mathfinance.cn/tags/option/" rel="tag">option</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/valuation-of-stock-option-with-discrete-dividend/">Valuation of stock option with discrete dividend</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/vanna-volga-method/</link>
<title><![CDATA[Vanna Volga Method]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 05 Jan 2010 22:11:07 +0000</pubDate> 
<guid>http://www.mathfinance.cn/vanna-volga-method/</guid> 
<description>
<![CDATA[The <strong>vanna volga method</strong> is a popular pricing model for implied volatilities, especially for foreign exchange options, it is an empirical procedure that can be applied to "draw" an implied volatility smile curve from three given quotes (reversal, ATM and butterfly) for a certan time to maturity. Empirical research shows <strong>the vanna volga method</strong> has a comparable pricing performance with some <a href="http://www.mathfinance.cn/tags/stochastic/" target="_blank">stochastic volatility model</a>, for example, Castagna and Mercurio (2007) show the implied volatility curve of vanna volga method outperforms that of Malz (1997), and performs equally well as of <a href="http://www.mathfinance.cn/sabr-stochastic-volatility/" target="_blank">SABR</a> (2002). <br/><br/>By building a self-financing portfolio consisting a unit of option at strike K, -delta1 units of underlying asset, and -xi units of options at strike ki, Castagna and Mercurio (2007) calculate the weight xi for three given quotes with the help of Ito's lemma and then approximate the European option value under <strong>vanna volga method</strong>, as stated in the paper, VV pricing model has several advantages: "it has a clear financial rationale supporting, based on the hedging argument...; it allows for an automatic calibration to the main volatility data...; ... it can be extended to any European-style derivative..."<br/><br/>Below is a simple Matlab code to price a call option based on Castagna and Mercurio (2007):<div class="code">% option price under Vanna volga model for any strike k<br/>% sigma2 is ATM implied vol, k2 is ATM strike<br/>s = 1.205;<br/>t = 94/365;<br/>r = -log(0.9902752)/t;<br/>rf = -log(0.9945049)/t;<br/>sigma1 = 0.0979;<br/>sigma3 = 0.0929;<br/>sigma2 = 0.09375;<br/>k1 = 1.172;<br/>k3 = 1.2504;<br/>k2 = 1.2115;<br/>k = 1.24;<br/>Vega1 = Vega(s,k1,r,t,sigma2,rf);<br/>Vega3 = Vega(s,k3,r,t,sigma2,rf);<br/>Vegak = Vega(s,k,r,t,sigma2,rf);<br/>x1 = Vegak*log(k2/k)*log(k3/k)/(Vega1*log(k2/k1)*log(k3/k1));<br/>x3 = Vegak*log(k/k1)*log(k/k2)/(Vega3*log(k3/k1)*log(k3/k2));<br/>price = blsprice(s,k,r,t,sigma2,rf)+x1*(blsprice(s,k1,r,t,sigma1,rf)...<br/>&nbsp;&nbsp;&nbsp;&nbsp;-blsprice(s,k1,r,t,sigma2,rf))+x3*(blsprice(s,k3,r,t,sigma3,rf)...<br/>&nbsp;&nbsp;&nbsp;&nbsp;-blsprice(s,k3,r,t,sigma2,rf));</div><br/>where Vega is a function to compute vega under <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">black scholes</a> formula<div class="code">function VegaValue = Vega(s,k,r,t,sigma,rf)<br/>d1 = (log(s/k)+(r-rf+0.5*sigma^2)*t)/(sigma*sqrt(t));<br/>VegaValue = s*exp(-rf*t)*sqrt(t)*normpdf(d1,0,1);</div><br/><br/>Implied volatilities curve is therefore easily achieved by inverting VV pricing model. Interested ppl please refer to <a href="http://www.risk.net/risk/technical-paper/1506580/the-vanna-volga-method-implied-volatilities" target="_blank" rel="nofollow">http://www.risk.net/risk/technical-paper/1506580/the-vanna-volga-method-implied-volatilities</a> or an advanced one <a href="http://www.mathfinance.de/wystup/papers/wystup_vannavolga_eqf.pdf" target="_blank" rel="nofollow">www.mathfinance.de/wystup/papers/wystup_vannavolga_eqf.pdf</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/volatility/" rel="tag">volatility</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/vanna-volga-method/">Vanna Volga Method</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/ad-hoc-black-scholes-model-for-option-pricing/</link>
<title><![CDATA[Ad hoc Black Scholes model for Option Pricing]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 09 Dec 2009 22:16:41 +0000</pubDate> 
<guid>http://www.mathfinance.cn/ad-hoc-black-scholes-model-for-option-pricing/</guid> 
<description>
<![CDATA[One shortcoming of <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black Scholes</a> is its constant volatility assumption, lots of extension has been done to improve its out-of-sample performance, to name a few, <a href="http://www.mathfinance.cn/Heston_Stochastic_Volatility/" target="_blank">heston stochastic volatility model</a>, <a href="http://www.mathfinance.cn/sabr-stochastic-volatility/" target="_blank">SABR stochastic volatility model</a> and <a href="http://www.mathfinance.cn/garch-option-pricing/" target="_blank">Garch option pricing</a>. Here is a paper "On Justifications for the ad hoc Black-Scholes Method of Option Pricing" where the author interpolates the implied volatility, substitutes the result into <strong>Black Scholes</strong> formula, which outperforms the original <strong>Black Scholes model</strong>. Straightforward and few more lines to your codes are enough. <br/><br/><div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">Abstract: One of the most widely used option valuation procedures among practitioners is a version of Black-Scholes in which implied volatilities are smoothed across strike prices and maturities. A growing body of empirical evidence suggests that this ad hoc approach performs quite well. It has previously been argued that such a procedure works because it amounts to a sophisticated interpolation tool. We show that this is the case in a formal, asymptotic sense. In addition, we conduct some simulations which allow us to examine the importance of the sample size, the order of the polynomial, and the recalibration frequency in controlled settings. We also apply the ABS approach to daily S&P 100 index options to show that the procedure outperforms the Black-Scholes formula in valuing actual option prices out-of-sample.</div></div><br/><br/>Download the PDF at <a href="http://www.uh.edu/~jberkowi/" target="_blank" rel="nofollow">http://www.uh.edu/~jberkowi/</a> and the matlab files at <a href="http://www.bepress.com/snde/vol14/iss1/art4/" target="_blank" rel="nofollow">http://www.bepress.com/snde/vol14/iss1/art4/</a>.<br/>&nbsp;&nbsp;<br/><br/><br/>Tags - <a href="http://www.mathfinance.cn/tags/black_scholes/" rel="tag">black scholes</a> , <a href="http://www.mathfinance.cn/tags/volatility/" rel="tag">volatility</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/ad-hoc-black-scholes-model-for-option-pricing/">Ad hoc Black Scholes model for Option Pricing</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/zero-coupon-CIR-bond-price/</link>
<title><![CDATA[Zero coupon CIR bond price]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 03 Dec 2009 16:47:15 +0000</pubDate> 
<guid>http://www.mathfinance.cn/zero-coupon-CIR-bond-price/</guid> 
<description>
<![CDATA[A simple Matlab code to calculate a zero-coupon bond price under the <a href="http://www.mathfinance.cn/Cox_Ingersoll_Ross/" target="_blank">Cox-Ingersoll-Ross (CIR)</a> Interest Rate Model, where r0 is the current interest rate, alpha, kappa, sigma are CIR parameters standing for mean reversion speed, long term mean rate, and volatility of interest rate, T is the maturity of bond.<br/><div class="code">h = sqrt(kappa^2 + 2*sigma^2);<br/>A&nbsp;&nbsp;= (2*h*exp((kappa+h)*T/2)/(2*h + (kappa+h)*(exp(T*h)-1)))^((2*kappa*alpha)/sigma^2);<br/>B&nbsp;&nbsp;= 2*(exp(T*h)-1)/(2*h + (kappa+h)*(exp(T*h)-1));<br/>P =&nbsp;&nbsp;A*exp(-B*r0); % bond price at 0</div><br/><br/><a href="http://www.mathfinance.cn/attachment.php?fid=24" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=24" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>Tags - <a href="http://www.mathfinance.cn/tags/cir/" rel="tag">cir</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/zero-coupon-CIR-bond-price/">Zero coupon CIR bond price</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/pricing-parisian-options/</link>
<title><![CDATA[Pricing Parisian Options]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 27 Nov 2009 17:11:21 +0000</pubDate> 
<guid>http://www.mathfinance.cn/pricing-parisian-options/</guid> 
<description>
<![CDATA[A <strong>parisian option</strong> pricer was shared at the post before at <a href="http://www.mathfinance.cn/parisian-option-pricer/" target="_blank">http://www.mathfinance.cn/parisian-option-pricer/</a>, where the authors Haber, Schoenbucher, and Wilmott values <strong>Parisian and Parasian options</strong> via <a href="http://www.mathfinance.cn/implicit-explicit-pde/" target="_blank">explicit finite difference method</a>. (<strong>Parisian option</strong> is a barrier option but becomes activated only after stock prices have spent a certain continuous, pre-decided time, called a window, above or below the barrier.)<br/><br/>Unfortunately, the authors don't release their codes for us to study, I tried to program according to that paper with theta scheme finite difference, where theta =0, 0.5, 1 refer to explicit, Crank-Nicolson, and implicit finite difference, respectively. Below is a runnable <strong>naive</strong> Matlab code, please correct me if you find errors, cheers & have a nice weekend.<br/><div class="code">% set parameter<br/>N = 201; M = 200; s = 10; T = 1;<br/>Tau = 0.1; %barrier window 20 days<br/>sigma = 0.2; r = 0.05; K = 10;<br/>Bar = 12; %barrier<br/>bar = log(Bar);<br/>% time-space grid<br/>R = 3;<br/>h = 2*R/(N+1);<br/>k = T/M;<br/>NoTau = floor(Tau/k);<br/>x = linspace(-R,R,N+2)&#039;;<br/><br/>% compute finite difference matrix A<br/>e = ones(N,1);<br/>alphap = -sigma^2/2/h^2 +(sigma^2/2-r)/2/h;<br/>alpham = -sigma^2/2/h^2 -(sigma^2/2-r)/2/h;<br/>beta = sigma^2/h^2+r;<br/>A = spdiags(&#91;alpham*e, beta*e, alphap*e&#93;, -1:1, N, N);<br/>% compute matrices for the theta scheme<br/>theta = 0.5;<br/>B = speye(N,N) + theta*k*A;<br/>C = speye(N,N) - (1-theta)*k*A;<br/>% compute initial data<br/>u = max(exp(x)-K,0);<br/>u = repmat(u,1,NoTau+1);<br/>inx = find(x&gt;bar,1,&#039;first&#039;);<br/>u(:,1) = 0; %up and out when j=tau<br/>f = zeros(N,1);<br/>% start timestepping<br/>for m = 1:M<br/>&nbsp;&nbsp;&nbsp;&nbsp;lastu = u;<br/>&nbsp;&nbsp;&nbsp;&nbsp;% compute right hand side<br/>&nbsp;&nbsp;&nbsp;&nbsp;for j = 2:NoTau+1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f = C*&#91;lastu(2:inx-2,NoTau+1);lastu(inx-1:end-1,j-1)&#93;; %below using tau=0, above using tau=tau+1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u(:,j) = zeros(N+2,1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;% solve the linear system<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u(2:N+1,j) = B&#92;f;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end<br/>&nbsp;&nbsp;&nbsp;&nbsp;u(inx-1,2:NoTau) = u(inx-1,NoTau+1);%reset value at barrier point for parisian<br/>&nbsp;&nbsp;&nbsp;&nbsp;lastu = u;<br/>end</div><br/>Plots of the <strong>Parisian option</strong> and its delta W.R.T stock prices and barrier Tau.<br/><a href="http://www.mathfinance.cn/attachment.php?fid=22" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=22" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/><a href="http://www.mathfinance.cn/attachment.php?fid=23" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=23" class="insertimage" alt="Open in new window" title="Open in new window" border="0"/></a><br/>Tags - <a href="http://www.mathfinance.cn/tags/parisian/" rel="tag">parisian</a> , <a href="http://www.mathfinance.cn/tags/finite-difference/" rel="tag">finite-difference</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/pricing-parisian-options/">Pricing Parisian Options</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/garch-option-pricing/</link>
<title><![CDATA[Garch option pricing]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Sun, 15 Nov 2009 13:54:52 +0000</pubDate> 
<guid>http://www.mathfinance.cn/garch-option-pricing/</guid> 
<description>
<![CDATA[We all know one assumption of <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black Scholes model</a> is constant volatility during option period, which has been relaxed by several methods including <a href="http://www.mathfinance.cn/Heston_Stochastic_Volatility" target="_blank">Heston stochastic volatility</a>, <a href="http://www.mathfinance.cn/sabr-stochastic-volatility/" target="_blank">SABR stochastic volatility</a>, etc. Here is another way proposed by Jin-Chuan Duan, Geneviève Gauthier, and Jean-Guy Simonato in their paper "An analytical approximation for the <strong>GARCH option pricing</strong> model" published at the Journal of computational finance in 1999, http://www.journalofcomputationalfinance.com/public/showPage.html?page=1112.<br/><div class="quote"><div class="quote-title">Quotation</div><div class="quote-content"><strong>GARCH option pricing</strong> framework has been developed in recent years. However, an efficient method for computing option prices in this framework remains lacking. In this article, a fast analytical approximation is developed for computing <strong>European option prices in the GARCH framework</strong>. The approach, following that of Jarrow and Rudd (1982), uses the Edgeworth expansion of the risk-neutral density function. Analytical expressions for the first four moments of the cumulative asset return over any horizon under the GARCH model are derived in this paper. A numerical analysis shows that these moment formulas are accurate under fairly general conditions. The analytical <strong>GARCH option pricin</strong>g formula based on the Edgeworth expansion is found to work well for short-maturity options. For long-maturity options, the approximate formula is generally satisfactory, except when the volatility dynamic of the GARCH model exhibits an extremely high level of persistence.</div></div><br/><br/>Matlab codes can be downloaded at <a href="http://www.rmi.nus.edu.sg/DuanJC/" target="_blank" rel="nofollow">http://www.rmi.nus.edu.sg/DuanJC/l</a>, several other programming files can be also found at the page, for example, Co-integration option pricing model, <strong>GARCH option pricing</strong> model and its application to volatility smile, Linear and non-linear asymmetric GARCH models, Estimating exponential affine term structure models, and Maximum likelihood estimation method for Merton's deposit insurance pricing model. <br/>Tags - <a href="http://www.mathfinance.cn/tags/garch/" rel="tag">garch</a> , <a href="http://www.mathfinance.cn/tags/volatility/" rel="tag">volatility</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/garch-option-pricing/">Garch option pricing</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/numerical-integration-code/</link>
<title><![CDATA[Numerical Integration Code]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 10 Nov 2009 21:52:52 +0000</pubDate> 
<guid>http://www.mathfinance.cn/numerical-integration-code/</guid> 
<description>
<![CDATA[A followup post of my previous entry <a href="http://www.mathfinance.cn/using-quadrature-method-option-valuation/" target="_blank">Using Quadrature method for option valuation</a>, where I tested the alternative numerical method for option valuation, QUAD. If you read the original paper, you will notice at the end all option valuation problems are to solve an integral equation, therefore a good & proper <strong>numerical integration method</strong> becomes especially crucial.<br/><br/>My example in that post used simply Matlab embedded command "quadl", however, when the option becomes exotic, or the option has multiple observation times (for example, a Bermudan option), quadl can't be applied anymore as we have to match the nodes of these different observation times. (quadl does not allow users to specify how many points and how small interval an integral can have, correct me if i am wrong). Here is a good site on <strong>numerical integration code</strong> I just dug yesterday: Transforming Numerical Methods Education by University of South Florida, which is for undergraduate student at engineering or mathematics and is therefore in plain language, easy to understand. For example, under integration section, it includes <strong>trapezoidal rule</strong>, <strong>simpson's 1/3rd Rule</strong>, <strong>Romberg Integration</strong>, <strong>Gauss-Quadrature Rule</strong>, etc, for each <strong>numerical integration method</strong>, it provides well explained documents, matlab and MATHEMATICA codes, and even Youtube video......<br/><br/>Have fun at <a href="http://numericalmethods.eng.usf.edu/index.html" target="_blank" rel="nofollow">http://numericalmethods.eng.usf.edu/index.html</a>. A minor defect is its gauss quadrature point is up to 10 only, no worry, should you are unhappy with that, another C/C++ code on Gauss quadrature can be found at <a href="http://www.holoborodko.com/pavel/?page_id=679" target="_blank" rel="nofollow">http://www.holoborodko.com/pavel/?page_id=679</a>.<br/><br/><br/>Tags - <a href="http://www.mathfinance.cn/tags/quadrature/" rel="tag">quadrature</a> , <a href="http://www.mathfinance.cn/tags/integral/" rel="tag">integral</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/numerical-integration-code/">Numerical Integration Code</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/using-quadrature-method-option-valuation/</link>
<title><![CDATA[Using Quadrature method for option valuation]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 03 Nov 2009 16:58:14 +0000</pubDate> 
<guid>http://www.mathfinance.cn/using-quadrature-method-option-valuation/</guid> 
<description>
<![CDATA[Reading an interesting paper "<strong>universal option valuation using quadrature methods</strong>", which provides an alternative method to value options. Compared with lattice (<a href="http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/" target="_blank">binomial and trinomial trees</a>), <a href="http://www.mathfinance.cn/tags/finite-difference/" target="_blank">finite difference</a>, and <a href="http://www.mathfinance.cn/tags/monte_carlo/ " target="_blank">Monte Carlo</a> techniques,&nbsp;&nbsp;<strong>quadrature method (QUAD)</strong> possesses exceptional accuracy and speed, while isn't harder to implement. Basically what we need to do is to write down the problem in an integral function and to solve the function with techniques like Simpson's rule or Gauss Quadature, ect.<br/><br/>For s short comparison, a simple QUAD code to price a vanilla European call option is as follows, please refer to the original paper for the meaning of symbols:<br/><div class="code">%using QUAD to calculate a vanila european call<br/>x0 = log(s/k);<br/>kappa = 2*(r-d)/vol^2-1;<br/>dt = t;<br/>ymax = 3;<br/>A = 1/(sqrt(2*vol^2*pi*dt))*exp(-(kappa*x0/2)-(vol^2*kappa^2*dt/8)-r*dt);<br/>q = quadl(@myquad,0,ymax,&#91;&#93;,&#91;&#93;,x0,dt,vol,kappa,k); %Matlab embedded quadrature<br/>callprice = A*q;<br/><br/>function f = myquad(x,x0,dt,vol,kappa,k)<br/>B = exp(-((x0-x).^2./(2*vol^2*dt))+kappa*x/2);<br/>f = B.*max(exp(x)-1,0)*k;</div><br/><br/>Here I arbitrarily set ymax=3, which is enough for this simple example, the result for a European call option with strike price 9, stock price 10, volatility 20%, risk free rate 2%, dividend 1%, time to maturity 2 years is <strong>1.71429100893328</strong>, with 0.005681 seconds elapsed time using my humble laptop, in contrast with the embedded <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black Scholes</a> matlab function value <strong>1.71429100824415</strong>, and 100 time steps binomial tree value <strong>1.71422035929822</strong>. QUAD performs quite good, isn't it?<br/><br/>The exotic option pricing is left for further experiment, have a nice evening. <br/>PS: i was seriously drunken last weekend, my poor stomach.<br/>Tags - <a href="http://www.mathfinance.cn/tags/quadrature/" rel="tag">quadrature</a> , <a href="http://www.mathfinance.cn/tags/integral/" rel="tag">integral</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/using-quadrature-method-option-valuation/">Using Quadrature method for option valuation</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/quantitative-trading-strategies/</link>
<title><![CDATA[Quantitative trading strategies]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 27 Oct 2009 21:54:29 +0000</pubDate> 
<guid>http://www.mathfinance.cn/quantitative-trading-strategies/</guid> 
<description>
<![CDATA[Spent several days reading a book named <strong>Quantitative Trading Strategies: Harnessing the Power of Quantitative Techniques to Create a Winning Trading Program, </strong><a href="http://www.amazon.com/gp/product/0071412395?ie=UTF8&tag=quanfinacodei-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0071412395">Quantitative Trading Strategies: Harnessing the Power of Quantitative Techniques to Create a Winning Trading Program</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=as2&o=1&a=0071412395" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, compared with the book <a href="http://www.amazon.com/gp/product/0470284889?ie=UTF8&tag=quanfinacodei-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0470284889">Quantitative Trading: How to Build Your Own Algorithmic Trading Business</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=as2&o=1&a=0470284889" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> I read & shared at my earlier post <a href="http://www.mathfinance.cn/matlab-trading-code/" target="_blank">Matlab trading code</a>, this one is in more detail and more practical. For me, <strong>Quantitative trading</strong> is a good introductory book showing starters what algo trading is and how to begin and what to prepare in order to be an independent quant trader, while <strong>Quantitative trading strategies</strong> explains what a <strong>good trading strategy</strong> is, how to test a trategy a trader has, what's more, the author is kind enough to disclosure dozens of strategies he created. Whether those trading strategies still work or not is another issue, but at least readers are able to have a rough picture in mind the pros and cons of each strategy, the possible way to modify them for our own use after reading it.<br/><br/><a target="blank" href="http://www.ino.com/info/193/CD4232/&dp=0&l=0&campaignid=9"><img src="http://ino.directtrack.com/42/4232/193/" alt="" border="0" align="right"></img></a>Anyway, it is your turn to compare them.&nbsp;&nbsp;I write M files of several selected <strong>quantitative trading strategies</strong> from the book I have played, be aware although I wrote carefully, i dont gurantee the correct of them, and i didn't optimize the code, either, sorry.<br/><br/><strong>Moving Average</strong>: long when x day moving average crosses above y day moving average, short when x day moving average crosses below y day moving average<div class="code">pos=zeros(size(price,1),1);<br/>&#91;lead,lag&#93;= movavg(price,x,y,&#039;e&#039;);<br/>lead = &#91;zeros(x-1,1); lead&#93;; %to avoid dimension mismatch<br/>lag = &#91;zeros(y-1,1); lag&#93;;<br/>pos(lead&gt;lag)=1;&nbsp;&nbsp; <br/>pos(lag&gt;lead)=-1;<br/></div><br/><br/><strong>Volatility Breakouts</strong>:<div class="code">m = size(price,1);<br/>pos=zeros(m,1);<br/>for i = 2:m<br/>&nbsp;&nbsp;&nbsp;&nbsp;%put here the way to calculate variance C<br/>&nbsp;&nbsp;&nbsp;&nbsp;UpperTrigger = price(i-1)+multiplier*sqrt(C);<br/>&nbsp;&nbsp;&nbsp;&nbsp;LowerTrigger = price(i-1)-multiplier*sqrt(C);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if price(i)&gt;=UpperTrigger pos(i) = 1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;elseif price(i)&lt;=LowerTrigger pos(i) = -1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end<br/>end<br/></div><br/><br/><strong>stochastic indicator</strong>:<div class="code">stosc = stochosc(highp, lowp, closep, kperiod, dperiod); %embedded Matlab function<br/>m = size(highp,1);<br/>pos=zeros(m,1);<br/>inx1 = find(stosc(:,1)&gt;=30);<br/>inx2 = find(stosc(:,1)&gt;=stosc(:,2));<br/>pos(intersect(inx1,inx2)) = 1;<br/>inx1 = find(stosc(:,1)&lt;=80);<br/>inx2 = find(stosc(:,1)&lt;=stosc(:,2));<br/>pos(intersect(inx1,inx2)) = -1;<br/></div><br/><br/><strong>Divergence Index</strong>:<div class="code">%divergence index strategy, m is long momentum period, n is for short<br/>longmom = tsmom(price,m); <br/>shortmom = tsmom(price,n);<br/>mm = size(price,1);<br/>pos=zeros(mm,1);<br/>DI = longmom.*shortmom./var(diff(price));<br/>inx1 = find(DI&lt;-8);<br/>inx2 = find(longmom&lt;0);<br/>inx3 = find(longmom&gt;0);<br/>pos(intersect(inx1,inx2))=-1;<br/>pos(intersect(inx1,inx3))=1;<br/></div><br/><br/><strong>Moving Average Confluence Method</strong>:<div class="code">% p - *price* data<br/>% N - number of points to generate signal<br/>pos=zeros(size(p,1),1);<br/>macs = zeros(size(p,1),20);<br/>for i=1:20<br/>&nbsp;&nbsp;&nbsp;&nbsp;j=i*4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#91;lead,lag&#93;= movavg(p,i,j,&#039;e&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;lead = &#91;nan(i-1,1); lead&#93;; %to avoid dimension mismatch<br/>&nbsp;&nbsp;&nbsp;&nbsp;lag = &#91;nan(j-1,1); lag&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;macs(lead&gt;lag,i) = 5;<br/>end<br/>macssum = sum(macs,2);<br/>macssum(1:80) = 50; %first 80 observations with zero position<br/>pos(macssum&gt;=N)=1;&nbsp;&nbsp;&nbsp;&nbsp;<br/>pos(macssum&lt;=(100-N))=-1;<br/></div><br/>There are other strategies left to you to backtest the effectiveness of <a href="http://www.mathfinance.cn/stock-neural-network.html" target="_blank">technical analysis</a>, for example, Kestner’s Moving Average System, Second Order Breakout, MACD Histogram Retracement, Normalized Envelope Indicator, etc. Have fun.<br/>Tags - <a href="http://www.mathfinance.cn/tags/trading/" rel="tag">trading</a> , <a href="http://www.mathfinance.cn/tags/strategy/" rel="tag">strategy</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/quantitative-trading-strategies/">Quantitative trading strategies</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/algorithmic-trading-MATLAB-webinar/</link>
<title><![CDATA[Algorithmic Trading with MATLAB Webinar]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 05 Oct 2009 10:37:57 +0000</pubDate> 
<guid>http://www.mathfinance.cn/algorithmic-trading-MATLAB-webinar/</guid> 
<description>
<![CDATA[Just a followup of my previous entry <a href="http://www.mathfinance.cn/matlab-trading-code/" target="_blank">Matlab trading code</a>, where you can watch <strong>Algorithmic Trading with MATLAB Webinar</strong> following one of the links. Dr. Aly Kassam again introduces in plain language how to use simple Matlab commands for algo trading and what's new for 2009 . <br/><br/>Click <a href="http://www.mathworks.com/company/events/webinars/wbnr34139.html?id=34139&p1=523845973&p2=523845982" target="_blank" rel="nofollow">here</a> to watch it, including:<br/><div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">• building a robust and generic back-testing framework<br/>• building and testing nonlinear trading models<br/>• using parallel computing to improve efficiency<br/>• deploying models to work with third party software</div></div><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/trading/" rel="tag">trading</a> , <a href="http://www.mathfinance.cn/tags/algo/" rel="tag">algo</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/algorithmic-trading-MATLAB-webinar/">Algorithmic Trading with MATLAB Webinar</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/make-matlab-fast-fly/</link>
<title><![CDATA[Making your Matlab Fly]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Sun, 04 Oct 2009 11:51:36 +0000</pubDate> 
<guid>http://www.mathfinance.cn/make-matlab-fast-fly/</guid> 
<description>
<![CDATA[Undoubtedly <a href="http://www.mathfinance.cn/category/matlab/" target="_blank">Matlab</a> is one of Quant researchers' most favorite software, easy for beginners, helpful doc, amounts of online free shared codes, etc., unfortunately, when compared with others like C++, one con of Matlab I often heard is its slow speed.&nbsp;&nbsp;As an Interpreted Language, Matlab is in some sense less efficient than Compiled language, however, we can speed it up by using tricks like vectorization, to fly your Matlab, below are tips and tricks I personally find useful and easy to apply.<br/><br/>1, Writing Fast MATLAB Code, <a href="http://www.math.ucla.edu/~getreuer/matopt.pdf" target="_blank"rel="nofollow">PDF doc</a>;<br/>2, Maximize Matlab performance, <a href="http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/matlab_prog/ch7_per6.html" target="_blank" rel="nofollow">http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/matlab_prog/ch7_per6.html</a>;<br/>3, MATLAB array manipulation tips and tricks, <a href="http://home.online.no/~pjacklam/matlab/doc/mtt/index.html" target="_blank" rel="nofollow">http://home.online.no/~pjacklam/matlab/doc/mtt/index.html</a>;<br/>4, matlab tips and tricks, <a href="http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html" target="_blank" rel="nofollow">http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html</a>;<br/>5, Accelerating Matlab, <a href="http://research.microsoft.com/en-us/um/people/minka/software/matlab.html" target="_blank" rel="nofollow">http://research.microsoft.com/en-us/um/people/minka/software/matlab.html</a><br/><br/>Many other Matlab accelerating skills can be found on the webpage 4. Be ready to take off.&nbsp;&nbsp;<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/make-matlab-fast-fly/">Making your Matlab Fly</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/gaussian-process-regression/</link>
<title><![CDATA[Gaussian Process Regression]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 22 Sep 2009 10:19:28 +0000</pubDate> 
<guid>http://www.mathfinance.cn/gaussian-process-regression/</guid> 
<description>
<![CDATA[I recently read a paper comparing the performances of different models to predict stock returns, at the end the authors rank the models by their out-of-sample symmetric mean absolute percentage error (SMAPE), surprisingly for me, The winning four models turned out to be:<br/>1: <strong>Gaussian process regression</strong>;<br/>2: <a href="http://www.mathfinance.cn/neural-network-source-code/" target="_blank">Neural network</a>;<br/>3: Multiple regression model;<br/>4: A very simple model based on a simple moving average.<br/><br/>What interests me is <strong>Gaussian process regression</strong> is the best model by the authors, as stated: "A List of different monitored learning techniques have been attempted to predict future stock returns, both for potential monetary make and because it is an interesting research problem. We use regression to capture changes in stock price prediction as a function of a covariance<br/>(kernel or Gram) matrix. For our aims it is natural to think of the price of a stock as being some function over time. Generally, a Gaussian processes can be cosidered to be defining a distrubution over functions with the inference step occurring directly in the space of functions. Thus, by using <strong>Gaussian process regression</strong> to extend a function beyond known price data, we can predict whether stocks will rise or fall the next day, and by how much."<br/><br/>Should you are interested, here is a book Gaussian Processes for Machine Learning to be freely downloaded, accompanying Matlab package is also available at the website.<br/><a href="http://www.gaussianprocess.org/gpml/" target="_blank" rel="nofollow">http://www.gaussianprocess.org/gpml/</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/regression/" rel="tag">regression</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/gaussian-process-regression/">Gaussian Process Regression</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-trading-code/</link>
<title><![CDATA[Matlab trading code]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Sat, 25 Jul 2009 07:31:36 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-trading-code/</guid> 
<description>
<![CDATA[I have been on vacation for exactly two weeks, reading Chinese fictions, visiting parents and friends, enjoying delicious food, etc. Life is wonderful except I have a little worry about my British visa. <br/><br/><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2FQuantitative-Trading-Build-Algorithmic-Business%2Fdp%2F0470284889%3Fie%3DUTF8%26qid%3D1248506281%26sr%3D8-1&tag=quanfinacodei-20&linkCode=ur2&camp=1789&creative=9325">Quantitative Trading: How to Build Your Own Algorithmic Trading Business</a><img src="http://www.assoc-amazon.com/e/ir?t=quanfinacodei-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> is a great book I bought several months ago but had few chances to read until recently. It is an easy-to-understand book on implementing quantitative (or algorithmic) trading for independent traders. This is the area fascinating me from right the beginning of learning quantitative finance. Therefore I have started to play <strong>algorithem trading with Matlab</strong>, the three sites I have visited often within the last week are: <br/><iframe align="left" src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=quanfinacodei-20&o=1&p=8&l=as1&m=amazon&f=ifr&asins=0470284889" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>Recorded Webinar: Algorithmic Trading with MATLAB for Financial Applications: <a href="http://www.mathworks.com/company/events/webinars/wbnr30376.html?id=30376&p1=50647&p2=50649" target="_blank" rel="nofollow">http://www.mathworks.com/company/events/webinars/wbnr30376.html?id=30376&p1=50647&p2=50649</a><br/><strong>Trading with Matlab</strong>: <a href="http://www.tradingwithmatlab.com/home" target="_blank" rel="nofollow">http://www.tradingwithmatlab.com/home</a><br/>Interactive Brokers via Matlab: <a href="http://www.maxdama.com/2008/12/interactive-brokers-via-matlab.html" target="_blank" rel="nofollow">http://www.maxdama.com/2008/12/interactive-brokers-via-matlab.html</a><br/><br/>There you could find and download useful resources and API code on <strong>Matlab trading</strong>, for instance, Pairs Trading, Intraday Data Acquisition. Enjoy.<br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/trading/" rel="tag">trading</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-trading-code/">Matlab trading code</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/simulation-based-estimation-contingent-claims-price/</link>
<title><![CDATA[Simulation-Based Estimation of Contingent-Claims Prices]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 18 Jun 2009 10:56:07 +0000</pubDate> 
<guid>http://www.mathfinance.cn/simulation-based-estimation-contingent-claims-price/</guid> 
<description>
<![CDATA[Please allow me to share an interesting paper I came across this morning, <em>Simulation-Based Estimation of Contingent-Claims Prices</em>, the main point of this paper is to use <a href="http://www.mathfinance.cn/tags/monte_carlo/" target="_blank">Monte Carlo simulation</a>, along with <a href="http://www.mathfinance.cn/maximum-likelihood-estimation/" target="_blank">Maximum likelihood estimation (MLE)</a>, to reduce the biases caused by MLE method alone,<div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">A new methodology is proposed to estimate theoretical prices of financial contingent claims whose values are dependent on some other underlying financial assets. In the literature, the preferred choice of estimator is usually maximum likelihood (ML). ML has strong asymptotic justification but is not necessarily the best method in finite samples. <br/>This paper proposes a simulation-based method. When it is used in connection with ML, it can improve the finite-sample performance of the ML estimator while maintaining its good asymptotic properties. The method is implemented and evaluated here in the <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Black-Scholes option pricing model </a> and in the <a href="http://www.mathfinance.cn/tags/vasicek/" target="_blank">Vasicek bond</a> and bond option pricing<br/>model. It is especially favored when the bias in ML is large due to strong persistence in the data or strong nonlinearity in pricing functions. Monte Carlo studies show that the proposed procedures achieve bias reductions over ML estimation in pricing contingent claims when ML is biased. The bias reductions are sometimes accompanied by reductions in variance. Empirical applications to U.S. Treasury bills highlight the differences between the bond prices implied by the simulation-based approach and those delivered by ML. Some consequences for the statistical testing of contingent-claim pricing models are discussed.</div></div><br/>Download the paper and accompanying matlab code at <a href="http://www.mysmu.edu/faculty/yujun/research.html" target="_blank" rel="nofollow">http://www.mysmu.edu/faculty/yujun/research.html</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/simulation/" rel="tag">simulation</a> , <a href="http://www.mathfinance.cn/tags/mle/" rel="tag">mle</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/simulation-based-estimation-contingent-claims-price/">Simulation-Based Estimation of Contingent-Claims Prices</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/vector-autoregression/</link>
<title><![CDATA[Vector autoregression (VAR)]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 12 Jun 2009 12:52:30 +0000</pubDate> 
<guid>http://www.mathfinance.cn/vector-autoregression/</guid> 
<description>
<![CDATA[Neil left me a <a href="http://www.mathfinance.cn/contact-me" target="_blank" rel="nofollow">message</a>: "...I am looking for examples of <strong>Vector Autoregression</strong> so I can code into excel, do you know of any links or any books that have this as code..."<br/><br/><strong>Vector autoregression (VAR) model</strong> is one of the most successful, flexible, and easy to use models for the analysis of multivariate time series. It is a natural extension of the univariate autoregressive model to dynamic multivariate time series. The VAR model has proven to be especially useful for describing the dynamic behavior of economic and financial time series and<br/>for forecasting. <a href="http://en.wikipedia.org/wiki/Vector_autoregression" target="_blank" rel="nofollow">Wikipedia </a> has a detailed explanation on it.<br/><br/>Unfortunately I have not used it except once I tried the built-in VAR function in Eviews over 5 years ago, when one of my classmates did a seminar presentation on it. Sorry I couldn't find useful VBA code, what i do get is a sample spreadsheet showing the VAR Series Analysis & Results but it seems the author intentionly hides the macro code, <a href="http://www.afpc.tamu.edu/courses/622/files/lecturedemos/Lecture%2007%20Vector%20Autoregression.xls" target="_blank" rel="nofollow">http://www.afpc.tamu.edu/courses/622/files/lecturedemos/Lecture%2007%20Vector%20Autoregression.xls</a>.<br/><br/>If you are happy with Matlab, here is a <strong>Vector autoregression (VAR)</strong> package where you can track line by line how to implement and use the model, hope it helps, <a href="http://www.rri.wvu.edu/WebBook/LeSage/etoolbox/var_bvar/contents.html" target="_blank" rel="nofollow">http://www.rri.wvu.edu/WebBook/LeSage/etoolbox/var_bvar/contents.html</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/vector-autoregression/" rel="tag">vector-autoregression</a> , <a href="http://www.mathfinance.cn/tags/var/" rel="tag">var</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/vector-autoregression/">Vector autoregression (VAR)</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-toolbox/</link>
<title><![CDATA[Matlab toolbox]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 08 Jun 2009 16:09:50 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-toolbox/</guid> 
<description>
<![CDATA[Dozens of <strong>Matlab toolboxes</strong>(packages) for downloading, including the following classifications:<br/>Audio - Astronomy - BiomedicalInformatics - Chemometrics&nbsp;&nbsp;- Chaos - Chemistry - Coding - Control - Communications - Engineering - Data Mining - Excel - FEM - Fuzzy - Finance - GAs - Graph - Graphics - Images - ICA - Kernel - Markov - Medical - MIDI - Misc. - MPI - NNets - Oceanography - Optimization - Plot - Signal Processing - Optimization - Statistics - SVM&nbsp;&nbsp;- Web - etc ...<br/><br/>Recommended <strong>matlab toolboxes</strong>:<br/><a href="http://www.mathfinance.cn/kernel-density-estimation/" target="_blank">Kernel Density Estimation</a> Toolbox <br/>http://ssg.mit.edu/~ihler/code/&nbsp;&nbsp;<br/><br/><a href="http://www.mathfinance.cn/bootstrapping-yield-curve/" target="_blank">BOOTSTRAP</a> MATLAB TOOLBOX<br/>http://www.csp.curtin.edu.au/downloads/bootstrap_toolbox.html<br/><br/>CompEcon Toolbox for Matlab<br/>http://www4.ncsu.edu/~pfackler/compecon/toolbox.html<br/><br/>Random <a href="http://www.mathfinance.cn/neural-network-source-code/" target="_blank">Neural Networks</a><br/>http://www.cs.ucf.edu/~ahossam/rnnsimv2/<br/><br/>Logistic regression <br/>http://www.spatial-econometrics.com/ <br/><br/>ARfit: A Matlab package for the estimation of parameters and eigenmodes of multivariate autoregressive models<br/>http://www.gps.caltech.edu/~tapio/arfit/<br/><br/>Time Series Analysis<br/>http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/tsa/<br/><br/>Interested ppl may download more at <a href="http://www.tech.plym.ac.uk/spmc/links/matlab/matlab_toolbox.html" target="_blank" rel="nofollow">http://www.tech.plym.ac.uk/spmc/links/matlab/matlab_toolbox.html</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/matlab/" rel="tag">matlab</a> , <a href="http://www.mathfinance.cn/tags/toolbox/" rel="tag">toolbox</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-toolbox/">Matlab toolbox</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/matlab-optimization-introduction/</link>
<title><![CDATA[Matlab optimization introduction]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Fri, 05 Jun 2009 09:12:10 +0000</pubDate> 
<guid>http://www.mathfinance.cn/matlab-optimization-introduction/</guid> 
<description>
<![CDATA[it is indisputable that <a href="http://www.mathfinance.cn/optimization-packages/" target="_blank">optimization </a>has been a crucial part to our financial world, the application of optimization routine ranges from fundamental <a href="http://www.mathfinance.cn/markowitz-efficient-frontier/" target="_blank">mean-variance Markowitz efficient frountier </a>to advanced <a href="http://www.mathfinance.cn/neural-network-source-code/" target="_blank">neural network stock price prediction</a>. Here is a carefully selected group of methods for unconstrained and bound constrained <strong>Matlab optimization </strong>problems including:<br/><strong>Line Search Methods</strong>: <br/>steep.m : Steepest Descent <br/>gaussn.m : Damped Gauss-Newton <br/>bfgswopt.m : BFGS, low storage <br/>Polynomial line search routines: polyline.m , polymod.m <br/>Numerical Derivatives: diffhess.m : Difference Hessian, <br/>requires dirdero.m : directional derivative, as do several other codes <br/><strong>Trust Region Codes</strong>: <br/>ntrust.m : Newton's Method with Simple Dogleg <br/>levmar.m : Levenberg-Marquardt for nonlinear least squares <br/>cgtrust.m : Steihaug CG-dogleg <br/><strong>Bound Constrained Problems</strong>: <br/>gradproj.m : Gradient Projection Method <br/>projbfgs.m: Projected BFGS code <br/><strong>Noisy Problems</strong>: <br/>imfil.m : Implicit Filtering <br/>nelder.m : Nelder-Mead <br/>simpgrad.m : Simplex Gradient, used in implicit filtering and Nelder-Mead codes <br/>hooke.m : Hooke-Jeeves code <br/>mds.m : Multidirectional Search code&nbsp;&nbsp; <br/>Check <a href="http://www.siam.org/books/kelley/fr18/matlabcode.php" target="_blank" rel="nofollow">http://www.siam.org/books/kelley/fr18/matlabcode.php</a> for detail.<br/>Tags - <a href="http://www.mathfinance.cn/tags/optimization/" rel="tag">optimization</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/matlab-optimization-introduction/">Matlab optimization introduction</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/heuristic-optimization-downside-risk-minimization/</link>
<title><![CDATA[Heuristic Optimization for Downside Risk Minimization]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Thu, 28 May 2009 16:24:44 +0000</pubDate> 
<guid>http://www.mathfinance.cn/heuristic-optimization-downside-risk-minimization/</guid> 
<description>
<![CDATA[Modern portfolio optimization started with <a href="http://www.mathfinance.cn/markowitz-efficient-frontier/" target="_blank">Markowitz Efficient Frontier</a>, <strong>Heuristic search and optimization</strong> is a new approach for solving complex problems that overcomes many shortcomings of traditional <a href="http://www.mathfinance.cn/optimization-packages/" target="_blank">optimization techniques</a>. <strong>Heuristic optimization </strong>techniques are general purpose methods that are very flexible and can be applied to many types of objective functions and constraints, especially where the objective function is non-convex and has many local minima. This is in particular the case when the risk is expressed as <a href="http://www.mathfinance.cn/var-expected-shortfall-t-distribution/" target="_blank">VaR, expected shortfall</a>, Omega, maximum loss etc., and when the future returns of the individual assets are modelled as scenarios.<br/><br/>An interesting paper "<a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=910233" target="_blank" rel="nofollow">A Data-Driven Optimization Heuristic for Downside Risk Minimization</a>" demonstrates how to apply <strong>Heuristic optimization method </strong>under constraint of downside risk, code can be downloaded at <a href="http://comisef.eu/?q=resources_data_driven_opt" target="_blank" rel="nofollow">http://comisef.eu/?q=resources_data_driven_opt</a>, take a look if interested. <br/>Tags - <a href="http://www.mathfinance.cn/tags/heuristic/" rel="tag">heuristic</a> , <a href="http://www.mathfinance.cn/tags/optimization/" rel="tag">optimization</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/heuristic-optimization-downside-risk-minimization/">Heuristic Optimization for Downside Risk Minimization</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/binomial-tree-american-option/</link>
<title><![CDATA[Binomial tree for American option]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 20 May 2009 16:26:20 +0000</pubDate> 
<guid>http://www.mathfinance.cn/binomial-tree-american-option/</guid> 
<description>
<![CDATA[This is a follow up post of my previous entry <a href="http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/" target="_blank">Nine Ways to Implement Binomial Tree Option Pricing</a> because the latter covers European option only. Compared with <a href="http://www.mathfinance.cn/Crank-Nicholson-american-option" target="_blank">pricing American option by Crank-Nicholson finite difference</a> or <a href="http://www.mathfinance.cn/least_square_monte_carlo/" target="_blank">American Options via least square Monte Carlo Simulation</a>, Binomial tree is the easiest to implement, what you need to do is just adding a MAX expression on every node of your tree.<br/><br/>Here is a <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1341181" target="_blank" rel="nofollow">paper</a> on the implementation of <strong>binomial tree methods for the pricing of American option</strong>' value and <a href="http://www.mathfinance.cn/option-greeks/" target="_blank">Greeks</a>, matlab codes can be found in the paper or separately <a href="http://comisef.eu/?q=implementing_binomial_trees" target="_blank" rel="nofollow">here</a>. <br/>Tags - <a href="http://www.mathfinance.cn/tags/binomial/" rel="tag">binomial</a> , <a href="http://www.mathfinance.cn/tags/american/" rel="tag">american</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/binomial-tree-american-option/">Binomial tree for American option</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/</link>
<title><![CDATA[Nine Ways to Implement Binomial Tree Option Pricing]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Mon, 18 May 2009 14:51:19 +0000</pubDate> 
<guid>http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/</guid> 
<description>
<![CDATA[<strong>Binomial tree model</strong> is almost the most popular yet easiest way for option pricing, for one thing, it can be used for most option classes in market, for example, European option, American option, Bermuda option, etc.; for another, <strong>Binomial tree </strong>is straitforward to implement, several lines are enough for a vanilla option. Besides, it has a not-bad convergence speed, read my old post <a href="http://www.mathfinance.cn/avoid-oscillation-Binomial-tree/" target="_blank">A Simple Trick to Avoid Oscillation in Binomial Trees</a> for improvement. <br/><br/>But how many ways are you able to <strong>implement binomial trees</strong>? here is a pretty interesting paper on <strong>Nine Ways to Implement Binomial Tree Option Pricing</strong>, unlike <a href="http://www.mathfinance.cn/black_scholes_language/" target="_blank">Mr. espen haug's more than 30 languages collection of Black Scholes model</a>, these nine ways are all runnable in Matlab only, and the difference among them is computational efficiency, below is a plot of execution times of the first five<br/><a href="http://www.mathfinance.cn/attachment.php?fid=12" target="_blank"><img src="http://www.mathfinance.cn/attachment.php?fid=12" class="insertimage" alt="Open in new window" title="Open in new window" border="0" width="500" height="400"/></a><br/><br/>here are the <a href="http://personal.strath.ac.uk/d.j.higham/reps.html" target="_blank" rel="nofollow">paper</a> and <a href="http://personal.strath.ac.uk/d.j.higham/algfiles.html" target="_blank" rel="nofollow">matlab codes</a>, you might feel in the end <strong>binomial tree implemention</strong> is not such easy .<br/><br/>Enjoy.<br/> <br/>Tags - <a href="http://www.mathfinance.cn/tags/binomial/" rel="tag">binomial</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/nine-ways-implement-binomial-tree-option-pricing/">Nine Ways to Implement Binomial Tree Option Pricing</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/neural-network-source-code/</link>
<title><![CDATA[Neural Network source code]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Wed, 22 Apr 2009 15:02:31 +0000</pubDate> 
<guid>http://www.mathfinance.cn/neural-network-source-code/</guid> 
<description>
<![CDATA[<strong>Neural network matlab source code</strong> accompanying the book <strong>Neural Networks in Finance</strong>: Gaining Predictive Edge in the Market by professor Paul D. McNelis. This book has got wonderful review like “This book clarifies many of the mysteries of <strong>Neural Networks</strong> and related optimization techniques for researchers in both economics and finance. It contains many practical examples backed up with computer programs for readers to explore. I recommend it to anyone who wants to understand methods used in nonlinear forecasting.”– Blake LeBaron, Professor of Finance, Brandeis University”. Presumably a worthy-reading one. <br/><br/><a href="http://www.jdoqocy.com/c2111js0ys-FJKLGMLMFHGKGGILN" target="_blank"><br/><img src="http://www.tqlkg.com/sj118c37w1-LPQRMSRSLNMQMMORT" align="left" alt="" border="0"/></a>Download the <strong>Neural Network matlab source code</strong> and several paper at the author's webpage: http://www.bnet.fordham.edu/mcnelis/recent.htm or try using <a href="http://www.tkqlhce.com/10107uoxuowBFGHCIHIBDGHJHEG" target="_blank" onmouseover="window.status='http://tradingsolutions.com/';return true;" onmouseout="window.status=' ';return true;">TradingSolutions:</a> Financial analysis and investment software that combines technical analysis with neural network and genetic algorithms. <img src="http://www.ftjcfx.com/sf105xjnbhf0456176702568635" width="1" height="1" border="0"/><br/><br/><a href="http://www.anrdoezrs.net/8r97lnwtnvAEFGBHGHACBFBCFHB" target="_blank" onmouseover="window.status='http://tradingsolutions.com/';return true;" onmouseout="window.status=' ';return true;">Download TradingSolutions</a><br/><img src="http://www.lduhtrp.net/20110p59y31NRSTOUTUNPOSOPSUO" width="1" height="1" border="0"/><br/>Tags - <a href="http://www.mathfinance.cn/tags/neural-network/" rel="tag">neural-network</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/neural-network-source-code/">Neural Network source code</a></strong>.
]]>
</description>
</item><item>
<link>http://www.mathfinance.cn/managing-diversification/</link>
<title><![CDATA[Managing Diversification]]></title> 
<author>abiao &lt;&gt;</author>
<category><![CDATA[Matlab]]></category>
<pubDate>Tue, 21 Apr 2009 17:27:15 +0000</pubDate> 
<guid>http://www.mathfinance.cn/managing-diversification/</guid> 
<description>
<![CDATA[Needless to say, <strong>diversification</strong> plays a pivotal role in investment, not only for risk management, but for return generation. Attilio Meucci and his colleagues have another wonderful paper on managing diversification:<div class="quote"><div class="quote-title">Quotation</div><div class="quote-content">We propose a unified, fully general methodology to analyze and act on <strong>diversification</strong> in any environment, including long-short trades in highly correlated markets. First, we build the <strong>diversification</strong> distribution, i.e. the distribution of the uncorrelated bets in the portfolio that are consistent with the portfolio constraints. Next, we summarize the wealth of information provided by the <strong>diversification</strong> distribution into one single diversification index, the effective number of bets, based on the entropy of the <strong>diversification distribution</strong>. Then, we introduce the <a href="http://www.mathfinance.cn/markowitz-efficient-frontier/" target="_blank">mean-diversification efficient frontier</a>, a diversification approach to portfolio optimization. Finally, we describe how to perform mean-diversification <a href="http://www.mathfinance.cn/tags/optimization/" target="_blank">optimization</a> in practice in the presence of transaction and market impact costs, by only trading a few optimally chosen securities.</div></div><br/><br/>Click for codes <a href="http://www.mathworks.com/matlabcentral/fileexchange/23271" target="_blank" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/23271</a><br/>Tags - <a href="http://www.mathfinance.cn/tags/diversification/" rel="tag">diversification</a><br /><strong>Read the full post at <a href="http://www.mathfinance.cn/managing-diversification/">Managing Diversification</a></strong>.
]]>
</description>
</item>
</channel>
</rss>