Extracting Stock Price Data from Yahoo via R

Arguably one of Yahoo's most valuable assets, aside from its stake in BABA, was it's finance website. Few sites, including Google, have such readily (freely) accessible and easily digestible financial information on US equities than Yahoo does. Of course, for the financially sophisticated there are far superior sites that have advanced charting platforms and useful visualizations (TradingView and FinViz come to mind),…

Parallelism for Model Training (using the caret package)

In a previous post we discussed how to achieve parallel programming in R using the doParallel package. This post provides an application of parallelism for training a model using the caret package. We use repeated cross validation to train a support vector machine (note the iris data is small and doesn't require such exhaustive training; it was merely used for…

Risk Factor Back-Testing

P&L exceeding VaR limits is not an uncommon phenomenon. In fact, (accurate) VaR models should be designed such that there is some expectation of P&L exceeding the VaR (the number of breaches being proportionate to the level of confidence). However, in practice, whenever P&L exceeds VaR it is prudent to investigate why the breach has occurred. For OSFI-regulated financial institutions,…

Upper Bound for RER under VaR

In continuation of some previous posts on residual estimation risk (RER), we establish an upper bound for RER when the risk measure is VaR for any arbitrary error distribution , where the error distribution is defined as the difference between an actual loss distribution and a loss estimator (see [1] for more details).   Asymmetric Error Distribution For an arbitrary…

Sensitivities for Make-whole Callable Bonds

A callable bond is a bond that provides the issuer with the right to exchange the bond for its call value in cash. There are a few ways one can value a callable bond by extending the expression of a vanilla bond: Yield-to-x: Calculate the yield-to-maturity, yield(s)-to-call, and/or yield-to-worst and take the lowest of this set. Revalue the bond with…

Some Simple Measures of Correlation

To implement the following measures of correlation, we use the ‘wine’ dataset from the HDclassif package. To wet your palate, we test for correlation between ‘alcohol’ and ‘proline’ (an amino acid) content. Note that we employ the correlation measure tests from the psych, rather than base package.   Pearson’s Rho Correlation The Pearson correlation coefficient is a measure of the linear…

Numerical Mellin and Two-Sided Laplace Inversion

There are only a handful of methods for numerical Mellin (or equivalently, two-sided Laplace) inversion that have survived due to their computational accuracy and efficiency. One of these such methods is accredited to Dishon and Weiss [1]. The method is quite accurate despite being a numerical approximation and requiring the evaluation of an infinite series. We implement example 1 in…