├── DESCRIPTION ├── Meucci_functions.csv ├── NAMESPACE ├── R ├── BlackLittermanFormula.R ├── BlackScholesCallPrice.R ├── ButterflyTradingFunctions.R ├── CentralAndStandardizedStatistics.R ├── CmaCopula.R ├── ConvertChangeInYield2Price.R ├── CovertCompoundedReturns2Price.R ├── DetectOutliersviaMVE.R ├── DoubleDecay.R ├── EfficientFrontierPrices.R ├── EfficientFrontierReturns.R ├── EfficientFrontierReturnsBenchmark.R ├── EntropyProg.R ├── Fit2Moms.R ├── FitExpectationMaximization.R ├── FitMultivariateGarch.R ├── FitOrnsteinUhlenbeck.R ├── FullyFlexibleBayesNets.R ├── GenerateUniformDrawsOnUnitSphere.R ├── HermiteGrid.R ├── InterExtrapolate.R ├── InvariantProjection.R ├── LeastInfoKernel.R ├── Log2Lin.R ├── LognormalCopulaPdf.R ├── LognormalMoments2Parameters.R ├── LognormalParameters2Statistics.R ├── MaxRsqCS.R ├── MaxRsqTS.R ├── MeanDiversificationFrontier.R ├── MleRecursionForStudentT.R ├── MultivariateOUnCointegration.R ├── MvnRnd.R ├── NormalCopulaPdf.R ├── PerformIidAnalysis.R ├── PlotCompositionEfficientFrontier.R ├── PlotDistributions.R ├── PlotMarginalsNormalInverseWishart.R ├── PlotVolVsCompositionEfficientFrontier.R ├── Prior2Posterior.R ├── ProjectionStudentT.R ├── QuantileMixture.R ├── RandNormalInverseWishart.R ├── RankingInformationFunctions.R ├── RobustBayesianAllocation.R ├── SimulateJumpDiffusionMerton.R ├── StudentTCopulaPdf.R ├── TwoDimEllipsoid.R ├── data.R ├── logToArithmeticCovariance.R └── pHistPriorPosterior.R ├── THANKS ├── TODO ├── data ├── bondAttribution.rda ├── butterfliesAnalytics.rda ├── covNRets.rda ├── db.rda ├── dbFFP.rda ├── derivatives.rda ├── equities.rda ├── fILMR.rda ├── fX.rda ├── factorsDistribution.rda ├── fixedIncome.rda ├── freaqEst.rda ├── highYieldIndices.rda ├── implVol.rda ├── linearModel.rda ├── returnsDistribution.rda ├── sectorsSnP500.rda ├── sectorsTS.rda ├── securitiesIndustryClassification.rda ├── securitiesTS.rda ├── stockSeries.rda ├── swap2y4y.rda ├── swapParRates.rda ├── swaps.rda ├── timeSeries.rda └── usSwapRates.rda ├── demo ├── 00Index ├── AnalyticalvsNumerical.R ├── ButterflyTrading.R ├── DetectOutliersviaMVE.R ├── FullFlexProbs.R ├── FullyFlexibleBayesNets.R ├── FullyIntegratedLiquidityAndMarketRisk.R ├── HermiteGrid_CVaR_Recursion.R ├── HermiteGrid_CaseStudy.R ├── HermiteGrid_demo.R ├── InvariantProjection.R ├── MeanDiversificationFrontier.R ├── Prior2Posterior.R ├── RankingInformation.R ├── RobustBayesianAllocation.R ├── S_AnalyzeLognormalCorrelation.R ├── S_AnalyzeNormalCorrelation.R ├── S_AnalyzeNormalInverseWishart.R ├── S_AutocorrelatedProcess.R ├── S_BivariateSample.R ├── S_BlackLittermanBasic.R ├── S_BondProjectionPricingNormal.R ├── S_BondProjectionPricingStudentT.R ├── S_BuyNHold.R ├── S_CPPI.R ├── S_CallsProjectionPricing.R ├── S_CheckDiagonalization.R ├── S_CornishFisher.R ├── S_CorrelationPriorUniform.R ├── S_CovarianceEvolution.R ├── S_CrossSectionConstrainedIndustries.R ├── S_CrossSectionIndustries.R ├── S_DerivativesInvariants.R ├── S_DeterministicEvolution.R ├── S_DisplayLognormalCopulaPdf.R ├── S_DisplayNormalCopulaCdf.R ├── S_DisplayNormalCopulaPdf.R ├── S_DisplayStudentTCopulaPdf.R ├── S_ESContributionFactors.R ├── S_ESContributionsStudentT.R ├── S_EigenvalueDispersion.R ├── S_EllipticalNDim.R ├── S_EntropyView.R ├── S_EquitiesInvariants.R ├── S_EquityProjectionPricing.R ├── S_EstimateExpectedValueEvaluation.R ├── S_EstimateMomentsComboEvaluation.R ├── S_EstimateQuantileEvaluation.R ├── S_Estimator.R ├── S_EvaluationGeneric.R ├── S_ExactMeanAndCovariance.R ├── S_ExpectationMaximizationHighYield.R ├── S_ExtremeValueTheory.R ├── S_FactorAnalysisNotOk.R ├── S_FactorResidualCorrelation.R ├── S_FitProjectRates.R ├── S_FitSwapToStudentT.R ├── S_FixedIncomeInvariants.R ├── S_FullCodependence.R ├── S_FxCopulaMarginal.R ├── S_GenerateMixtureSample.R ├── S_HedgeOptions.R ├── S_HorizonEffect.R ├── S_InvestorsObjective.R ├── S_JumpDiffusionMerton.R ├── S_LinVsLogReturn.R ├── S_LognormalSample.R ├── S_MarkovChainMonteCarlo.R ├── S_MaxMinVariance.R ├── S_MaximumLikelihood.R ├── S_MeanVarianceBenchmark.R ├── S_MeanVarianceCalls.R ├── S_MeanVarianceHorizon.R ├── S_MeanVarianceOptimization.R ├── S_MultiVarSqrRootRule.R ├── S_NonAnalytical.R ├── S_NormalSample.R ├── S_OrderStatisticsPdfLognormal.R ├── S_OrderStatisticsPdfStudentT.R ├── S_PasturMarchenko.R ├── S_ProjectNPriceMvGarch.R ├── S_ProjectSummaryStatistics.R ├── S_PureResidualBonds.R ├── S_ResidualAnalysisTheory.R ├── S_SelectionHeuristics.R ├── S_SemiCircular.R ├── S_ShrinkageEstimators.R ├── S_SnPCaseStudy.R ├── S_StatArbSwaps.R ├── S_StudentTSample.R ├── S_SwapPca2Dim.R ├── S_TStatApprox.R ├── S_TimeSeriesConstrainedIndustries.R ├── S_TimeSeriesIndustries.R ├── S_TimeSeriesVsCrossSectionIndustries.R ├── S_Toeplitz.R ├── S_ToyExample.R ├── S_UtilityMax.R ├── S_VaRContributionsUniform.R ├── S_VolatilityClustering.R ├── S_Wishart.R ├── S_WishartCorrelation.R ├── S_WishartLocationDispersion.R ├── S_plotGaussHermite.R └── logToArithmeticCovariance.R └── man ├── BlackLittermanFormula.Rd ├── BlackScholesCallPrice.Rd ├── CMAcombination.Rd ├── CMAseparation.Rd ├── Central2Raw.Rd ├── CentralAndStandardizedStatistics.Rd ├── ComputeCVaR.Rd ├── ComputeMVE.Rd ├── ComputeMoments.Rd ├── CondProbViews.Rd ├── ConvertChangeInYield2Price.Rd ├── ConvertCompoundedReturns2Price.Rd ├── Cumul2Raw.Rd ├── DetectOutliersViaMVE.Rd ├── DoubleDecay.Rd ├── EfficientFrontierPrices.Rd ├── EfficientFrontierReturns.Rd ├── EfficientFrontierReturnsBenchmark.Rd ├── EntropyProg.Rd ├── Equities.Rd ├── FDButterflies.Rd ├── Fit2Moms.Rd ├── FitExpectationMaximization.Rd ├── FitMultivariateGarch.Rd ├── FitOU.Rd ├── FitOrnsteinUhlenbeck.Rd ├── GenFirstEigVect.Rd ├── GenPCBasis.Rd ├── GenerateLogNormalDistribution.Rd ├── GenerateUniformDrawsOnUnitSphere.Rd ├── HorizonPricing.Rd ├── InterExtrapolate.Rd ├── LeastInfoKernel.Rd ├── Log2Lin.Rd ├── LognormalCopulaPdf.Rd ├── LognormalMoments2Parameters.Rd ├── LognormalParam2Statistics.Rd ├── LongShortMeanCVaRFrontier.Rd ├── MaxEntropy.Rd ├── MaxRsqCS.Rd ├── MaxRsqTS.Rd ├── MeanTCEntropyFrontier.Rd ├── MleRecursionForStudentT.Rd ├── MvnRnd.Rd ├── NoisyObservations.Rd ├── NormalCopulaPdf.Rd ├── OUstep.Rd ├── OUstepEuler.Rd ├── PanicCopula.Rd ├── PartialConfidencePosterior.Rd ├── PerformIidAnalysis.Rd ├── PlotCompositionEfficientFrontier.Rd ├── PlotDistributions.Rd ├── PlotFrontier.Rd ├── PlotMarginalsNormalInverseWishart.Rd ├── PlotResults.Rd ├── PlotVolVsCompositionEfficientFrontier.Rd ├── Prior2Posterior.Rd ├── ProjectionStudentT.Rd ├── QuantileMixture.Rd ├── RIEfficientFrontier.Rd ├── RandNormalInverseWishart.Rd ├── Raw2Central.Rd ├── Raw2Cumul.Rd ├── RejectOutlier.Rd ├── SimulateJumpDiffusionMerton.Rd ├── StockSeries.Rd ├── StudentTCopulaPdf.Rd ├── SummStats.Rd ├── TimeSeries.Rd ├── Tweak.Rd ├── TwoDimEllipsoid.Rd ├── UsSwapRates.Rd ├── ViewCurveSlope.Rd ├── ViewImpliedVol.Rd ├── ViewRanking.Rd ├── ViewRealizedVol.Rd ├── bondAttribution.Rd ├── butterfliesAnalytics.Rd ├── covNRets.Rd ├── db.Rd ├── dbFFP.Rd ├── db_FX.Rd ├── derivatives.Rd ├── efficientFrontier.Rd ├── fILMR.Rd ├── factorsDistribution.Rd ├── fixedIncome.Rd ├── freaqEst.Rd ├── garch1f4.Rd ├── garch2f8.Rd ├── gaussHermiteMesh.Rd ├── hermitePolynomial.Rd ├── highYieldIndices.Rd ├── implVol.Rd ├── integrateSubIntervals.Rd ├── kernelbw.Rd ├── kernelcdf.Rd ├── kernelinv.Rd ├── kernelpdf.Rd ├── linearModel.Rd ├── linreturn.Rd ├── normalizeProb.Rd ├── pHist.Rd ├── pHistPriorPosterior.Rd ├── private_fun.Rd ├── returnsDistribution.Rd ├── robustBayesianPortfolioOptimization.Rd ├── sectorsSnP500.Rd ├── sectorsTS.Rd ├── securitiesIndustryClassification.Rd ├── securitiesTS.Rd ├── std.Rd ├── subIntervals.Rd ├── swap2y4y.Rd ├── swapParRates.Rd └── swaps.Rd /R/BlackLittermanFormula.R: -------------------------------------------------------------------------------- 1 | #' @title Computes the Black-Litterman formula for the moments of the posterior normal. 2 | #' 3 | #' @description This function computes the Black-Litterman formula for the moments of the posterior normal, as described in 4 | #' A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Mu [vector] (N x 1) prior expected values. 7 | #' @param Sigma [matrix] (N x N) prior covariance matrix. 8 | #' @param P [matrix] (K x N) pick matrix. 9 | #' @param v [vector] (K x 1) vector of views. 10 | #' @param Omega [matrix] (K x K) matrix of confidence. 11 | #' 12 | #' @return BLMu [vector] (N x 1) posterior expected values. 13 | #' @return BLSigma [matrix] (N x N) posterior covariance matrix. 14 | #' 15 | #' @references 16 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 17 | #' 18 | #' See Meucci's script for "BlackLittermanFormula.m" 19 | #' 20 | #' @author Xavier Valls \email{flamejat@@gmail.com} 21 | #' @export 22 | 23 | BlackLittermanFormula = function( Mu, Sigma, P, v, Omega) 24 | { 25 | BLMu = Mu + Sigma %*% t( P ) %*% ( solve( P %*% Sigma %*% t( P ) + Omega ) %*% ( v - P %*% Mu ) ); 26 | BLSigma = Sigma - Sigma %*% t( P ) %*% ( solve( P %*% Sigma %*% t( P ) + Omega ) %*% ( P %*% Sigma ) ); 27 | 28 | return( list( BLMu = BLMu , BLSigma = BLSigma ) ); 29 | 30 | } -------------------------------------------------------------------------------- /R/ConvertChangeInYield2Price.R: -------------------------------------------------------------------------------- 1 | #' @title Convert change in yield-to-maturity to price for fixed-income securities 2 | #' 3 | #' @description Convert change in yield-to-maturity to price for fixed-income securities, as described in 4 | #' A. Meucci "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Exp_DY [vector] (N x 1) expected value of change in yield to maturity 7 | #' @param Cov_DY [matrix] (N x N) covariance of change in yield to maturity 8 | #' @param Times2Mat [scalar] time to maturity 9 | #' @param CurrentPrices [vector] (N x 1) current prices 10 | #' 11 | #' @return Exp_Prices [vector] (N x 1) expected prices 12 | #' @return Cov_Prices [matrix] (N x N) covariance of prices 13 | #' 14 | #' @references 15 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 16 | #' See Meucci's script for "ConvertChangeInYield2Price.m". 17 | #' 18 | #' A. Meucci - "Risk and Asset Allocation"-Springer (2005). See (6.77)-(6.79). 19 | #' 20 | #' @author Xavier Valls \email{flamejat@@gmail.com} 21 | #' @export 22 | 23 | ConvertChangeInYield2Price = function( Exp_DY, Cov_DY, Times2Mat, CurrentPrices ) 24 | { 25 | Mu = log( CurrentPrices ) - Times2Mat * Exp_DY; 26 | Sigma = diag( Times2Mat ^ 2, length(Times2Mat) ) %*% Cov_DY; 27 | 28 | 29 | Exp_Prices = exp(Mu + (1/2) * diag( Sigma )); 30 | Cov_Prices = exp(Mu + (1/2) * diag( Sigma )) %*% t(exp(Mu + (1/2) * diag(Sigma))) * ( exp( Sigma ) - 1); 31 | 32 | return( list( Exp_Prices = Exp_Prices, Cov_Prices = Cov_Prices ) ); 33 | } -------------------------------------------------------------------------------- /R/CovertCompoundedReturns2Price.R: -------------------------------------------------------------------------------- 1 | #' @title Convert compounded returns to prices for equity-like securities. 2 | #' 3 | #' @description Convert compounded returns to prices for equity-like securities, as described in 4 | #' A. Meucci "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Exp_Comp_Rets [vector] (N x 1) expected values of compounded returns 7 | #' @param Cov_Comp_Rets [matrix] (N x N) covariance matrix of compounded returns 8 | #' @param Starting_Prices [vector] (N x 1) 9 | #' 10 | #' @return Exp_Prices [vector] (N x 1) expected values of prices 11 | #' @return Cov_Prices [matrix] (N x N) covariance matrix of prices 12 | #' 13 | #' @references 14 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 15 | #' See Meucci's script for "ConvertCompoundedReturns2Price.m". 16 | #' 17 | #' A. Meucci - "Risk and Asset Allocation"-Springer (2005). See (6.77)-(6.79). 18 | #' 19 | #' @author Xavier Valls \email{flamejat@@gmail.com} 20 | #' @export 21 | 22 | ConvertCompoundedReturns2Price = function(Exp_Comp_Rets, Cov_Comp_Rets, Starting_Prices) 23 | { 24 | Mu = log(Starting_Prices) + Exp_Comp_Rets; 25 | Sigma = Cov_Comp_Rets; 26 | 27 | Exp_Prices = exp( Mu + 0.5 * diag( Sigma ) ); 28 | Cov_Prices = exp( Mu + 0.5 * diag( Sigma ) ) %*% t( exp( Mu + 0.5 * diag(Sigma) )) * ( exp( Sigma ) - 1 ); 29 | 30 | return( list( Exp_Prices = Exp_Prices, Cov_Prices = Cov_Prices ) ); 31 | } -------------------------------------------------------------------------------- /R/DoubleDecay.R: -------------------------------------------------------------------------------- 1 | #' Computes a double-decay covariance matrix. 2 | #' 3 | #' This function computes a double-decay covariance matrix for the risk drivers provided, as described in 4 | #' A. Meucci, "Personalized Risk Management: Historical Scenarios with Fully Flexible Probabilities" 5 | #' GARP Risk Professional, Dec 2010, p 47-51 6 | #' 7 | #' @param X matrix representing the risk drivers. 8 | #' @param lmd_c numeric representing the low decay (long half-life) for the correlations. 9 | #' @param lmd_s numeric representing the high decay (short half-life) for the volatilities. 10 | #' @return m matrix of zeros, representing the expectation of the risk drivers. 11 | #' @return S matrix representing the double-decay estimation for the correlation matrix of the risk drivers. 12 | #' 13 | #' @references 14 | #' \url{http://www.symmys.com/node/150} 15 | #' See Meucci script for "DoubleDecay.m" 16 | #' 17 | #' @author Xavier Valls \email{flamejat@@gmail.com} 18 | #' @export 19 | 20 | DoubleDecay = function( X, lmd_c, lmd_s) 21 | { 22 | 23 | N = dim( X ) 24 | m = matrix( 0, N[2], 1); 25 | 26 | p_c = exp( -lmd_c * ( N[1] - t(rbind( 1:N[1] ) ) ) ); 27 | 28 | p_c = kronecker( matrix( 1, 1, N[2] ), p_c / sum( p_c ) ); # workaround on p_c=repmat( p_c/sum(p_c),1,N); 29 | 30 | S_1 = t( p_c * X ) %*% X; 31 | 32 | C = cov2cor( S_1 ); 33 | 34 | p_s = exp( -lmd_s * ( N[1] - t(rbind( 1:N[1] ) ) ) ); 35 | 36 | p_s = kronecker(matrix(1,1,N[2]),p_s/sum(p_s)); 37 | S_2 = t( p_s*X ) %*% X; 38 | 39 | R = cov2cor(S_2) ; 40 | s = c( 0.0099, 0.0538, 0.0163 ); 41 | 42 | s = sqrt(diag(S_2)); 43 | S = diag(s) %*% C %*% diag(s); 44 | 45 | return( list( m = m , S = S ) ) 46 | } -------------------------------------------------------------------------------- /R/Fit2Moms.R: -------------------------------------------------------------------------------- 1 | #' Uses Entropy Pooling to compute a double-decay covariance matrix. 2 | #' 3 | #' This function uses Entropy Pooling to compute a double-decay covariance matrix, as described in 4 | #' A. Meucci, "Personalized Risk Management: Historical Scenarios with Fully Flexible Probabilities" 5 | #' GARP Risk Professional, Dec 2010, p 47-51 6 | #' 7 | #' @param X matrix representing the risk drivers. 8 | #' @param m matrix of zeros, representing the expectation of the risk drivers. 9 | #' @param S matrix representing the double-decay estimation for the correlation matrix of the risk drivers. 10 | #' @return p list containing the vector of posterior probabilities and information about the optimization performance. 11 | #' 12 | #' @references 13 | #' \url{http://www.symmys.com/node/150} 14 | #' See Meucci script for "S_MainFullFlexProbs.m" 15 | #' 16 | #' @author Xavier Valls \email{flamejat@@gmail.com} 17 | #' @export 18 | 19 | Fit2Moms = function( X, m, S) 20 | { 21 | N = dim(X); 22 | 23 | Aeq = matrix( 1, 1, N[1] ); # constrain probabilities to sum to one... 24 | beq = 1; 25 | 26 | Aeq = rbind( Aeq , t(X) ); # ...constrain the first moments... 27 | beq = rbind( beq, m ); 28 | 29 | SecMom = S + m %*% t(m); #...constrain the second moments... 30 | 31 | for ( k in 1:N[2] ) 32 | { 33 | for ( l in k:N[2] ) 34 | { 35 | Aeq = rbind( Aeq , t(X[ ,k] * X[ ,l] ) ); 36 | beq = rbind( beq, SecMom[k,l] ); 37 | } 38 | } 39 | 40 | p_0 = matrix( 1, N[1], 1) / N[1]; 41 | 42 | return ( p = EntropyProg( p_0, matrix( , 0, 0), matrix( , 0, 0), Aeq , beq)$p_); # ...compute posterior probabilities 43 | 44 | } -------------------------------------------------------------------------------- /R/FitOrnsteinUhlenbeck.R: -------------------------------------------------------------------------------- 1 | #' @title Fits a multivariate Ornstein - Uhlenbeck process at estimation step tau. 2 | #' 3 | #' @description Fit a multivariate OU process at estimation step tau, as described in A. Meucci 4 | #' "Risk and Asset Allocation", Springer, 2005 5 | #' 6 | #' @param Y : [matrix] (T x N) 7 | #' @param tau : [scalar] time step 8 | #' 9 | #' @return Mu : [vector] long-term means 10 | #' @return Th : [matrix] whose eigenvalues have positive real part / mean reversion speed 11 | #' @return Sig : [matrix] Sig = S * S', covariance matrix of Brownian motions 12 | #' 13 | #' @note 14 | #' o dY_t = -Th * (Y_t - Mu) * dt + S * dB_t where 15 | #' o dB_t: vector of Brownian motions 16 | #' 17 | #' @references 18 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 19 | #' 20 | #' See Meucci's script for "FitOrnsteinUhlenbeck.m" 21 | #' 22 | #' @author Xavier Valls \email{flamejat@@gmail.com} 23 | #' @export 24 | 25 | FitOrnsteinUhlenbeck = function( Y, tau ) 26 | { 27 | T = nrow(Y); 28 | N = ncol(Y); 29 | 30 | X = Y[ -1, ]; 31 | F = cbind( matrix( 1, T-1, 1 ), Y[ -nrow(Y), ] ); 32 | E_XF = t(X) %*% F / T; 33 | E_FF = t(F) %*% F / T; 34 | B = E_XF %*% solve( E_FF ); 35 | if( length( B[ , -1 ] ) != 1 ) 36 | { 37 | Th = -logm( B[ , -1 ] ) / tau; 38 | 39 | }else 40 | { 41 | Th = -log( B[ , -1 ] ) / tau; 42 | } 43 | 44 | Mu = solve( diag( 1, N ) - B[ , -1 ] ) %*% B[ , 1 ] ; 45 | 46 | U = F %*% t(B) - X; 47 | 48 | Sig_tau = cov(U); 49 | 50 | N = length(Mu); 51 | TsT = kron( Th, diag( 1, N ) ) + kron( diag( 1, N ), Th ); 52 | 53 | VecSig_tau = matrix(Sig_tau, N^2, 1); 54 | VecSig = ( solve( diag( 1, N^2 ) - expm( -TsT * tau ) ) %*% TsT ) %*% VecSig_tau; 55 | Sig = matrix( VecSig, N, N ); 56 | 57 | return( list( Mu = Mu, Theta = Th, Sigma = Sig ) ) 58 | } -------------------------------------------------------------------------------- /R/GenerateUniformDrawsOnUnitSphere.R: -------------------------------------------------------------------------------- 1 | #' @title Generate a uniform sample on the unit hypersphere. 2 | #' 3 | #' @description Generate a uniform sample on the unit hypersphere, as described in A. Meucci, 4 | #' "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param J : [scalar] number of draws 7 | #' @param N : [scalar] dimension 8 | #' 9 | #' @return X : [matrix] (T x N) of draws 10 | #' 11 | #' @note 12 | #' Initial MATLAB's script by Xiaoyu Wang - Dec 2006 13 | #' 14 | #' We decompose X=U*R, where U is a uniform distribution on unit sphere and 15 | # R is a distribution on (0,1) proportional to r^(Dims-1), i.e. the area of surface of radius r. 16 | #' 17 | #' @references 18 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 19 | #' See Meucci's script for "GenerateUniformDrawsOnUnitSphere.m" 20 | #' 21 | #' @author Xavier Valls \email{flamejat@@gmail.com} 22 | #' @export 23 | 24 | GenerateUniformDrawsOnUnitSphere = function(J, N) 25 | { 26 | l = matrix( 1, 1, N ); 27 | 28 | # 1. Generate U 29 | Z = matrix( runif(J*N), J, N ); 30 | normZ = sqrt( apply( Z * Z, 1, sum ) ); 31 | U = Z / ( normZ %*% l ); 32 | 33 | # 2. Generate R 34 | # the pdf of R is proportional to r^(N-1) therefore the cdf of R is r^N 35 | # we use quantile function of R sample R from uniform simulations 36 | Y = runif(J); 37 | R = Y ^ ( 1/N ); 38 | 39 | # 3. Generate X 40 | X = U * ( R %*% l ); 41 | return( X ); 42 | } -------------------------------------------------------------------------------- /R/LeastInfoKernel.R: -------------------------------------------------------------------------------- 1 | #' Computes least information kernel smoothing 2 | #' 3 | #' This script uses Entropy Pooling to compute least information kernel smoothing, as described in 4 | #' A. Meucci, "Personalized Risk Management: Historical Scenarios with Fully Flexible Probabilities" 5 | #' GARP Risk Professional, Dec 2010, p 47-51 6 | #' 7 | #' @param Y Matrix representing the macroeconomic indicator 8 | #' @param y scalar reprenting the target to which Y is expected to be close in the Generalized Empirical Distribution 9 | #' @param h2 N X N matrix 10 | #' 11 | #' @return p list containing the vector of posterior probabilities and information about the optimization performance. 12 | #' 13 | #' @references 14 | #' \url{http://www.symmys.com/node/150} 15 | #' See Meucci script for "LeastInfoKernel.m" 16 | #' 17 | #' @author Xavier Valls \email{flamejat@@gmail.com} 18 | #' @export 19 | 20 | LeastInfoKernel = function( Y, y, h2 ) 21 | { 22 | T = dim(Y)[1]; 23 | N = dim(Y)[2]; 24 | Aeq = matrix( 1, 1, T ); # constrain probabilities to sum to one... 25 | beq = 1; 26 | # ...constrain the first moments... 27 | Aeq = rbind( Aeq, t(Y) ); 28 | beq = rbind( beq, y ); 29 | 30 | if( !is.nan(h2) ) 31 | { 32 | SecMom = h2 + y %*% t( y ); # ...constrain the second moments... 33 | for( k in 1:N ) 34 | { 35 | for( l in k:N ) 36 | { 37 | Aeq = rbind( Aeq, ( Y[ , k ] * Y[ , l ] ) ); 38 | beq = rbind( beq, SecMom[ k, l ] ); 39 | } 40 | } 41 | } 42 | p_0 = matrix( 1, T, 1 ) / T; 43 | p = EntropyProg( p_0, matrix(,0,0), matrix(,0,0), Aeq, beq ); # ...compute posterior probabilities 44 | return( p$p_ ); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /R/Log2Lin.R: -------------------------------------------------------------------------------- 1 | #' @title Maps moments of log-returns to linear returns . 2 | #' 3 | #' @description Map moments of log-returns to linear returns, as described in A. Meucci, 4 | #' "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Mu [vector] (N x 1) 7 | #' @param Sigma [matrix] (N x N) 8 | #' 9 | #' @return M [vector] (N x 1) 10 | #' @return S [matrix] (N x N) 11 | #' 12 | #' @references 13 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 14 | #' 15 | #' See Meucci's script for "Log2Lin.m" 16 | #' 17 | #' @author Xavier Valls \email{flamejat@@gmail.com} 18 | #' @export 19 | 20 | Log2Lin = function( Mu, Sigma ) 21 | { 22 | M = exp( Mu + (1/2) * diag( Sigma )) - 1; 23 | S = exp( Mu + (1/2) * diag( Sigma )) %*% t( exp( Mu + ( 1/2 ) * diag(Sigma) ) ) * ( exp( Sigma ) - 1 ); 24 | 25 | return( list( M = M, S = S ) ); 26 | } -------------------------------------------------------------------------------- /R/LognormalCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #' @title Computes the pdf of the copula of the lognormal distribution at the generic point u in the unit hypercube. 2 | #' 3 | #' @description Computes the pdf of the copula of the lognormal distribution at the generic point u in the unit hypercube, 4 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param u [vector] (J x 1) grades 7 | #' @param Mu [vector] (N x 1) location parameter 8 | #' @param Sigma [matrix] (N x N) scatter parameter 9 | #' 10 | #' @return F_U [vector] (J x 1) PDF values 11 | #' 12 | #' @references 13 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 14 | #' "E 36 - Pdf of the lognormal copula". 15 | #' 16 | #' See Meucci's script for "LognormalCopulaPdf.m" 17 | #' 18 | #' @author Xavier Valls \email{flamejat@@gmail.com} 19 | #' @export 20 | 21 | LognormalCopulaPdf = function( u, Mu, Sigma ) 22 | { 23 | N = length( u ); 24 | s = sqrt( diag( Sigma )); 25 | 26 | x = qlnorm( u, Mu, s ); 27 | 28 | Numerator = ( 2 * pi ) ^ ( -N / 2 ) * ( (det ( Sigma ) ) ^ ( -0.5 ) ) / 29 | prod(x) * exp( -0.5 * t(log(x) - Mu) %*% mldivide( Sigma , ( log( x ) - Mu ), pinv=FALSE ) ); 30 | 31 | fs = dlnorm( x, Mu, s); 32 | 33 | Denominator = prod(fs); 34 | 35 | F_U = Numerator / Denominator; 36 | 37 | return ( F_U ); 38 | } -------------------------------------------------------------------------------- /R/LognormalMoments2Parameters.R: -------------------------------------------------------------------------------- 1 | #' @title Computes the mean and standard deviation of a lognormal distribution from its parameters. 2 | #' 3 | #' @description Computes the mean and standard deviation of a lognormal distribution from its parameters, as described in 4 | #' A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' \deqn{\sigma^{2} = \ln \left( 1 + \frac{V}{E^{2}} \right) , } 7 | #' \deqn{\mu = \ln(E) - \frac{1}{2} \ln \left( 1 + \frac{V}{E^{2}} \right) .} 8 | #' 9 | #' 10 | #' @param e [scalar] expected value of the lognormal distribution 11 | #' @param v [scalar] variance of the lognormal distribution 12 | #' 13 | #' @return mu [scalar] expected value of the normal distribution 14 | #' @return sig2 [scalar] variance of the normal distribution 15 | #' 16 | #' @note Inverts the formulas (1.98)-(1.99) in "Risk and Asset Allocation", Springer, 2005. 17 | #' 18 | #' @references 19 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, "E 25 - Simulation of a lognormal random variable". 20 | #' 21 | #' See Meucci's script for "LognormalMoments2Parameters.m" 22 | #' 23 | #' @author Xavier Valls \email{flamejat@@gmail.com} 24 | #' @export 25 | 26 | #determines $\mu$ and $\sigma^2$ from $\Expect\{X\}$ and $\Var\{X\}$, and uses it to determine $\mu$ 27 | # and $\sigma^{2}$ such that $\Expect\left\{ X\right\} \equiv 3$ and $\Var\left\{ X\right\} \equiv 5$ 28 | LognormalMoments2Parameters = function( e, v ) 29 | { 30 | sig2 = log( 1 + v / ( e^2 ) ); 31 | mu = log( e ) - sig2 / 2; 32 | 33 | return( list( sigma_square = sig2 , mu = mu ) ); 34 | 35 | } -------------------------------------------------------------------------------- /R/LognormalParameters2Statistics.R: -------------------------------------------------------------------------------- 1 | #' @title Compute expectation, covariance, standard deviation and correlation for a lognormal distribution. 2 | #' 3 | #' @description Compute expectation, covariance, standard deviation and correlation for a lognormal distribution, as described in 4 | #' A. Meucci "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Mu : [vector] (N x 1) location parameter 7 | #' @param Sigma : [matrix] (N x N) scale parameter 8 | #' 9 | #' 10 | #' @return Exp : [vector] (N x 1) expectation 11 | #' @return Cov : [matrix] (N x N) covariance 12 | #' @return Std : [vector] (N x 1) standard deviation 13 | #' @return Corr : [matrix] (N x N) correlation 14 | #' 15 | #' @references 16 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 17 | #' "E 85 - Correlation in lognormal markets". 18 | #' 19 | #' See Meucci's script for "LognormalParam2Statistics.m" 20 | #' 21 | #' @author Xavier Valls \email{flamejat@@gmail.com} 22 | #' @export 23 | 24 | LognormalParam2Statistics = function( Mu, Sigma ) 25 | { 26 | 27 | Exp = exp( Mu + (1/2) * diag( Sigma ) ); 28 | Cov = exp( Mu + (1/2) * diag( Sigma ) ) %*% t( exp( Mu + (1/2) * diag( Sigma ) ) ) * ( exp( Sigma ) - 1 ); 29 | Std = sqrt( diag( Cov ) ); 30 | Corr = diag( 1 / Std ) %*% Cov %*% diag( 1 / Std ); 31 | 32 | return( list( Exp = Exp, Covariance = Cov, Standard_Deviation = Std, Correlation = Corr ) ); 33 | } -------------------------------------------------------------------------------- /R/MvnRnd.R: -------------------------------------------------------------------------------- 1 | #' @title Generate normal simulations whose sample moments match the population moments 2 | #' 3 | #' @description Generate normal simulations whose sample moments match the population moments, 4 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param M : [vector] (N x 1) expectation 7 | #' @param S : [matrix] (N x N) covariance matrix 8 | #' @param J : [scalar] number of draws (even number) 9 | #' 10 | #' @return X : [matrix] (J x N) of drawsF_U : [vector] (J x 1) PDF values 11 | #' 12 | #' @references 13 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 14 | #' "E 64 - Simulation of a multivariate normal random variable with matching moments". 15 | #' 16 | #' See Meucci's script for "MvnRnd.m". 17 | #' 18 | #' @author Xavier Valls \email{flamejat@@gmail.com} 19 | #' @export 20 | 21 | MvnRnd = function( M, S, J ) 22 | { 23 | if ( !require( "QZ" ) ) stop("QZ package installation required for this script"); 24 | 25 | N = length(M); 26 | 27 | # generate antithetic variables (mean = 0) 28 | Y = rmvnorm( J/2, matrix( 0, N ), S ); 29 | Y = rbind( Y, -Y ); 30 | 31 | # compute sample covariance: NOTE defined as "cov(Y,1)", not as "cov(Y)" 32 | S_ = ( dim(Y)[1] - 1 )/ dim(Y)[1] * cov( Y ); 33 | 34 | # solve Riccati equation using Schur method 35 | H = rbind( cbind( matrix( 0, N, N ), -S ), cbind( -S, matrix( 0, N, N ) ) ); 36 | 37 | U = ordqz( H, keyword = "lhp" )$Q; 38 | 39 | U_lu = U[ 1:N, 1:N ]; 40 | U_ld = U[ (N+1):nrow(U), 1:N ]; 41 | 42 | B = U_ld %*% solve( U_lu ); 43 | 44 | # affine transformation to match mean and covariances 45 | X = Y %*% B + kronecker( matrix( 1, J, 1 ), t( M ) ); 46 | 47 | return( X ); 48 | } -------------------------------------------------------------------------------- /R/NormalCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #' @title Computes the pdf of the copula of the normal distribution at the generic point u in the unit hypercube 2 | #' 3 | #' @description Computes the pdf of the copula of the normal distribution at the generic point u in the unit 4 | #' hypercube, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param u [vector] (J x 1) grade 7 | #' @param Mu [vector] (N x 1) mean 8 | #' @param Sigma [matrix] (N x N) covariance 9 | #' 10 | #' @return F_U [vector] (J x 1) PDF values 11 | #' 12 | #' @references 13 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 14 | #' "E 33 - Pdf of the normal copula". 15 | #' 16 | #' See Meucci's script for "NormalCopulaPdf.m" 17 | #' 18 | #' @author Xavier Valls \email{flamejat@@gmail.com} 19 | #' @export 20 | 21 | NormalCopulaPdf = function( u, Mu, Sigma ) 22 | { 23 | N = length( u ); 24 | s = sqrt( diag( Sigma )); 25 | 26 | x = qnorm( u, Mu, s ); 27 | 28 | Numerator = ( 2 * pi ) ^ ( -N / 2 ) * ( (det ( Sigma ) ) ^ ( -0.5 ) ) * exp( -0.5 * t(x - Mu) %*% mldivide( Sigma , ( x - Mu ))); 29 | 30 | fs = dnorm( x, Mu, s); 31 | 32 | Denominator = prod(fs); 33 | 34 | F_U = Numerator / Denominator; 35 | 36 | return ( F_U ); 37 | } -------------------------------------------------------------------------------- /R/PlotCompositionEfficientFrontier.R: -------------------------------------------------------------------------------- 1 | #' @title Plots the efficient frontier 2 | #' 3 | #' @description Plot the efficient frontier, as described in A. Meucci, 4 | #' "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param Portfolios : [matrix] (M x N) M portfolios of size N (weights) 7 | #' 8 | #' @references 9 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 10 | #' 11 | #' See Meucci's script for "PlotCompositionEfficientFrontier.m" 12 | #' 13 | #' @author Xavier Valls \email{flamejat@@gmail.com} 14 | #' @export 15 | 16 | PlotCompositionEfficientFrontier = function( Portfolios ) 17 | { 18 | dev.new(); 19 | 20 | xx = dim( Portfolios )[ 1 ]; 21 | N = dim( Portfolios )[ 2 ]; 22 | Data = t( apply( Portfolios, 1, cumsum ) ); 23 | 24 | plot( c(2000, 2000), xlim= c( 1, xx ), ylim = c( 0, max(Data) ), xlab = " Portfolio # risk propensity", ylab = "Portfolio composition" ); 25 | 26 | for( n in 1 : N ) 27 | { 28 | x = rbind( 1, matrix(1 : xx), xx ); 29 | y = rbind( 0, matrix( Data[ , N-n+1 ] ), 0 ); 30 | polygon( x, y, col = rgb( 0.9 - mod(n,3)*0.2, 0.9 - mod(n,3)*0.2, 0.9 - mod(n,3)*0.2) ); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /R/PlotDistributions.R: -------------------------------------------------------------------------------- 1 | #' Plot numerical and analytical prior and posterior distributions 2 | #' 3 | #' @param X a vector containing the dataset 4 | #' @param p a vector cotaining the prior probability values 5 | #' @param Mu a vector containing the prior means 6 | #' @param Sigma a vector containing the prior standard deviations 7 | #' @param p_ a vector containing the posterior probability values 8 | #' @param Mu_ a vector containing the posterior means 9 | #' @param Sigma_ a vector containing the posterior standard deviations 10 | #' 11 | #' @references 12 | #' A. Meucci, "Fully Flexible Views: Theory and Practice" \url{http://www.symmys.com/node/158} 13 | #' See Meucci script for "PlotDistributions.m" 14 | #' 15 | #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com} 16 | #' @export 17 | 18 | PlotDistributions = function( X , p , Mu , Sigma , p_ , Mu_ , Sigma_ ) 19 | { 20 | J = nrow( X ) 21 | N = ncol( X ) 22 | 23 | NBins = round( 10*log( J ) ) 24 | 25 | for ( n in 1:N ) 26 | { 27 | # set ranges 28 | xl = min( X[ , n ] ) 29 | xh = max( X[ , n ] ) 30 | x = as.matrix( seq( from=xl, to=xh, by=(xh-xl) / 100 ) ) 31 | 32 | # posterior numerical 33 | # h3 = pHist(X[ ,n] , p_ , NBins ) 34 | 35 | # posterior analytical 36 | y1 = dnorm( x , Mu_[n] , sqrt( Sigma_[n,n] ) ) 37 | h4 = plot( x , y1, type='l', col='red', xlab='', ylab='' ) 38 | 39 | # prior analytical 40 | par( new = TRUE ) 41 | y2 = dnorm( x , Mu[n] ,sqrt( Sigma[n,n] ) ) 42 | h2 = plot( x , y2, type='l', col='blue', xlab='', ylab='' ) 43 | 44 | # xlim( cbind( xl , xh ) ) 45 | legend( x = 1.5, y =0.4 , legend=c("analytical","prior"), lwd=c(0.2,0.2), lty=c(1,1), col=c("red", "blue") ) 46 | } 47 | } -------------------------------------------------------------------------------- /R/PlotVolVsCompositionEfficientFrontier.R: -------------------------------------------------------------------------------- 1 | #' Plot the efficient frontier in the plane of portfolio weights versus standard deviation, 2 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005. 3 | #' 4 | #' @param Portfolios : [matrix] (M x N) of portfolios weights 5 | #' @param vol : [vector] (M x 1) of volatilities 6 | #' 7 | #' @references 8 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 9 | #' See Meucci's script for "PlotVolVsCompositionEfficientFrontier.m" 10 | #' 11 | #' @author Xavier Valls \email{flamejat@@gmail.com} 12 | #' @export 13 | 14 | PlotVolVsCompositionEfficientFrontier = function( Portfolios, vol ) 15 | { 16 | 17 | colors = c( "cyan","white","magenta","green","black","red" ); 18 | numcolors = length(colors); 19 | 20 | dev.new(); 21 | xx = dim( Portfolios )[ 1 ]; 22 | N = dim( Portfolios )[ 2 ]; 23 | 24 | Data = t( apply( Portfolios, 1, cumsum ) ); 25 | plot(c(0,0), xlim= c( min(vol)*100, max(vol)*100), ylim = c(0, max(Data)), xlab = "Risk %", ylab = "Portfolio weights") ; 26 | 27 | for( n in 1 : N ) 28 | { 29 | x = rbind( 1, matrix( 1 : xx ), xx ); 30 | v = rbind( min(vol), vol, max(vol) ) * 100 31 | y = rbind( 0, matrix(Data[ , N-n+1 ]), 0 ); 32 | polygon( v, y, col = colors[ mod( n, numcolors ) + 1 ] ); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /R/ProjectionStudentT.R: -------------------------------------------------------------------------------- 1 | #' @title Perform the horizon projection of a Student t invariant 2 | #' 3 | #' @description Perform the horizon projection of a Student t invariant, as described in 4 | #' A. Meucci "Risk and Asset Allocation", Springer, 2005 5 | #' 6 | #' @param nu [scalar] degree of freedom 7 | #' @param s [scalar] scatter parameter 8 | #' @param m [scalar] location parameter 9 | #' @param T [scalar] multiple of the estimation period to the invesment horizon 10 | #' 11 | #' @return x_Hor [scalar] probabilities at horizon 12 | #' @return f_Hor [scalar] horizon discretized pdf (non-standarized) 13 | #' @return F_Hor [scalar] horizon discretized cdf (non-standarized) 14 | #' 15 | #' @references 16 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 17 | #' "E 141 - Fixed-income market: projection of Student t invariants". 18 | #' 19 | #' See Meucci's script for "ProjectionStudentT.m" 20 | #' 21 | #' @author Xavier Valls \email{flamejat@@gmail.com} 22 | #' @export 23 | 24 | ProjectionStudentT = function(nu, m, s, T) 25 | { 26 | # set up grid 27 | N = 2 ^ 14; # coarseness level 28 | a = -qnorm( 10^(-15), 0, sqrt( T ) ); 29 | h = 2 * a / N; 30 | Xi = seq(-a+h, a, h ); 31 | 32 | # discretized initial pdf (standardized) 33 | f = 1 / h * ( pt( Xi + h/2, nu ) - pt( Xi - h/2, nu ) ); 34 | f[ N ] = 1 / h *( pt(-a + h/2, nu ) - pt( -a, nu ) + pt( a, nu )- pt( a-h/2, nu ) ); 35 | 36 | # discretized characteristic function 37 | Phi = fft(f); 38 | 39 | # projection of discretized characteristic function 40 | Signs = ( -1 )^((0:(N-1)) * ( T - 1)); 41 | Phi_T = h ^ ( T - 1 ) * Signs * (Phi ^ T); 42 | 43 | # horizon discretized pdf (standardized) 44 | f_T = as.numeric( ifft( Phi_T ) ); 45 | 46 | # horizon discretized pdf and cdf (non-standardized) 47 | x_Hor = m * T + s * Xi; 48 | f_Hor = f_T / s; 49 | F_Hor = h * cumsum( f_Hor * s ); 50 | 51 | return( list( x = x_Hor, f = f_Hor, F = F_Hor ) ); 52 | 53 | } -------------------------------------------------------------------------------- /R/QuantileMixture.R: -------------------------------------------------------------------------------- 1 | #' @title Computes the quantile of a mixture distribution by linear interpolation/extrapolation of the cdf. 2 | #' 3 | #' @description Computes the quantile of a mixture distribution by linear interpolation/extrapolation of the cdf. The confidence 4 | #' level p can be vector. If this vector is uniformly distributed on [0,1] the sample Q is distributed as the mixture. 5 | #' Described in A. Meucci "Risk and Asset Allocation", Springer, 2005. 6 | #' 7 | #' @param p [scalar] in [0,1], probability 8 | #' @param a [scalar] in (0,1), mixing probability 9 | #' @param m_Y [scalar] mean of normal component 10 | #' @param s_Y [scalar] standard deviation of normal component 11 | #' @param m_Z [scalar] first parameters of the log-normal component 12 | #' @param s_Z [scalar] second parameter of the log-normal component 13 | #' 14 | #' @return Q [scalar] quantile 15 | #' 16 | #' @references 17 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 18 | #' "E 184 - Estimation of a quantile of a mixture I". 19 | #' 20 | #'See Meucci's script for "QuantileMixture.m" 21 | #' 22 | #' @author Xavier Valls \email{flamejat@@gmail.com} 23 | #' @export 24 | 25 | QuantileMixture = function( p, a, m_Y, s_Y, m_Z, s_Z ) 26 | { 27 | # compute first moment 28 | m = a * m_Y + (1 - a) * exp( m_Z + 0.5 * s_Z * s_Z); 29 | 30 | # compute second moment 31 | Ex2 = a * (m_Y^2 + s_Y^2) + (1 - a) * exp( 2 * m_Z + 2 * s_Z * s_Z); 32 | s = sqrt( Ex2 - m * m ); 33 | 34 | # compute cdf on suitable range 35 | X = m + 6 * s * seq( -1, 1, 0.001 ); 36 | F = a * pnorm( X, m_Y, s_Y) + (1 - a) * plnorm(X, m_Z, s_Z); 37 | X = X[!duplicated(F)]; 38 | F = unique(F); 39 | 40 | # compute quantile by interpolation 41 | Q = interp1( F, X, p, method = "linear"); 42 | 43 | return( Q ); 44 | 45 | } -------------------------------------------------------------------------------- /R/StudentTCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #' @title Pdf of the copula of the Student t distribution at the generic point u in the unit hypercube 2 | #' 3 | #' @description Pdf of the copula of the Student t distribution at the generic point u in the unit hypercube, 4 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param u : [vector] (J x 1) grade 7 | #' @param nu : [numerical] degrees of freedom 8 | #' @param Mu : [vector] (N x 1) mean 9 | #' @param Sigma : [matrix] (N x N) scatter 10 | #' 11 | #' 12 | #' @return F_U : [vector] (J x 1) PDF values 13 | #' 14 | #' @references 15 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 16 | #' "E 88 - Copula vs. Correlation". 17 | #' 18 | #' See Meucci's script for "StudentTCopulaPdf.m" 19 | #' 20 | #' @author Xavier Valls \email{flamejat@@gmail.com} 21 | #' @export 22 | 23 | StudentTCopulaPdf = function( u, nu, Mu, Sigma ) 24 | { 25 | N = length( u ); 26 | s = sqrt( diag( Sigma )); 27 | 28 | x = Mu + s * qt( u, nu); 29 | 30 | z2 = t(x - Mu) %*% mldivide( Sigma, (x - Mu)); #z2 = t(x - Mu) %*% inv(Sigma) * (x-Mu); 31 | K = ( nu * pi )^( -N / 2 ) * gamma( ( nu + N ) / 2 ) / gamma( nu / 2 ) * ( ( det( Sigma ) )^( -0.5 )); 32 | Numerator = K * (1 + z2 / nu)^(-(nu + N) / 2); 33 | 34 | 35 | fs = dt((x - Mu) / s , nu); 36 | 37 | Denominator = prod(fs); 38 | 39 | F_U = Numerator / Denominator; 40 | 41 | return ( F_U ); 42 | } 43 | -------------------------------------------------------------------------------- /R/logToArithmeticCovariance.R: -------------------------------------------------------------------------------- 1 | #' Generate arithmetric returns and arithmetric covariance matrix given a distribution of log returns 2 | #' 3 | #' @param mu a numeric containing the expected logarithmic returns for each security 4 | #' @param sigma a covariance matrix of log returns 5 | #' 6 | #' @return a list containing two elements: 7 | #' @return arithmeticMean a numeric containing the mean arithmetic returns 8 | #' @return arithmeticCovariance a variance-covariance matrix in simple arithmetic return terms 9 | #' \deqn{ M_{ \tau }^{i} = e^{ \mu ^{\tau} _{i} + \frac{1}{2} \Sigma^{ii} _{\tau} }, 10 | #' \\ S^{ij} = e^{ \mu ^{\tau} _{i} + \mu ^{\tau} _{j} + \frac{1}{2} \big(\Sigma^{ii} _{\tau} + \Sigma^{jj} _{\tau}\big) } \big(e^{\Sigma^{ij} _{\tau}} - 1\big) } 11 | #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com} 12 | #' @export 13 | #' @references 14 | #' # formula (7) and (8) on page 5 of Appendix to "Meucci - A Common Pitfall in Mean-Variance Estimation" 15 | #' \url{http://www.wilmott.com/pdfs/011119_meucci.pdf} 16 | #' @export 17 | 18 | linreturn <- function( mu , sigma ) 19 | { 20 | # each element of M represents the linear returns for the corresponding log-returns element in mu 21 | M <- exp( mu + ( diag( sigma ) / 2 ) ) - 1 22 | 23 | # prep for formula (8) 24 | x1 <- outer( mu, mu , "+" ) 25 | x2 <- outer( diag( sigma ) , diag( sigma ) , "+" ) / 2 26 | 27 | # formula (8) 28 | S <- exp( x1 + x2 ) * ( exp( sigma ) - 1 ) 29 | list( mean = M , vcov = S ) 30 | } 31 | -------------------------------------------------------------------------------- /R/pHistPriorPosterior.R: -------------------------------------------------------------------------------- 1 | #' @title Plot prior and posterior distributions. 2 | #' 3 | #' @description Plot prior and posterior distributions, as described in A. Meucci, 4 | #' "Risk and Asset Allocation", Springer, 2005. 5 | #' 6 | #' @param X : [matrix] (J x N) simulations 7 | #' @param p : [vector] (J x 1) prior probabilities 8 | #' @param p_ : [vector] (J x 1) posterior probabilities 9 | #' 10 | #' @references 11 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}. 12 | #' 13 | #' See Meucci's script for "pHistPriorPosterior.m" 14 | #' 15 | #' @author Xavier Valls \email{flamejat@@gmail.com} 16 | #' @export 17 | 18 | pHistPriorPosterior = function( X, p, p_) 19 | { 20 | X = as.matrix(X); 21 | J = dim(X)[1]; 22 | N = dim(X)[2]; 23 | NBins = round(10 * log(J)); 24 | 25 | for( n in 1 : N ) 26 | { 27 | dev.new(); 28 | 29 | # set ranges 30 | xl = min(X[ , n]); 31 | xh = max(X[ , n]); 32 | 33 | par( mfrow = c( 2, 1 ) ); 34 | 35 | # prior numerical 36 | pHist( X[ , n ], p, NBins); 37 | # xlim([xl, xh]); 38 | # y1 = ylim(); 39 | # title('prior'); 40 | 41 | # posterior numerical 42 | pHist( X[ , n ], p_, NBins); 43 | # xlim([xl, xh]); 44 | # y2 = ylim(); 45 | # ylim([min(y1(1), y2(1)), max(y1(2), y2(2))]); 46 | # title('posterior'); 47 | 48 | # subplot(2, 1, 1); 49 | # ylim([min(y1(1), y2(1)), max(y1(2), y2(2))]); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | This package would not be possible without the work by Attilio Meucci not only 2 | to do the research, but to publish his code in an open format for others to use. 3 | 4 | Attilio has very graciously collaborated with the R port of his code, and supported 5 | the work and understanding that goes with any port. It is our hope that this 6 | package will be incorporated into later published versions of his work, so that 7 | language choice is not a restricting factor in using his research for teaching or 8 | live portfolios. -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Xavi's notes: 2 | 3 | * Matlab package doesn't seem to be necessary, find substitutes for its functions where possible 4 | * There are some problems with charts and what can be done with base graphics: 5 | - Maybe using ggplot2 instead of base graphics can provide more flexibility. 6 | - How to change the layout after the plot like in MATLAB to change name, limits... (look at pHistPriorPosterior code for an example ) 7 | - How to draw a histogram passing the x,y coordinates using the barplot function 8 | ... 9 | * All the scripts from the papers need to be revised, some don't even work. 10 | * Maybe there are some packages that aren't needed anymore. Find out which of them. 11 | * Documentation for papers and functions from Ram - Manan. 12 | * Look for the TODOs from Ram or Manan. 13 | * Confirm every datafile is different from the others. 14 | * Change coding style to one more R alike 15 | * Still 2 scripts left from the book: S_MeanVarianceCallsRobust from chapter 9 and S_OptionReplication from chapter 6 16 | * Improve documentation for every script from the book: 17 | - write down the equations 18 | * Not Sure if EntropyProg returns what it should with empty matrices as arguments for the constraints 19 | * Write text version of the formulas in the documentation 20 | -------------------------------------------------------------------------------- /data/bondAttribution.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/bondAttribution.rda -------------------------------------------------------------------------------- /data/butterfliesAnalytics.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/butterfliesAnalytics.rda -------------------------------------------------------------------------------- /data/covNRets.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/covNRets.rda -------------------------------------------------------------------------------- /data/db.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/db.rda -------------------------------------------------------------------------------- /data/dbFFP.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/dbFFP.rda -------------------------------------------------------------------------------- /data/derivatives.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/derivatives.rda -------------------------------------------------------------------------------- /data/equities.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/equities.rda -------------------------------------------------------------------------------- /data/fILMR.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/fILMR.rda -------------------------------------------------------------------------------- /data/fX.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/fX.rda -------------------------------------------------------------------------------- /data/factorsDistribution.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/factorsDistribution.rda -------------------------------------------------------------------------------- /data/fixedIncome.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/fixedIncome.rda -------------------------------------------------------------------------------- /data/freaqEst.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/freaqEst.rda -------------------------------------------------------------------------------- /data/highYieldIndices.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/highYieldIndices.rda -------------------------------------------------------------------------------- /data/implVol.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/implVol.rda -------------------------------------------------------------------------------- /data/linearModel.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/linearModel.rda -------------------------------------------------------------------------------- /data/returnsDistribution.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/returnsDistribution.rda -------------------------------------------------------------------------------- /data/sectorsSnP500.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/sectorsSnP500.rda -------------------------------------------------------------------------------- /data/sectorsTS.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/sectorsTS.rda -------------------------------------------------------------------------------- /data/securitiesIndustryClassification.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/securitiesIndustryClassification.rda -------------------------------------------------------------------------------- /data/securitiesTS.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/securitiesTS.rda -------------------------------------------------------------------------------- /data/stockSeries.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/stockSeries.rda -------------------------------------------------------------------------------- /data/swap2y4y.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/swap2y4y.rda -------------------------------------------------------------------------------- /data/swapParRates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/swapParRates.rda -------------------------------------------------------------------------------- /data/swaps.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/swaps.rda -------------------------------------------------------------------------------- /data/timeSeries.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/timeSeries.rda -------------------------------------------------------------------------------- /data/usSwapRates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/Meucci/35f4f506ac6fd10596e6384e543ea443801e25e9/data/usSwapRates.rda -------------------------------------------------------------------------------- /demo/DetectOutliersviaMVE.R: -------------------------------------------------------------------------------- 1 | # Example 1: Two-asset example with -.9 correlation 2 | # generate covariance matrix to sample "good returns" 3 | sig = matrix( c( 1 , 1 ) , nrow = 1 ); r = -.9 4 | correlationMatrix = rbind( cbind( 1 , r ) , cbind( r , 1 ) ) # generate 2x2 correlation matrix 5 | covarianceMatrix = diag(sig) * correlationMatrix * diag(sig) ; rm( correlationMatrix ) ; rm( sig ) ; rm( r ) # convert to covariance matrix 6 | 7 | # co-mingle sample from good covariance matrix with bad outliers and shuffle rows 8 | corruptSample = NoisyObservations( 50 , 7 , covarianceMatrix , shuffle = TRUE ) # returns 50 good samples and 7 bad samples 9 | 10 | # identify/detect number of outliers 11 | result = DetectOutliersViaMVE( corruptSample ) 12 | 13 | # remove outliers 14 | cleanSample = corruptSample[ c(-16, -57, -21, -39, -14, -52, -26 , -37 ), ] 15 | DetectOutliersViaMVE( cleanSample ) 16 | result 17 | 18 | # Example 2: Multi-asset example 19 | # generate covariance matrix to sample "good returns" 20 | library( Matrix ) 21 | numberOfStocks = 100 22 | rm( result ) ; rm( covarianceMatrix ) ; rm( corruptSample ) 23 | covarianceMatrix = matrix( rnorm( numberOfStocks^2 , 0 , .1 ) , nrow = numberOfStocks , ncol = numberOfStocks ) 24 | covarianceMatrix = ( covarianceMatrix + t( covarianceMatrix ) ) / 2 25 | covarianceMatrix = nearPD( covarianceMatrix , corr = FALSE )$mat 26 | covarianceMatrix = as.matrix(covarianceMatrix) 27 | 28 | # co-mingle sample from good covariance matrix with bad outliers and shuffle rows 29 | corruptSample = NoisyObservations( 150 , 7 , covarianceMatrix , shuffle = FALSE ) 30 | 31 | # identify/detect number of outliers 32 | result = DetectOutliersViaMVE( corruptSample ) 33 | result 34 | 35 | # print the index of the observation that is largest outlier 36 | RejectOutlier( corruptSample )$rejected -------------------------------------------------------------------------------- /demo/MeanDiversificationFrontier.R: -------------------------------------------------------------------------------- 1 | # This script computes the mean-diversification efficient frontier 2 | # see A. Meucci - "Managing Diversification", Risk Magazine, June 2009 3 | # available at www.ssrn.com 4 | 5 | # Code by A. Meucci. This version March 2009. 6 | # Last version available at MATLAB central as "Managing Diversification" 7 | 8 | # inputs 9 | # upload returns covariance and expectations 10 | 11 | # define benchmark and portfolio weights 12 | N = nrow( Mu ) 13 | w_0 = rep( 1, N ) / N 14 | 15 | # define constraints 16 | # long-short constraints... 17 | Constr = list() 18 | Constr$A = rbind( diag( N ), -diag( N ) ) 19 | Constr$b = rbind( as.matrix( rep( 1, N ) ), as.matrix( rep( 0.1, N ) ) ) 20 | Constr$Aeq = t( as.matrix( rep( 1 , N ) ) ) # budget constraint... 21 | Constr$beq = as.matrix( 1 ) 22 | 23 | # mean-diversification analysis and frontier 24 | EntropyFrontier = MeanTCEntropyFrontier( S , Mu , w_b , w_0 , Constr ) 25 | 26 | # mean-diversification of current allocation 27 | m = t( Mu ) %*% ( w_0 - w_b ) 28 | s = sqrt( t( w_0 - w_b ) %*% S %*% ( w_0 - w_b ) ) 29 | GenPCResult = GenPCBasis( S , emptyMatrix ) 30 | v_tilde = G %*% ( w_0 - w_b ) 31 | TE_contr = ( v_tilde * v_tilde ) / s 32 | R_2 = max( 10^(-10) , TE_contr/sum(TE_contr) ) 33 | Ne = exp( -t( R_2 ) %*% log( R_2 ) ) -------------------------------------------------------------------------------- /demo/S_AnalyzeLognormalCorrelation.R: -------------------------------------------------------------------------------- 1 | #' This script considers a bivariate lognormal market and display the correlation and the condition number of the 2 | #' covariance matrix, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 85 - Correlation in lognormal markets". 7 | #' 8 | #' See Meucci's script for "S_AnalyzeLognormalCorrelation.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | 14 | ########################################################################################################################################### 15 | ### Set input parameters 16 | Mu = rbind( 0, 0 ) 17 | s = c( 1, 1 ); 18 | rhos = seq( -0.99, 0.99, 0.01 ); 19 | nrhos = length( rhos ); 20 | Cs = array( NaN, nrhos ); 21 | CRs = array( NaN, nrhos ); 22 | 23 | ########################################################################################################################################### 24 | ### Iterate of rho values and compute the correlation and condition number 25 | 26 | for ( n in 1 : nrhos ) 27 | { 28 | rho = rhos[ n ] ; 29 | Sigma = rbind( c(s[1]^2, rho * s[1] * s[2]), c(rho * s[1] * s[2], s[2]^2) ); 30 | 31 | S = LognormalParam2Statistics(Mu, Sigma); 32 | 33 | Lambda = eigen(S$Covariance); 34 | 35 | Cs[ n ] = S$Correlation[1, 2]; 36 | CRs[ n ] = min(Lambda$values) / max(Lambda$values); 37 | } 38 | 39 | ########################################################################################################################################### 40 | ### Display the results 41 | 42 | par( mfrow = c( 2, 1) ); 43 | plot( rhos, Cs, xlab = "r", ylab = "correlation", type ="l" ); 44 | plot( rhos, CRs, xlab = "r", ylab = "condition ratio", type ="l" ); 45 | -------------------------------------------------------------------------------- /demo/S_AnalyzeNormalCorrelation.R: -------------------------------------------------------------------------------- 1 | #' This script considers a bivariate normal market and display the correlation and the condition number of the 2 | #' covariance matrix, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 84 - Correlation in normal markets". 7 | #' 8 | #' See Meucci's script for "S_AnalyzeNormalCorrelation.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | ################################################################################################################### 14 | ### Set input parameters 15 | 16 | Mu = rbind( 0, 0 ) 17 | s = c( 1, 1 ); 18 | 19 | rhos = seq( -0.99, 0.99, 0.01 ); 20 | nrhos = length( rhos ); 21 | 22 | Cs = array( NaN, nrhos ); 23 | CRs = array( NaN, nrhos ); 24 | 25 | 26 | ################################################################################################################### 27 | ### Iterate of rho values and compute the correlation and condition numberfor ( n in 1 : nrhos ) 28 | 29 | for ( n in 1 : nrhos ) 30 | { 31 | rho = rhos[ n ] ; 32 | Sigma = rbind( c(s[1]^2, rho * s[1] * s[2]), c(rho * s[1] * s[2], s[2]^2) ); 33 | 34 | Covariance = Sigma; 35 | Standard_Deviation = sqrt( diag( Covariance ) ); 36 | Correlation = diag( 1 / Standard_Deviation ) %*% Covariance %*% diag( 1 / Standard_Deviation ); 37 | 38 | Lambda = eigen( Covariance ); 39 | 40 | Cs[n] = Correlation[ 1, 2 ]; 41 | CRs[n] = min( Lambda$values ) / max( Lambda$values ); 42 | } 43 | 44 | ################################################################################################################### 45 | ### Display the results 46 | par( mfrow = c( 2, 1) ); 47 | plot( rhos, Cs, xlab = "r", ylab = "correlation", type ="l" ); 48 | plot( rhos, CRs, xlab = "r", ylab = "condition ratio", type ="l" ); 49 | -------------------------------------------------------------------------------- /demo/S_AutocorrelatedProcess.R: -------------------------------------------------------------------------------- 1 | #' This script simulates a Ornstein-Uhlenbeck AR(1) process, as described in A. Meucci, 2 | #' "Risk and Asset Allocation", Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 133 - Simulation of a Ornstein-Uhlenbeck process". 7 | #' 8 | #' See Meucci's script for "S_AutocorrelatedProcess.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Input parameters 14 | 15 | theta = 0.1; # reversion speed 16 | m = 0.05; # long term mean 17 | sigma = 0.01; # volatility 18 | T = 10^4; # number of steps 19 | tau = 0.01; # discrete time interval 20 | 21 | ################################################################################################################## 22 | ### Determine parameters 23 | var = sigma^2 / 2 / theta * ( 1 - exp( -2 * theta * tau ) ); 24 | sd = sqrt(var); 25 | eps = rnorm( T, 0, sd ); 26 | 27 | x = matrix( NaN, T, 1); 28 | x[ 1 ] = 0; 29 | 30 | for( t in 1 : (T - 1) ) 31 | { 32 | x[ t + 1 ] = m + exp( -theta * tau ) * ( x[ t ] - m ) + eps[ t ]; 33 | } 34 | 35 | dev.new(); 36 | plot( x, type="l", main = "AR(1) process vs. time" ); 37 | -------------------------------------------------------------------------------- /demo/S_BlackLittermanBasic.R: -------------------------------------------------------------------------------- 1 | #' This script describes to basic market-based Black-Litterman approach in particular: 2 | #' - full confidence = conditional 3 | #' - no confidence = reference model 4 | #' Described in A. Meucci, "Risk and Asset Allocation", 5 | #' Springer, 2005, Chapter 9. 6 | #' 7 | #' @references 8 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 9 | #' "E 303 - Black-Litterman and beyond II". 10 | #' 11 | #' See Meucci's script for "S_BlackLittermanBasic.m" and "E 302 - Black-Litterman and beyond I" 12 | #' 13 | #' @author Xavier Valls \email{flamejat@@gmail.com} 14 | 15 | ################################################################################################################## 16 | ### Load inputs 17 | data("covNRets"); 18 | 19 | ################################################################################################################## 20 | ### Compute efficient frontier 21 | NumPortf = 40; # number of MV-efficient portfolios 22 | L2L = Log2Lin( covNRets$Mu, covNRets$Sigma ); 23 | EFR = EfficientFrontierReturns( NumPortf, L2L$S, L2L$M ); 24 | PlotCompositionEfficientFrontier( EFR$Composition ); 25 | 26 | ################################################################################################################## 27 | ### Modify expected returns the Black-Litterman way and compute new efficient frontier 28 | P = cbind( 1, 0, 0, 0, 0, -1 ); # pick matrix 29 | Omega = P %*% covNRets$Sigma %*% t( P ); 30 | Views = sqrt( diag( Omega ) ); # views value 31 | 32 | B = BlackLittermanFormula( covNRets$Mu, covNRets$Sigma, P, Views, Omega ); 33 | 34 | L2LBL = Log2Lin( B$BLMu, B$BLSigma ); 35 | EFRBL = EfficientFrontierReturns( NumPortf, L2LBL$S, L2LBL$M ); 36 | PlotCompositionEfficientFrontier( EFRBL$Composition ); 37 | -------------------------------------------------------------------------------- /demo/S_CheckDiagonalization.R: -------------------------------------------------------------------------------- 1 | # This script verifies the correctness of the eigenvalue-eigenvector representation in terms of real matrices 2 | # for the transition matrix of an OU process discussed in A. Meucci (2009) 3 | # "Review of Statistical Arbitrage, Cointegration, and Multivariate Ornstein-Uhlenbeck" 4 | # available at ssrn.com 5 | 6 | # Code by A. Meucci, April 2009 7 | # Most recent version available at www.symmys.com > Teaching > MATLAB 8 | 9 | N = 5 10 | Theta = matrix( runif( N^2 ), 5, byrow = T ) 11 | 12 | tmp = eigen( Theta ) 13 | B = tmp$vectors 14 | L = tmp$values 15 | 16 | A = Re( B ) - Im( B ) 17 | 18 | Index_j = as.matrix( which( Im ( L ) != 0 ) ) 19 | L = diag( L ) 20 | 21 | G = L 22 | for ( s in c( seq( from = 1, to = length( Index_j ), by = 2 ) ) ) 23 | { 24 | G[ Index_j[ s : (s+1) ] , Index_j[ s : (s+1) ] ] = rbind( c( 1 , 0 ), c( 0 , 1 ) ) * Re( L[ Index_j[s],Index_j[s] ] ) + 25 | rbind( c( 0 , 1 ), c( -1 , 0 ) ) * Im( L [ Index_j[s] , Index_j[s] ] ) 26 | } 27 | Theta_ = A %*% G %*% solve( A ) 28 | -------------------------------------------------------------------------------- /demo/S_CornishFisher.R: -------------------------------------------------------------------------------- 1 | #'This script compares the Cornish-Fisher estimate of the VaR with the true analytical VaR under the lognormal 2 | #'assumptions as described in A. Meucci,"Risk and Asset Allocation", Springer, 2005, Chapter 5. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 223 - Cornish-Fisher approximation of the Value-at-Risk". 7 | #' 8 | #' See Meucci's script for "S_CornishFisher.m" 9 | # 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################### 13 | ### Inputs 14 | mu = 0.05; 15 | sig = 0.05; # NB: change here and see the impact of approximation 16 | 17 | ################################################################################################################### 18 | ### Process data 19 | E_X = exp( mu + sig ^ 2 / 2 ); 20 | Sd_X = exp( mu + sig ^ 2 / 2 ) * sqrt( exp( sig ^ 2 ) - 1 ); 21 | Sk_X = sqrt( exp( sig ^ 2 ) - 1 ) * ( exp( sig ^ 2 ) + 2 ); 22 | 23 | c = seq(0.001, 0.999, 0.001 ); 24 | z = qnorm( c ); 25 | 26 | Q_CF = E_X + Sd_X * ( z + Sk_X / 6 * ( z ^ 2 - 1 ) ); 27 | Q_true = qlnorm( c,mu,sig ); 28 | 29 | x = Q_true; 30 | f = dlnorm( x, mu, sig ); 31 | 32 | ################################################################################################################### 33 | ### Plots 34 | dev.new(); 35 | plot( x, f, type= "l", main = "pdf" ); 36 | 37 | dev.new(); 38 | plot( c, Q_true, type = "l", col = "red", main = "quantile" ); 39 | lines( c, Q_CF ); 40 | legend( "topleft", 1.9, c( "true", "Cornish-Fisher approx" ), col = c( "black","red" ), 41 | lty=1, bg = "gray90" ); 42 | -------------------------------------------------------------------------------- /demo/S_DeterministicEvolution.R: -------------------------------------------------------------------------------- 1 | # This script animates the evolution of the determinstic component of an OU process 2 | # see A. Meucci (2009) 3 | # "Review of Statistical Arbitrage, Cointegration, and Multivariate Ornstein-Uhlenbeck" 4 | # available at ssrn.com 5 | 6 | # Code by A. Meucci, April 2009 7 | # Most recent version available at www.symmys.com > Teaching > MATLAB 8 | 9 | # input parameters of multivariate OU process 10 | K = 1 11 | J = 1 12 | 13 | x0 = rep( 1, K + 2*J ) 14 | 15 | Mu = 0 * matrix( runif(K + 2*J), ncol = 1 ) 16 | 17 | A = rbind( c(1,0,0), c(0,1,0), c(0,0,1) ) 18 | 19 | ls = -10 20 | gs = 10 21 | os = 100 22 | 23 | ts_0 = .001 * as.matrix( seq( from = 0, to = 300, by = 1 ) ) 24 | 25 | # process inputs 26 | Gamma = diag( ls, nrow = length( ls ) ) 27 | for( j in 1:J ) 28 | { 29 | G = rbind( cbind( gs[j], os[j] ), cbind( -os[j], gs[j] ) ) 30 | Gamma = as.matrix( bdiag( Gamma , G ) ) 31 | } 32 | 33 | Theta = A %*% Gamma %*% solve( A ) 34 | 35 | # process dynamics 36 | S = 0 * matrix( runif( ( K + 2*J )^2 ), nrow = K + 2*J, byrow = T ) 37 | Sigma = S %*% t( S ) 38 | X_t = matrix(0, nrow = nrow( Theta ), ncol = length( ts_0 ) ) 39 | for( j in 1 : length( ts_0 ) ) 40 | { 41 | t = ts_0[ j ] 42 | X_t[ , j ] = OUstep( t( x0 ) , t , Mu , Theta , Sigma )$X_t 43 | } 44 | 45 | # plots 46 | plot( ts_0 , X_t[ 1 , ] ) 47 | plot( ts_0 , X_t[ 2 , ] ) 48 | plot( ts_0 , X_t[ 3 , ] ) 49 | 50 | # t = 0:pi/50:10*pi; 51 | # AnimateTrajectory(X_t(1,:),X_t(2,:),X_t(3,:)) 52 | -------------------------------------------------------------------------------- /demo/S_DisplayLognormalCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #' This script displays the pdf of the copula of a lognormal distribution, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 36 - Pdf of the lognormal copula". 7 | #' 8 | #' See Meucci's script for "S_DisplayLognormalCopulaPdf.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | ############################################################################################################# 14 | ### Input parameters 15 | Mu = rbind( 100.0, -30.0 ); 16 | r = 0.8; 17 | sigmas = rbind( 1000, 0.01 ); 18 | nu = 100; 19 | Sigma = diag( c( sigmas ) ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( c( sigmas ) ); 20 | 21 | ############################################################################################################# 22 | ### Grid 23 | GridSide1 = seq( 0.05, 0.95, 0.05 ); 24 | GridSide2 = GridSide1; 25 | nMesh = length(GridSide1); 26 | 27 | ############################################################################################################# 28 | ### Compute pdf of copula 29 | 30 | f_U = matrix( NaN, nMesh, nMesh); 31 | 32 | for ( j in 1 : nMesh ) 33 | { 34 | for ( k in 1 : nMesh) 35 | { 36 | u = c( GridSide1[ j ], GridSide2[ k ] ); 37 | f_U[ j, k ] = LognormalCopulaPdf(u, Mu, Sigma); 38 | } 39 | } 40 | 41 | #mesh representation 42 | 43 | persp( GridSide1, GridSide2, f_U, 44 | theta = 7 * 45, phi = 30, expand=0.6, col='lightblue', shade=0.75, ltheta=120, 45 | ticktype='detailed', xlab = "U_1", ylab = "U_2", zlab = "copula pdf" ); 46 | -------------------------------------------------------------------------------- /demo/S_DisplayNormalCopulaCdf.R: -------------------------------------------------------------------------------- 1 | #' This script displays the cdf of the copula of a normal distribution, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 35 - Cdf of the normal copula". 7 | #' 8 | #' See Meucci's script for "S_DisplayNormalCopulaCdf.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | ############################################################################################################# 14 | ### Input parameters 15 | Mu = c( 0, 0 ); 16 | r = -0.999; 17 | sigmas = c(1, 1 ); 18 | Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas ); 19 | 20 | ############################################################################################################# 21 | ### Grid 22 | GridSide1 = seq( 0.05, 0.95, 0.05 ); 23 | GridSide2 = GridSide1; 24 | nMesh = length(GridSide1); 25 | 26 | ############################################################################################################# 27 | ### Compute cdf of copula 28 | 29 | F_U = matrix( NaN, nMesh, nMesh); 30 | 31 | for ( j in 1 : nMesh ) 32 | { 33 | for ( k in 1 : nMesh) 34 | { 35 | u = c( GridSide1[ j ], GridSide2[ k ] ); 36 | x= qnorm( u, Mu, sigmas ); 37 | F_U[ j, k ] = pmvnorm( lower = -Inf, upper = x, mean = Mu, corr = Sigma ); 38 | } 39 | } 40 | 41 | #mesh representation 42 | 43 | persp( GridSide1, GridSide2, F_U, 44 | theta = 7 * 45, phi = 30, expand=0.6, col='lightblue', shade=0.75, ltheta=120, 45 | ticktype='detailed', xlab = "U_1", ylab = "U_2", zlab = "copula cdf" ); -------------------------------------------------------------------------------- /demo/S_DisplayNormalCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #' This script displays the pdf of the copula of a normal distribution, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 33 - Pdf of the normal copula". 7 | #' 8 | #' @author Xavier Valls \email{flamejat@@gmail.com} 9 | #' 10 | 11 | ############################################################################################################# 12 | ### input parameters 13 | Mu = rbind( 1, -1 ); 14 | r = 0.7; 15 | sigmas = c( 1, 1 ); 16 | Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas ); 17 | 18 | ############################################################################################################# 19 | ### Grid 20 | GridSide1 = seq( 0.05, 0.95, 0.05 ); 21 | GridSide2 = GridSide1; 22 | nMesh = length(GridSide1); 23 | 24 | ############################################################################################################# 25 | ### Compute pdf of copula 26 | 27 | f_U = matrix( NaN, nMesh, nMesh); 28 | 29 | for ( j in 1 : nMesh ) 30 | { 31 | for ( k in 1 : nMesh) 32 | { 33 | u = c( GridSide1[ j ], GridSide2[ k ] ); 34 | f_U[ j, k ] = NormalCopulaPdf(u, Mu, Sigma); 35 | } 36 | } 37 | 38 | #mesh representation 39 | 40 | persp( GridSide1, GridSide2, f_U, 41 | theta = 7 * 45, phi = 30, expand=0.6, col='lightblue', shade=0.75, ltheta=120, 42 | ticktype='detailed', xlab = "U_1", ylab = "U_2", zlab = "copula pdf" ); 43 | -------------------------------------------------------------------------------- /demo/S_DisplayStudentTCopulaPdf.R: -------------------------------------------------------------------------------- 1 | #'This script displays the pdf of the copula of a Student t distribution, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 88 - Copula vs. Correlation". 7 | #' 8 | #' See Meucci's script for "S_DisplayStudentTCopulaPdf.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | ############################################################################################################# 14 | ### input parameters 15 | 16 | Mu = rbind( 0, 0 ); 17 | r = 0.5; 18 | sigmas = c( 1, 2 ); 19 | Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas ); 20 | #nu = 1; Sigma(1,2) = 0; Sigma(2,1) = 0; 21 | nu = 200; 22 | 23 | ############################################################################################################# 24 | ### Grid 25 | GridSide1 = seq( 0.05, 0.95, 0.05 ); 26 | GridSide2 = GridSide1; 27 | nMesh = length(GridSide1); 28 | 29 | ############################################################################################################# 30 | ### Compute pdf of copula 31 | 32 | f_U = matrix( NaN, nMesh, nMesh); 33 | 34 | for ( j in 1 : nMesh ) 35 | { 36 | for ( k in 1 : nMesh) 37 | { 38 | u = c( GridSide1[ j ], GridSide2[ k ] ); 39 | f_U[ j, k ] = StudentTCopulaPdf( u, nu, Mu, Sigma ); 40 | } 41 | } 42 | 43 | #mesh representation 44 | 45 | persp( GridSide1, GridSide2, f_U, 46 | theta = 7 * 45, phi = 30, expand=0.6, col='lightblue', shade=0.75, ltheta=120, 47 | ticktype='detailed', xlab = "U_1", ylab = "U_2", zlab = "copula pdf" ); 48 | -------------------------------------------------------------------------------- /demo/S_EntropyView.R: -------------------------------------------------------------------------------- 1 | #' This script illustrates the Entropy Pooling approach, as described in A. Meucci, "Risk and Asset Allocation", 2 | #' Springer, 2005, Chapter 9. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 304 - Entropy pooling". 7 | #' 8 | #' See Meucci's script for "S_EntropyView.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Market simulations 14 | nSim = 100000; 15 | B = ( runif( nSim ) < 0.5); 16 | X = B * rnorm( nSim, -1, 1 ) + ( 1 - B ) * rnorm( nSim, 1, 1 ); 17 | 18 | ################################################################################################################## 19 | ### View 20 | # specify view E{X} = 0.5 and constraint 1'*p = 1. 21 | p_prior = matrix( 1, nSim, 1) / nSim; 22 | Aeq = rbind( X, matrix( 1, 1, nSim ) ); 23 | beq = rbind( 0.5, 1 ); 24 | 25 | ################################################################################################################## 26 | ### Posterior market distribution using the Entropy Pooling approach 27 | #Using package's EntropyProg instead of Books EntropyMinimization (Same function, different names) 28 | p_post = EntropyProg( p_prior, Aeq = Aeq, beq = beq)$p; 29 | pHistPriorPosterior(X,p_prior, p_post); 30 | fprintf('prior sample mean = #f\n', mean(X)); 31 | fprintf('posterior sample mean = #f\n', X' * p_post); 32 | 33 | -------------------------------------------------------------------------------- /demo/S_EquitiesInvariants.R: -------------------------------------------------------------------------------- 1 | #' This file performs the quest for invariance in the stock market, as described in 2 | #' A. Meucci "Risk and Asset Allocation", Springer, 2005, chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 135 - Equity market: quest for invariance". 7 | #' 8 | #' See Meucci's script for "S_EquitiesInvariants.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Load daily stock prices from the utility sector in the S&P 500 14 | data("equities"); 15 | 16 | ################################################################################################################## 17 | ### Pick one stock from database 18 | Stock_Index = 20; 19 | P = Equities$Prices[ 632 : nrow( Equities$Prices ), Stock_Index ]; # select data after 1/8 rule 20 | 21 | ################################################################################################################## 22 | ### Quest for invariance 23 | # first invariant 24 | X = P[ -1 ] / P[ -length( P )]; 25 | PerformIidAnalysis( 1 : length( X ), X, 'Analysis for X' ); 26 | 27 | # second invariant 28 | Y = P[ -1 ] / P[ -length( P )]; 29 | PerformIidAnalysis(1 : length( Y ), Y, 'Analysis for Y' ); 30 | 31 | # third invariant 32 | Z = X ^ 2; 33 | PerformIidAnalysis( 1 : length(Z), Z, 'Analysis for Z' ); 34 | 35 | # fourth invariant 36 | W = P[ 3 : length( P ) ] - 2 * P[ 2: ( length( P ) -1 ) ] + P[ 1 : ( length( P ) -2 ) ]; 37 | PerformIidAnalysis( 1 : length( W ), W, 'Analysis for W' ); 38 | -------------------------------------------------------------------------------- /demo/S_ExactMeanAndCovariance.R: -------------------------------------------------------------------------------- 1 | #' Generate draws from a multivariate normal with matching mean and covariance, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 64 - Simulation of a multivariate normal random variable with matching moments". 7 | #' 8 | #' See Meucci's script for "S_ExactMeanAndCovariance.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ######################################################################################################## 13 | ### Inputs 14 | N = 20; # dimension (number of risk factors) 15 | J = 200; # number of simulations 16 | 17 | ######################################################################################################## 18 | ### Generate desired population moments: 19 | 20 | # vector of expected values M 21 | M = matrix(runif( N ) -0.5); 22 | # covariance matrix S 23 | A = matrix( runif( N * N ), c( N, N )) - 0.5; 24 | S = A %*% t( A ); 25 | 26 | # generate sample of size J from multivariate normal N(M,S) 27 | X = MvnRnd( M, S, J ); # exact match between sample and population moments 28 | 29 | ######################################################################################################## 30 | ### Compute sample moments and errors 31 | M_ = matrix( apply( X, 2, mean )); #apply 32 | S_ = ( dim( X )[1] - 1 )/ dim( X )[1] * cov( X ); 33 | 34 | ######################################################################################################## 35 | ### Check errors 36 | Err_M = max( abs( M - M_ ) ) / max( abs( M ) ); 37 | Err_S = max( max( abs( S - S_) ) )/ max( max( abs( S ) ) ); 38 | 39 | print(Err_M); 40 | print(Err_S); 41 | 42 | -------------------------------------------------------------------------------- /demo/S_FactorAnalysisNotOk.R: -------------------------------------------------------------------------------- 1 | #'This script illustrates the hidden factor analysis puzzle, as described in A. Meucci, 2 | #'"Risk and Asset Allocation", Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 111 - Hidden factors: puzzle". 7 | #' 8 | #' See Meucci's script for "S_FactorAnalysisNotOk.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Inputs 14 | 15 | N = 5; # market dimension 16 | K = 2; # factors dimension 17 | J = 10000; # numbers of simulations 18 | 19 | ################################################################################################################## 20 | ### Define true hidden loadings B 21 | 22 | B = matrix( runif( N*K ), N, K ) - 0.5; 23 | 24 | B = B / sqrt( 1.5 * max( max( B %*% t(B) ) ) ); 25 | 26 | # define true hidden idiosyncratic variances 27 | D = array( 1, N) - diag( B %*% t(B) ); 28 | 29 | # define true hidden global covariance 30 | S = B %*% t( B ) + diag( D, length(D) ); 31 | 32 | # generate normal variables with matching moments 33 | X = MvnRnd( matrix( 0, N, 1 ), S, J ); 34 | 35 | # recover loadings FA$loadings, idiosyncratic variances FA$uniquenesness and factors FA$scores by factor analysis 36 | #[FA$loadings, FA$uniquenesness, T_, stats, F_] 37 | FA = factanal(X, K, scores = "Bartlett" ); 38 | 39 | # factor analysis recovers the structure exactly however... 40 | S_ = FA$loadings %*% t( FA$loadings ) + diag( FA$uniquenesses, length( FA$uniquenesses) ); 41 | Match = 1 - max( abs( ( S - S_) / S) ); 42 | print(Match); 43 | 44 | # ...the systematic+idiosyncratic decomposition is NOT recovered 45 | U_ = X - FA$scores %*% t(FA$loadings); # compute residuals 46 | S_U = cor( U_ ); # compute correlations 47 | 48 | # residuals are not idiosyncratic 49 | print( S_U ); -------------------------------------------------------------------------------- /demo/S_FactorResidualCorrelation.R: -------------------------------------------------------------------------------- 1 | #' This script illustrates exogenous loadings and endogenous factors the true analytical VaR under the lognormal 2 | #' assumptions from the estimation interval to the investment horizon, as described in A. Meucci, 3 | #' "Risk and Asset Allocation", Springer, 2005, Chapter 3. 4 | #' 5 | #' @references 6 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 7 | #' "E 125 - Correlation factors-residual: normal example". 8 | #' 9 | #' See Meucci's script for "S_FactorResidualCorrelation.m" 10 | #' 11 | #' @author Xavier Valls \email{flamejat@@gmail.com} 12 | 13 | ################################################################################################################## 14 | ### Input parameters: 15 | N = 4; # market size 16 | nSim = 10000; 17 | mu = 0.1 + 0.3 * runif(N); 18 | sigma = 0.5 * mu; 19 | dd = matrix(rnorm( N*N ), N, N ); 20 | Corr = cov2cor( dd %*% t( dd ) ); 21 | Sigma = diag( sigma, length(sigma) ) %*% Corr %*% diag( sigma, length(sigma) ); 22 | 23 | ################################################################################################################## 24 | ### Generate simulations for X 25 | X = MvnRnd(mu, Sigma, nSim); 26 | 27 | ################################################################################################################## 28 | ### Generate a random vector beta 29 | beta = matrix( 1, N ) + rnorm(N) * 0.1; 30 | 31 | ################################################################################################################## 32 | ### Compute factor realization by cross-sectional regression and residuals 33 | F = ( X %*% beta ) / ( t( beta ) %*% (beta) )[1]; 34 | F = solve( t( beta ) %*% beta)[1] * ( X %*% beta ); 35 | 36 | # compute residual 37 | U = X - F %*% t(beta); 38 | 39 | # correlation of residuals U among themselves and with factors F 40 | R = cor( cbind( F, U ) ); 41 | print(R); 42 | 43 | -------------------------------------------------------------------------------- /demo/S_FitProjectRates.R: -------------------------------------------------------------------------------- 1 | # This script fits the swap rates dynamics to a multivariate Ornstein-Uhlenbeck process 2 | # and computes and plots the estimated future distribution 3 | # see A. Meucci (2009) 4 | # "Review of Statistical Arbitrage, Cointegration, and Multivariate Ornstein-Uhlenbeck" 5 | # available at ssrn.com 6 | 7 | # Code by A. Meucci, April 2009 8 | # Most recent version available at www.symmys.com > Teaching > MATLAB 9 | 10 | # inputs 11 | TimeStep = 5 # select time interval (days) 12 | Taus = c( 1/252,5/252,1/12,.5,1,2,10 ) # select horizon projection (years) 13 | Pick = c( 2,3 ) 14 | 15 | # estimation 16 | StepRates = Rates[ seq( from = 1, to = nrow( Rates ), by = TimeStep ) , ] 17 | OUResult = FitOU( as.matrix( StepRates ) , TimeStep / 252 ) 18 | 19 | for( s in 1:length(Taus)) 20 | { 21 | RGB = .6 * as.matrix( c( runif(1),runif(1),runif(1) ) ) 22 | tau = Taus[ s ] 23 | 24 | # projection 25 | # x_T = Mu 26 | x_T = Rates[ nrow( Rates ) , ] 27 | OUstepResult = OUstep( as.matrix( x_T ) , tau , OUResult$Mu , OUResult$Th , OUResult$Sig ) 28 | 29 | # plot 30 | # historical observations 31 | plot( Rates[ , Pick[1] ] , Rates[ , Pick[2] ] ) 32 | 33 | # current observation 34 | plot( x_T[ Pick[1] ] , x_T[ Pick[2] ] ) 35 | 36 | # horizon location 37 | plot( OUstepResult$Mu_t[ Pick[1] ] , OUstepResult$Mu_t[ Pick[2] ] ) 38 | } -------------------------------------------------------------------------------- /demo/S_FixedIncomeInvariants.R: -------------------------------------------------------------------------------- 1 | #' This file performs the quest for invariance in the fixed income market, as described in A. Meucci 2 | #' "Risk and Asset Allocation", Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 139 - Fixed-income market: quest for invariance". 7 | #' 8 | #' See Meucci's script for "S_FixedIncomeInvariants.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Load government yield curve and bond yield data for different dates 14 | data("fixedIncome"); 15 | 16 | ################################################################################################################## 17 | ### Pick time-to-maturity for one point on the yield curve 18 | ycMaturityIndex = 4; # 1..6 19 | 20 | # select the yield time series for a constant time-to-maturity 21 | yield = fixedIncome$ycYieldPercent[ , ycMaturityIndex ]; 22 | 23 | ################################################################################################################## 24 | ### Quest for invariance 25 | # changes in the yield curve 26 | X = yield[ -1 ] - yield[ -length( yield ) ]; 27 | PerformIidAnalysis( 1:length( X ), X, "Changes in yield curve" ); 28 | 29 | # changes in the logarithm of the yield curve 30 | Y = log( yield[ -1 ] ) - log( yield[ -length( yield ) ] ); 31 | PerformIidAnalysis( 1 : length( Y ), Y, "Changes in log of yield curve" ); 32 | -------------------------------------------------------------------------------- /demo/S_FullCodependence.R: -------------------------------------------------------------------------------- 1 | #' This script illustrates the concept of co-dependence, as described 2 | #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 89 - Full co-dependence". 7 | #' 8 | #' See Meucci's script for "S_FullCodependence.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ############################################################################################################# 13 | ### Generate draws 14 | J = 10000; 15 | N = 10; 16 | sig2 = 1; 17 | 18 | U = runif( J ); 19 | X = matrix( NaN, J, N ); 20 | 21 | for( n in 1 : N ) 22 | { 23 | a = n / 2; 24 | b = 2 * sig2; 25 | X[ , n ] = qgamma( U, a, b ); 26 | } 27 | 28 | NumBins = round( 10 * log( J )); 29 | 30 | par( mfrow = c( 3, 1) ); 31 | hist( X[ , 1 ], NumBins, xlab = "X_1", main = "histogram of X_1" ); 32 | plot( X[ , 1 ], X[ , 2 ], xlab = "X_1", ylab = "X_2" ); 33 | hist( X[ , 2 ], NumBins, xlab = "X_2", main = "histogram of X_1" ); 34 | 35 | -------------------------------------------------------------------------------- /demo/S_GenerateMixtureSample.R: -------------------------------------------------------------------------------- 1 | #' This script generates draws from a univarite mixture, as described in A. Meucci, "Risk and Asset Allocation", 2 | #' Springer, 2005, Chapter 4. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 184 - Estimation of a quantile of a mixture I". 7 | #' 8 | #' See Meucci's script for "S_GenerateMixtureSample.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com}### 11 | 12 | ################################################################################################################## 13 | ### Inputs 14 | a = 0.8; 15 | m_Y = 0.1; 16 | s_Y = 0.2; 17 | m_Z = 0; 18 | s_Z = 0.15; 19 | 20 | T = 52; 21 | 22 | ################################################################################################################## 23 | ### Computations 24 | P = runif(T); 25 | Q = QuantileMixture( P, a, m_Y, s_Y, m_Z, s_Z ); 26 | 27 | dev.new(); 28 | plot( Q ); -------------------------------------------------------------------------------- /demo/S_JumpDiffusionMerton.R: -------------------------------------------------------------------------------- 1 | #' This script simulates a jump-diffusion process, as described in A. Meucci, "Risk and Asset Allocation", 2 | #' Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 132 - Simulation of a jump-diffusion process". 7 | #' 8 | #' See Meucci's script for "S_JumpDiffusionMerton.m" 9 | #' @note see Merton, R. C., 1976. "Option pricing when underlying stocks are discontinuous". Journal of Financial 10 | #' Economics 3, 125-144. 11 | #' @author Xavier Valls \email{flamejat@@gmail.com} 12 | 13 | ################################################################################################################## 14 | ### Parameters 15 | ts = seq( 1/252, 1, 1/252); # grid of time values at which the process is evaluated ("0" will be added, too) 16 | J = 10; # number of simulations 17 | 18 | ################################################################################################################## 19 | ### Simulate processes 20 | 21 | mu = 0.00; # deterministic drift 22 | sig = 0.20; # Gaussian component 23 | 24 | l = 3.45; # Poisson process arrival rate 25 | a = 0; # drift of log-jump 26 | D = 0.2; # st.dev of log-jump 27 | 28 | X = SimulateJumpDiffusionMerton( mu, sig, l, a, D, ts, J ); 29 | matplot(c( 0, ts), t(X), type="l", xlab = "time", main = "Merton jump-diffusion"); 30 | -------------------------------------------------------------------------------- /demo/S_MarkovChainMonteCarlo.R: -------------------------------------------------------------------------------- 1 | #' This script illustrates the Metropolis-Hastings algorithm, as described in A. Meucci,"Risk and Asset Allocation", 2 | #' Springer, 2005, Chapter 7. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 280 - Markov chain Monte Carlo". 7 | #' 8 | #' See Meucci's script for "S_MarkovChainMonteCarlo.m" 9 | # 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Set-up target and candidate 14 | # kernel of the target distribution 15 | kernel = function(x) dnorm( x, 1, 0.5 ); 16 | 17 | # parameters of the normal candidate distribution 18 | mu = 0; 19 | sig = 5; 20 | 21 | ################################################################################################################## 22 | ### Set up MH algorithm 23 | nSim = 10000; 24 | xt = matrix( NaN, nSim, 1); 25 | nacc = 0; 26 | xt[ 1 ] = 0; 27 | 28 | for( i in 2 : nSim ) 29 | { 30 | # normal candidate 31 | r = mu + sig * rnorm(1); 32 | # kernel at candidate 33 | f1 = kernel( r ); 34 | # kernel at past 35 | f2 = kernel( xt[ i-1 ] ); 36 | 37 | prob = f1 / f2; 38 | xt[ i ] = xt[ i-1 ]; 39 | if( prob > 1 || runif(1) > (1 - prob) ) 40 | { 41 | xt[ i ] = r; 42 | nacc = nacc + 1; 43 | } 44 | } 45 | ################################################################################################################## 46 | ### Post-process output 47 | # acceptance rate 48 | print( nacc / nSim ); 49 | 50 | # display MCMC over time 51 | dev.new(); 52 | plot( xt, type = "l" ); 53 | 54 | # distribution 55 | dev.new(); 56 | hist( xt, log(10*nSim) ); 57 | -------------------------------------------------------------------------------- /demo/S_OrderStatisticsPdfLognormal.R: -------------------------------------------------------------------------------- 1 | #' This script script shows that the pdf of the r-th order statistics of a lognormal random variable, 2 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 78 - Order statistics". 7 | #' 8 | #' See Meucci's script for "S_OrderStatisticsPdfLognormal.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | if ( !require( "scatterplot3d" ) ) stop("scatterplot3d package installation required for this script") 14 | 15 | ################################################################################################################# 16 | ### Input 17 | 18 | mu = 0.2; 19 | s = 0.25; 20 | T = 70; 21 | 22 | ################################################################################################################# 23 | ### Pdf of r-th order statistic concentrated around the r/T quantile 24 | 25 | rs = 1 : T; 26 | x = seq( 0 , 2.5 * exp(mu + s * s / 2), 0.01 ); 27 | 28 | F = plnorm( x, mu, s ); 29 | f = dlnorm( x, mu, s ); 30 | 31 | #matrix to plot 32 | 33 | a = scatterplot3d( 0, 0 , 0, xlim=c(0,4), ylim=c(0,1), zlim=c(0,10), xlab = "x", ylab = "r/T", zlab = "pdf" ); 34 | 35 | for ( n in 1 : length( rs ) ) 36 | { 37 | r = rs[ n ]; 38 | pdf_rT = gamma( T + 1 ) / ( gamma( r ) * gamma( T - r + 1 )) * ( F ^ (r - 1) ) * (( 1 - F ) ^ ( T - r) ) * f; 39 | q = qlnorm( r / T, mu, s ); 40 | a$points3d( x, r / T + 0 * x, pdf_rT ); 41 | a$points3d( q, r / T, 0 ); 42 | } -------------------------------------------------------------------------------- /demo/S_OrderStatisticsPdfStudentT.R: -------------------------------------------------------------------------------- 1 | #' This script script shows that the pdf of the r-th order statistics of a tudent t random variable, 2 | #' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 2. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 78 - Order statistics". 7 | #' 8 | #' See Meucci's script for "S_OrderStatisticsPdfStudentT.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | #' 12 | 13 | if ( !require( "scatterplot3d" ) ) stop("scatterplot3d package installation required for this script") 14 | 15 | ################################################################################################################# 16 | ### Input 17 | mu = 0; 18 | s = 1; 19 | nu = 10; 20 | T = 70; 21 | 22 | ################################################################################################################# 23 | ### Pdf of r-th order statistic concentrated around the r/T quantile 24 | 25 | rs = 1: T; 26 | x = mu + s * seq( -4, 4, 0.01); 27 | 28 | F = pt((x - mu) / s, nu); 29 | f = 1 / s * dt((x - mu) / s, nu); 30 | 31 | a = scatterplot3d( 0, 0 , 0, xlim = c(-4 , 4 ), ylim = c( 0, 1 ), zlim = c( 0, 3), xlab = "x", ylab = "r/T", zlab = "pdf" ); 32 | 33 | for ( n in 1 : length( rs ) ) 34 | { 35 | r = rs[ n ]; 36 | pdf_rT = gamma( T + 1 ) / ( gamma( r ) * gamma( T - r + 1 )) * ( F ^ (r - 1) ) * (( 1 - F ) ^ ( T - r) ) * f; 37 | q = mu + s * qt( r / T, nu ); 38 | a$points3d( x, r / T + 0 * x, pdf_rT, type = "l" ); 39 | a$points3d( q, r / T, 0 ); 40 | } -------------------------------------------------------------------------------- /demo/S_PasturMarchenko.R: -------------------------------------------------------------------------------- 1 | #' This script illustrate the Marchenko-Pastur limit of runifom matrix theory, as described in A. Meucci, 2 | #' "Risk and Asset Allocation", Springer, 2005, Chapter 4. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 190 - Random matrix theory: Marchenko-Pastur limit". 7 | #' 8 | #' See Meucci's script for "S_PasturMarchenko.m" 9 | #' 10 | 11 | ################################################################################################################## 12 | ### Inputs 13 | T = 1500; 14 | N = 900; 15 | 16 | ################################################################################################################## 17 | ### Empirical eigenvalues 18 | 19 | #X = matrix( runif(T*N), T, N ) ; # normal 20 | #X = (matrix( runif(T*N), T, N ) - 0.5) * sqrt(12); # uniform 21 | X = log(matrix( runif( T*N ), T, N )) + 1; # exponential 22 | 23 | Y = ( t(X) %*% X ) / T; # symmetrize and rescale 24 | E = t(eigen(Y)$values); 25 | 26 | NumBins = ceiling( 10 * log( length( E ))); 27 | h = hist(E, NumBins, 1); 28 | t_= h$mids; 29 | b = h$counts; 30 | D = t_[ 2 ] - t_[ 1 ]; 31 | h = b / (D * N); 32 | 33 | ################################################################################################################## 34 | ### Theoretical eigenvalues 35 | q = N / T; 36 | t_min = ( 1 - sqrt( q )) ^ 2; 37 | t_max = ( 1 + sqrt( q )) ^ 2; 38 | t = seq(t_[ 1 ], t_[length(t_)], (t_[ length(t_) ]- t_[ 1 ])/100 ); 39 | a = pmax( t_max - t, 0); 40 | b = pmax( t - t_min, 0); 41 | y = 1 / ( q * 2 * pi * t) * sqrt(a * b); 42 | 43 | ################################################################################################################## 44 | ### Plots 45 | #barplot(t_,h); 46 | plot(t_,h, type="h", lwd=5); 47 | lines(t , y, col = 'red', lwd = 3); 48 | -------------------------------------------------------------------------------- /demo/S_ProjectSummaryStatistics.R: -------------------------------------------------------------------------------- 1 | 2 | #' This script projects summary statistics to arbitrary horizons, as described in A. Meucci 3 | #' "Risk and Asset Allocation", Springer, 2005, chapter 3. 4 | #' 5 | #' @references 6 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 7 | #' "E 97 - Projection of skewness, kurtosis, and all standardized summary statistics". 8 | #' 9 | #' See Meucci's script for "S_ProjectSummaryStatistics.m" 10 | #' 11 | #' @author Xavier Valls \email{flamejat@@gmail.com} 12 | 13 | ################################################################################################################## 14 | ### Inputs 15 | 16 | N = 6; # focus on first N standardized summary statistics 17 | K = 100; # projection horizon 18 | 19 | # generate arbitrary distribution 20 | J = 100000; # number of scenarios 21 | 22 | Z = rnorm( J ); 23 | X = sin( Z ) + log( cos( Z ) + 2 ); 24 | 25 | ################################################################################################################## 26 | ### Compute single-period standardized statistics and central moments 27 | CaSS = CentralAndStandardizedStatistics( X, N ); 28 | print( CaSS$ga ); 29 | print( CaSS$mu ); 30 | 31 | # compute single-period non-central moments 32 | mu_ = Central2Raw( CaSS$mu ); 33 | print( mu_); 34 | 35 | # compute single-period cumulants 36 | ka = Raw2Cumul(mu_); 37 | print(ka); 38 | 39 | # compute multi-period cumulants 40 | Ka = K * ka; 41 | print(Ka); 42 | 43 | # compute multi-period non-central moments 44 | Mu_ = Cumul2Raw(Ka); 45 | print(Mu_); 46 | 47 | # compute multi-period central moments 48 | Mu = Raw2Central(Mu_); 49 | print(Mu); 50 | 51 | # compute multi-period standardized statistics 52 | Ga = Mu; 53 | Ga[ 2 ] = sqrt( Mu[ 2 ]); 54 | 55 | for( n in 3 : N ) 56 | { 57 | Ga[ n ] = Mu[ n ] / ( Ga[ 2 ] ^ n ); 58 | } 59 | 60 | print(Ga); -------------------------------------------------------------------------------- /demo/S_PureResidualBonds.R: -------------------------------------------------------------------------------- 1 | #' This script models the joint distribution of the yet-to-be realized key rates of the government curve, 2 | #' as described in A. Meucci "Risk and Asset Allocation", Springer, 2005, chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 112 - Pure residual models: duration/curve attribution". 7 | #' 8 | #' See Meucci's script for "S_PureResidualBonds.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Load data 14 | data("bondAttribution"); 15 | 16 | 17 | ################################################################################################################## 18 | # bondAttribution$B = key rate durations 19 | # bondAttribution$F = key rate weekly changes 20 | # bondAttribution$X = bonds returns net of carry 21 | 22 | Dim = dim(bondAttribution$B); 23 | 24 | U = 0 * bondAttribution$X; 25 | 26 | for( t in 1 : Dim[1] ) 27 | { 28 | U[ t, ] = bondAttribution$X[ t, ] - bondAttribution$F[ t, ] %*% drop(bondAttribution$B[ t, , ]); 29 | } 30 | 31 | C = cor(cbind( U, bondAttribution$F ) ); 32 | 33 | 34 | C_U = C[ 1:Dim[3], 1:Dim[3] ]; 35 | C_FU = C[ 1:Dim[3], -(1:Dim[3]) ]; 36 | 37 | # not systematic-plus-idiosyncratic model 38 | print(C_U); 39 | print(C_FU); 40 | 41 | -------------------------------------------------------------------------------- /demo/S_SemiCircular.R: -------------------------------------------------------------------------------- 1 | #' This script illustrate the semi-circular law of random matrix theory, as described in A. Meucci, 2 | #' "Risk and Asset Allocation", Springer, 2005, Chapter 4. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 189 - Random matrix theory: semi-circular law". 7 | #' 8 | #' See Meucci's script for "S_SemiCircular.m" 9 | 10 | ################################################################################################################## 11 | ### Inputs 12 | N = 1000; # matrix size 13 | 14 | ################################################################################################################## 15 | ### Empirical eigenvalues 16 | 17 | #X = rnorm( N ); # normal 18 | #X = ( runif(N)-0.5 ) * sqrt(12); # uniform 19 | X = log( matrix( runif(N^2), N, N )) + 1; # exponential 20 | 21 | Y = (X + t(X) ) / ( 2 * sqrt( 2 * N )); # symmetrize and rescale 22 | E = t(eigen(Y)$values); 23 | 24 | ################################################################################################################## 25 | ### Theoretical eigenvalues 26 | t = seq( -1, 1, 0.01 ); 27 | g = 2 / pi * sqrt(1 - t^2); 28 | 29 | NumBins = ceiling( 10 * log( length( E ))); 30 | h = hist(E, NumBins, plot = FALSE); 31 | t_= h$mids; 32 | b = h$counts; 33 | D = t_[ 2 ] - t_[ 1 ]; 34 | h = b / (D * N); 35 | 36 | ################################################################################################################## 37 | ### Plots 38 | dev.new(); 39 | plot( t_, h, type = "h" , lwd = 5 ); 40 | lines( t, g, col = "red", lwd = 3 ); 41 | -------------------------------------------------------------------------------- /demo/S_Toeplitz.R: -------------------------------------------------------------------------------- 1 | #' This script shows that the eigenvectors of a Toeplitz matrix have a Fourier basis structure under t-distribution 2 | #' assumptions, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 130 - Eigenvectors for Toeplitz structure". 7 | #' 8 | #' See Meucci's script for "S_Toeplitz.R" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | 13 | ############################################################################################################### 14 | ### Inputs 15 | 16 | N = 200; # dimension of the matrix 17 | Decay = 0.9; # decay factor 18 | 19 | ############################################################################################################### 20 | T = diag( 1, N); 21 | for( n in 1 : (N - 1) ) 22 | { 23 | 24 | T = T + Decay^n * ( cbind( matrix( 0, N, N -( N-n ) ), diag( 1, N , N-n) ) + 25 | cbind( rbind( matrix(0, N-(N-n), N-n ), diag( 1, N-n)), matrix(0, N, N-(N-n) ) )) ; 26 | 27 | } 28 | eig = eigen( T ); 29 | 30 | ############################################################################################################### 31 | 32 | #R sorts the eigen vectors, so the results aren't going to be exactly the same as in MATLAB 33 | 34 | dev.new(); 35 | plot( eig$vectors[ , n ], type = "l", col = runif(1)*100 ); 36 | lines( eig$vectors[ , n-1 ], type = "l", col = runif(1)*100 ); 37 | -------------------------------------------------------------------------------- /demo/S_VolatilityClustering.R: -------------------------------------------------------------------------------- 1 | #' This file generates paths for a volatility clustering, as described in A. Meucci, "Risk and Asset Allocation", 2 | #' Springer, 2005, Chapter 3. 3 | #' 4 | #' @references 5 | #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, 6 | #' "E 134 - Simulation of a GARCH process". 7 | #' 8 | #' See Meucci's script for "S_VolatilityClustering.m" 9 | #' 10 | #' @author Xavier Valls \email{flamejat@@gmail.com} 11 | 12 | ################################################################################################################## 13 | ### Input parameters 14 | mu = 0.05; # mean 15 | a = 0.03; 16 | b = 0.96; 17 | s = 0.01; 18 | T = 1000; 19 | 20 | ################################################################################################################## 21 | ### Simulate path 22 | z = rnorm(T); 23 | s2 = s^2; 24 | eps = array( NaN, T ); 25 | eps[ 1 ] = s2; 26 | for( t in 1 : (T - 1) ) 27 | { 28 | s2[ t + 1 ] = s^2 + a * ( z[ t ]^2) + b * s2[ t ]; 29 | eps[ t + 1 ] = mu + sqrt( s2[ t + 1] ) * z[ t + 1 ]; 30 | } 31 | 32 | dev.new(); 33 | plot(eps, type = "l", main = "GARCH(1,1) process vs. time", xlab = "", ylab = "" ); 34 | -------------------------------------------------------------------------------- /demo/S_plotGaussHermite.R: -------------------------------------------------------------------------------- 1 | # Diplay mesh points based on Gaussian-Hermite quadrature 2 | # This script complements the article 3 | # "Fully Flexible Extreme Views" 4 | # by A. Meucci, D. Ardia, S. Keel 5 | # available at www.ssrn.com 6 | # The most recent version of this code is available at 7 | # MATLAB Central - File Exchange 8 | 9 | N = 50; 10 | X = matrix( data=NA, nrow=N, ncol=N) 11 | 12 | for (i in 1:N) { 13 | x = gaussHermiteMesh(i) 14 | X[1:length(x), i] = x 15 | } 16 | 17 | # mesh points 18 | for (i in 1:N) { 19 | plot(1:N, t(X[i,])) 20 | } -------------------------------------------------------------------------------- /demo/logToArithmeticCovariance.R: -------------------------------------------------------------------------------- 1 | # Generate arithmetric returns and arithmetric covariance matrix given a distribution of log returns 2 | 3 | # Example experiment with two assets 4 | 5 | # initialize with average log returns and log-based covariance matrix 6 | m1 <- c( .05 , .12 , .1 ) 7 | S1 <- matrix( c( .1 , .05 , .02 , .05 , .1 , .03 , .02 , .03 , .1 ), nrow = 3 ) 8 | 9 | # simulate log-return draws from log-based covariance matrix assuming normal distribution 10 | set.seed(1001) 11 | library(MASS) 12 | logReturns <- MASS::mvrnorm(2000000,mu=m1,Sigma=S1) 13 | 14 | # convert to arithmetic returns 15 | arithmeticReturn = exp( logReturns ) - 1 16 | colMeans( arithmeticReturn ) 17 | # create arithmetric based covariance matrix 18 | var( arithmeticReturn ) 19 | 20 | # compare simulation results with linreturn function 21 | linreturn( m1, S1 ) -------------------------------------------------------------------------------- /man/BlackLittermanFormula.Rd: -------------------------------------------------------------------------------- 1 | \name{BlackLittermanFormula} 2 | \alias{BlackLittermanFormula} 3 | \title{Computes the Black-Litterman formula for the moments of the posterior normal.} 4 | \usage{ 5 | BlackLittermanFormula(Mu, Sigma, P, v, Omega) 6 | } 7 | \arguments{ 8 | \item{Mu}{[vector] (N x 1) prior expected values.} 9 | 10 | \item{Sigma}{[matrix] (N x N) prior covariance matrix.} 11 | 12 | \item{P}{[matrix] (K x N) pick matrix.} 13 | 14 | \item{v}{[vector] (K x 1) vector of views.} 15 | 16 | \item{Omega}{[matrix] (K x K) matrix of confidence.} 17 | } 18 | \value{ 19 | BLMu [vector] (N x 1) posterior expected values. 20 | 21 | BLSigma [matrix] (N x N) posterior covariance matrix. 22 | } 23 | \description{ 24 | This function computes the Black-Litterman formula for 25 | the moments of the posterior normal, as described in A. 26 | Meucci, "Risk and Asset Allocation", Springer, 2005. 27 | } 28 | \author{ 29 | Xavier Valls \email{flamejat@gmail.com} 30 | } 31 | \references{ 32 | A. Meucci - "Exercises in Advanced Risk and Portfolio 33 | Management" \url{http://symmys.com/node/170}. 34 | 35 | See Meucci's script for "BlackLittermanFormula.m" 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/BlackScholesCallPrice.Rd: -------------------------------------------------------------------------------- 1 | \name{BlackScholesCallPrice} 2 | \alias{BlackScholesCallPrice} 3 | \alias{BlackScholesCallPutPrice} 4 | \alias{BlackScholesPutPrice} 5 | \title{Compute the Black-Scholes price of a European call or put option.} 6 | \usage{ 7 | BlackScholesCallPrice(spot, K, r, vol, T) 8 | 9 | BlackScholesPutPrice(spot, K, r, vol, T) 10 | 11 | BlackScholesCallPutPrice(spot, K, r, vol, T) 12 | } 13 | \arguments{ 14 | \item{spot}{[scalar] spot price of underlying} 15 | 16 | \item{K}{[scalar] strike of the call optioon} 17 | 18 | \item{r}{[scalar] risk free rate as a fraction} 19 | 20 | \item{vol}{[scalar] volatility of the underlying as a 21 | fraction} 22 | 23 | \item{T}{[scalar] time to maturity in years} 24 | } 25 | \value{ 26 | c [scalar] price of European call(s) 27 | 28 | p [scalar] price of European put(s) 29 | 30 | delta [scalar] delta of the call(s) or put(s) 31 | 32 | cash [scalar] cash held in a replicating portfolio 33 | } 34 | \description{ 35 | Compute the Black-Scholes price of a European call or put 36 | option as described in A. Meucci, "Risk and Asset 37 | Allocation", Springer, 2005. 38 | } 39 | \note{ 40 | Code is vectorized, so the inputs can be vectors or 41 | matrices (but sizes must match) 42 | } 43 | \author{ 44 | Xavier Valls \email{flamejat@gmail.com} 45 | } 46 | \references{ 47 | A. Meucci - "Exercises in Advanced Risk and Portfolio 48 | Management" \url{http://symmys.com/node/170}. 49 | 50 | See Meucci's script for "BlackScholesCallPrice.m" 51 | } 52 | 53 | -------------------------------------------------------------------------------- /man/CMAcombination.Rd: -------------------------------------------------------------------------------- 1 | \name{CMAcombination} 2 | \alias{CMAcombination} 3 | \title{CMA combination. Glues an arbitrary copula and arbitrary marginal distributions into a new joint distribution} 4 | \usage{ 5 | CMAcombination(x, u, U) 6 | } 7 | \arguments{ 8 | \item{x}{a generic x variable. Note: Linearly spaced 'x' 9 | help for coverage when performing linear interpolation} 10 | 11 | \item{u}{The value of the cumulative density function 12 | associated with x (parametric or non-parametric)} 13 | 14 | \item{U}{an aribtrary copula. Can take any copula 15 | obtained with the separation step (i.e. a set of 16 | scenario-probabilities)} 17 | } 18 | \value{ 19 | X a J x N matrix containing the new joint distribution 20 | based on the arbitrary copula 'U' 21 | } 22 | \description{ 23 | The combination step starts from arbitrary marginal 24 | distributions, and grades distributed according to a 25 | chosen arbitrary copula which can, but does not need to, 26 | be obtained by seperation. Then this function combines 27 | the marginals and copula into a new joint distribution. 28 | } 29 | \author{ 30 | Ram Ahluwalia \email{rahluwalia@gmail.com} 31 | } 32 | \references{ 33 | Meucci A., "New Breed of Copulas for Risk and Portfolio 34 | Management", Risk, September 2011 Most recent version of 35 | article and code available at 36 | \url{http://www.symmys.com/node/335} 37 | } 38 | 39 | -------------------------------------------------------------------------------- /man/CMAseparation.Rd: -------------------------------------------------------------------------------- 1 | \name{CMAseparation} 2 | \alias{CMAseparation} 3 | \title{CMA separation. Decomposes arbitrary joint distributions (scenario-probabilities) into their copula and marginals} 4 | \usage{ 5 | CMAseparation(X, p) 6 | } 7 | \arguments{ 8 | \item{X}{A matrix where each row corresponds to a 9 | scenario/sample from a joint distribution. Each column 10 | represents the value from a marginal distribution} 11 | 12 | \item{p}{A 1-column matrix of probabilities of the 13 | Jth-scenario joint distribution in X} 14 | } 15 | \value{ 16 | xdd a JxN matrix where each column consists of each 17 | marginal's generic x values in ascending order 18 | 19 | udd a JxN matrix containing the cumulative probability 20 | (cdf) for each marginal by column - it is rescaled by 'l' 21 | to be <1 at the far right of the distribution can 22 | interpret 'udd' as the probability weighted grade 23 | scenarios (see formula 11 in Meucci) 24 | 25 | U a copula (J x N matrix) - the joint distribution of 26 | grades defined by feeding the original variables X into 27 | their respective marginal CDF 28 | } 29 | \description{ 30 | The CMA separation step attains from the cdf "F" for the 31 | marginal "X", the scenario-probabilities representation 32 | of the copula (cdf of U: "F") and the inter/extrapolation 33 | representation of the marginal CDF's. It seperates this 34 | distribution into the pure "individual" information 35 | contained in the marginals and the pure "joint" 36 | information contained in the copula. 37 | } 38 | \details{ 39 | Separation step of Copula-Marginal Algorithm (CMA) 40 | } 41 | \author{ 42 | Ram Ahluwalia \email{rahluwalia@gmail.com} 43 | } 44 | \references{ 45 | Meucci A., "New Breed of Copulas for Risk and Portfolio 46 | Management", Risk, September 2011 Most recent version of 47 | article and code available at 48 | \url{http://www.symmys.com/node/335} 49 | } 50 | 51 | -------------------------------------------------------------------------------- /man/Central2Raw.Rd: -------------------------------------------------------------------------------- 1 | \name{Central2Raw} 2 | \alias{Central2Raw} 3 | \title{Transforms first n central moments into first n raw moments (first central moment defined as expectation)} 4 | \usage{ 5 | Central2Raw(mu) 6 | } 7 | \arguments{ 8 | \item{mu}{: [vector] (length N corresponding to order N) 9 | central moments} 10 | } 11 | \value{ 12 | mu_ : [vector] (length N corresponding to order N) 13 | corresponding raw moments 14 | } 15 | \description{ 16 | Step 2 of projection process: From the central moments of 17 | step 1, we compute the non-central moments. To do so we 18 | start with the first non-central moment and apply 19 | recursively an identity (formula 20) 20 | } 21 | \details{ 22 | \deqn{ \tilde{ \mu }^{ \big(1\big) }_{X} \equiv \mu 23 | ^{\big(1\big)}_{X} \\ \tilde{ \mu }^{ \big(n\big) }_{X} 24 | \equiv \mu ^{n}_{X} \sum_{k=0}^{n-1} \big(-1\big)^{n-k+1} 25 | \mu ^{n-k}_{X} \tilde{ \mu }^{\big(k\big)}_{X} } 26 | } 27 | \author{ 28 | Ram Ahluwalia \email{rahluwalia@gmail.com} 29 | } 30 | \references{ 31 | A. Meucci - "Exercises in Advanced Risk and Portfolio 32 | Management" \url{http://symmys.com/node/170}, "E 16- Raw 33 | moments to central moments". 34 | 35 | See Meucci's script for "Central2Raw.m" 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/CentralAndStandardizedStatistics.Rd: -------------------------------------------------------------------------------- 1 | \name{CentralAndStandardizedStatistics} 2 | \alias{CentralAndStandardizedStatistics} 3 | \title{Compute central and standardized statistics.} 4 | \usage{ 5 | CentralAndStandardizedStatistics(X, N) 6 | } 7 | \arguments{ 8 | \item{X}{[vector] (J x 1) draws from the distribution} 9 | 10 | \item{N}{[scalar] highest degree for the central moment} 11 | } 12 | \value{ 13 | ga [vector] (1 x N) standardized statistics up to order N 14 | 15 | mu [vector] (1 x N) central moments up to order N 16 | } 17 | \description{ 18 | Compute central and standardized statistics, as described 19 | in A. Meucci "Risk and Asset Allocation", Springer, 2005. 20 | 21 | Computes the central moments \deqn{ CM_1^X \equiv 22 | \mu_{X}\,, \quad CM_n^X \equiv E \{(X - E\{ X 23 | \})^{n}\}\,, \quad n=2,3,\ldots ,} and from them the 24 | standarized statistics \deqn{ 25 | \mu_{X},\sigma_{X},sk_{X},ku_{X},\gamma_{X}^{(5)}, \ldots 26 | ,\gamma_{X}^{(n)} .} where \deqn{\gamma_{X}^{(n)} \equiv 27 | E \{(X - \mu_{X})^{n}\}/\sigma_{X}^{n},\quad n\geq3 .} 28 | } 29 | \author{ 30 | Xavier Valls \email{flamejat@gmail.com} 31 | } 32 | \references{ 33 | A. Meucci - "Exercises in Advanced Risk and Portfolio 34 | Management" \url{http://symmys.com/node/170}, "E 97 - 35 | Projection of skewness, kurtosis, and all standardized 36 | summary statistics". See Meucci's script for 37 | "CentralAndStandardizedStatistics.m" 38 | 39 | Kendall, M., Stuart, A. - "The Advanced Theory of 40 | Statistics", 1969. Volume, 3rd Edition. Griffin. 41 | 42 | A. Meucci - "Annualization and general projection of 43 | skweness, kurtosis, and all summary statistics", GARP 44 | Risk Professional August 2010, 55-56. 45 | \url{http://symmys.com/node/136}. 46 | } 47 | 48 | -------------------------------------------------------------------------------- /man/ComputeCVaR.Rd: -------------------------------------------------------------------------------- 1 | \name{ComputeCVaR} 2 | \alias{ComputeCVaR} 3 | \title{Computes the conditional value at risk as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", 4 | The Risk Magazine, October 2008, p 100-106} 5 | \usage{ 6 | ComputeCVaR(Units, Scenarios, Conf) 7 | } 8 | \arguments{ 9 | \item{Units}{panel of joint factors realizations} 10 | 11 | \item{Scenarios}{vector of probabilities} 12 | 13 | \item{Conf}{Confidence} 14 | } 15 | \value{ 16 | CVaR Conditional Value at Risk 17 | } 18 | \description{ 19 | Computes the conditional value at risk as it appears in 20 | A. Meucci, "Fully Flexible Views: Theory and Practice", 21 | The Risk Magazine, October 2008, p 100-106 22 | } 23 | \author{ 24 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 25 | } 26 | \references{ 27 | A. Meucci, "Fully Flexible Views: Theory and Practice" 28 | \url{http://www.symmys.com/node/158} See Meucci script 29 | for "ButterflyTrading/ComputeCVaR.m" 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/ComputeMVE.Rd: -------------------------------------------------------------------------------- 1 | \name{ComputeMVE} 2 | \alias{ComputeMVE} 3 | \title{Compute the minimum volume ellipsoid for a given (multi-variate) time-series} 4 | \usage{ 5 | ComputeMVE(data) 6 | } 7 | \arguments{ 8 | \item{data}{a matrix time-series of data. Each row is a 9 | observation (date). Each column is an asset} 10 | } 11 | \value{ 12 | list a list with MVE_Location a numeric with the location 13 | parameter of minimum volume ellipsoid MVE_Dispersion a 14 | numeric with the covariance matrix of the minimum volume 15 | ellipsoid 16 | } 17 | \description{ 18 | Function computes the minimum volume ellipsoid for a 19 | given time series 20 | } 21 | \details{ 22 | via the expectations-minimization algorithm 23 | 24 | \deqn{ w_{t} = \frac{1}{T} , t = 1,...,T \\ m \equiv 25 | \frac{1}{ \sum_{s=1}^T w_{s} } \sum_{t=1}^T w_{t} x_{t} 26 | \\ S \equiv \sum_{t=1}^T w_{t} \big(x_{t} - m\big) 27 | \big(x_{t} - m\big)' \\ Ma_{t}^{2} \equiv \big(x-m\big)' 28 | S^{-1} \big(x-m\big), t=1,...,T \\ w_{t} \mapsto w_{t} 29 | Ma_{t}^{2} \\ U = \big(x_{1}' - \hat{E}',...,x_{T}' - 30 | \hat{E}' \big) \\ \hat{Cov} \equiv \frac{1}{T} U'U } 31 | 32 | The location and scatter parameters that define the 33 | ellipsoid are multivariate high-breakdown estimators of 34 | location and scatter 35 | } 36 | \author{ 37 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 38 | } 39 | \references{ 40 | \url{http://www.symmys.com/sites/default/files/Risk\%20and\%20Asset\%20Allocation\%20-\%20Springer\%20Quantitative\%20Finance\%20-\%20Estimation.pdf} 41 | See Sec. 4.6.1 of "Risk and Asset Allocation" - Springer 42 | (2005), by A. Meucci for the theory and the routine 43 | implemented below See Meucci script for "ComputeMVE.m" 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/ComputeMoments.Rd: -------------------------------------------------------------------------------- 1 | \name{ComputeMoments} 2 | \alias{ComputeMoments} 3 | \title{Takes a matrix of joint-scenario probability distributions and generates expectations, standard devation, and correlation matrix for the assets} 4 | \usage{ 5 | ComputeMoments(X, p) 6 | } 7 | \arguments{ 8 | \item{X}{a matrix of joint-probability scenarios (rows 9 | are scenarios, columns are assets)} 10 | 11 | \item{p}{a numeric vector containing the probabilities 12 | for each of the scenarios in the matrix X} 13 | } 14 | \value{ 15 | means a numeric vector of the expectations (probability 16 | weighted) for each asset 17 | 18 | sd a numeric vector of standard deviations corresponding 19 | to the assets in the covariance matrix 20 | 21 | correlationMatrix the correlation matrix resulting from 22 | converting the covariance matrix to a correlation matrix 23 | } 24 | \description{ 25 | Takes a matrix of joint-scenario probability 26 | distributions and generates expectations, standard 27 | devation, and correlation matrix for the assets 28 | } 29 | \author{ 30 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/CondProbViews.Rd: -------------------------------------------------------------------------------- 1 | \name{CondProbViews} 2 | \alias{CondProbViews} 3 | \title{Input conditional views} 4 | \usage{ 5 | CondProbViews(View, X) 6 | } 7 | \arguments{ 8 | \item{View}{TBD} 9 | 10 | \item{X}{TBD} 11 | } 12 | \value{ 13 | A TBD 14 | 15 | b TBD 16 | 17 | g TBD 18 | } 19 | \description{ 20 | statement: View(k).Who (e.g. [1 3])= View(k).Equal (e.g. 21 | {[2 3] [1 3 5]}) optional conditional statement: 22 | View(k).Cond_Who (e.g. [2])= View(k).Cond_Equal (e.g. 23 | {[1]}) amount of stress is quantified as Prob(statement) 24 | <= View(k).v if View(k).sgn = 1; Prob(statement) >= 25 | View(k).v if View(k).sgn = -1; 26 | } 27 | \details{ 28 | confidence in stress is quantified in View(k).c in (0,1) 29 | } 30 | \author{ 31 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/ConvertChangeInYield2Price.Rd: -------------------------------------------------------------------------------- 1 | \name{ConvertChangeInYield2Price} 2 | \alias{ConvertChangeInYield2Price} 3 | \title{Convert change in yield-to-maturity to price for fixed-income securities} 4 | \usage{ 5 | ConvertChangeInYield2Price(Exp_DY, Cov_DY, Times2Mat, 6 | CurrentPrices) 7 | } 8 | \arguments{ 9 | \item{Exp_DY}{[vector] (N x 1) expected value of change 10 | in yield to maturity} 11 | 12 | \item{Cov_DY}{[matrix] (N x N) covariance of change in 13 | yield to maturity} 14 | 15 | \item{Times2Mat}{[scalar] time to maturity} 16 | 17 | \item{CurrentPrices}{[vector] (N x 1) current prices} 18 | } 19 | \value{ 20 | Exp_Prices [vector] (N x 1) expected prices 21 | 22 | Cov_Prices [matrix] (N x N) covariance of prices 23 | } 24 | \description{ 25 | Convert change in yield-to-maturity to price for 26 | fixed-income securities, as described in A. Meucci "Risk 27 | and Asset Allocation", Springer, 2005. 28 | } 29 | \author{ 30 | Xavier Valls \email{flamejat@gmail.com} 31 | } 32 | \references{ 33 | A. Meucci - "Exercises in Advanced Risk and Portfolio 34 | Management" \url{http://symmys.com/node/170}, See 35 | Meucci's script for "ConvertChangeInYield2Price.m". 36 | 37 | A. Meucci - "Risk and Asset Allocation"-Springer (2005). 38 | See (6.77)-(6.79). 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/ConvertCompoundedReturns2Price.Rd: -------------------------------------------------------------------------------- 1 | \name{ConvertCompoundedReturns2Price} 2 | \alias{ConvertCompoundedReturns2Price} 3 | \title{Convert compounded returns to prices for equity-like securities.} 4 | \usage{ 5 | ConvertCompoundedReturns2Price(Exp_Comp_Rets, 6 | Cov_Comp_Rets, Starting_Prices) 7 | } 8 | \arguments{ 9 | \item{Exp_Comp_Rets}{[vector] (N x 1) expected values of 10 | compounded returns} 11 | 12 | \item{Cov_Comp_Rets}{[matrix] (N x N) covariance matrix 13 | of compounded returns} 14 | 15 | \item{Starting_Prices}{[vector] (N x 1)} 16 | } 17 | \value{ 18 | Exp_Prices [vector] (N x 1) expected values of prices 19 | 20 | Cov_Prices [matrix] (N x N) covariance matrix of prices 21 | } 22 | \description{ 23 | Convert compounded returns to prices for equity-like 24 | securities, as described in A. Meucci "Risk and Asset 25 | Allocation", Springer, 2005. 26 | } 27 | \author{ 28 | Xavier Valls \email{flamejat@gmail.com} 29 | } 30 | \references{ 31 | A. Meucci - "Exercises in Advanced Risk and Portfolio 32 | Management" \url{http://symmys.com/node/170}. See 33 | Meucci's script for "ConvertCompoundedReturns2Price.m". 34 | 35 | A. Meucci - "Risk and Asset Allocation"-Springer (2005). 36 | See (6.77)-(6.79). 37 | } 38 | 39 | -------------------------------------------------------------------------------- /man/Cumul2Raw.Rd: -------------------------------------------------------------------------------- 1 | \name{Cumul2Raw} 2 | \alias{Cumul2Raw} 3 | \title{Map cumulative moments into raw moments.} 4 | \usage{ 5 | Cumul2Raw(ka) 6 | } 7 | \arguments{ 8 | \item{ka}{: [vector] (length N corresponding to order N) 9 | cumulative moments} 10 | } 11 | \value{ 12 | mu_ : [vector] (length N corresponding to order N) 13 | corresponding raw moments 14 | } 15 | \description{ 16 | Step 5 of the projection process: 17 | } 18 | \details{ 19 | From the cumulants of Y we compute the raw non-central 20 | moments of Y 21 | 22 | We do so recursively by the identity in formula (24) 23 | which follows from applying (21) and re-arranging terms 24 | 25 | \deqn{ \tilde{ \mu } ^{ \big(n\big) }_{Y} \equiv \kappa^{ 26 | \big(n\big) }_{Y} + \sum_{k=1}^{n-1} (n-1)C_{k-1} 27 | \kappa_{Y}^{ \big(k\big) } \tilde{ \mu } ^{n-k}_{Y} } 28 | } 29 | \author{ 30 | Ram Ahluwalia \email{rahluwalia@gmail.com} 31 | } 32 | \references{ 33 | A. Meucci - "Exercises in Advanced Risk and Portfolio 34 | Management" \url{http://symmys.com/node/170}. See 35 | Meucci's script for "Cumul2Raw.m". 36 | 37 | A. Meucci - "Annualization and General Projection of 38 | Skewness, Kurtosis and All Summary Statistics" - formula 39 | (24) \url{http://www.symmys.com/node/136} 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/DetectOutliersViaMVE.Rd: -------------------------------------------------------------------------------- 1 | \name{DetectOutliersViaMVE} 2 | \alias{DetectOutliersViaMVE} 3 | \title{Use the minimum volume ellipsoid to detect outliers} 4 | \usage{ 5 | DetectOutliersViaMVE(corruptSample) 6 | } 7 | \arguments{ 8 | \item{corruptSample}{a matrix of returns with outlier 9 | data. Rows are observations, columns are assets.} 10 | } 11 | \value{ 12 | a list containing: plotdata a matrix of data used to plot 13 | minimum volume ellipsoid as a function of its length 14 | cutofflist an ordering of observations with the highest 15 | Mahalanobis distance (i.e. ordering of outliers by their 16 | index )#' numOutliers returns the number of outliers 17 | based on the slope of the minimum volume ellipsoid as a 18 | function of sample data 19 | } 20 | \description{ 21 | See Sec. 4.6.1 of "Risk and Asset Allocation" - Springer 22 | (2005), by A. Meucci for the theory and the routine 23 | implemented below 24 | } 25 | \author{ 26 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 27 | } 28 | \references{ 29 | \url{http://www.symmys.com} See Meucci script for 30 | "S_HighBreakdownMVE.m" 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/DoubleDecay.Rd: -------------------------------------------------------------------------------- 1 | \name{DoubleDecay} 2 | \alias{DoubleDecay} 3 | \title{Computes a double-decay covariance matrix.} 4 | \usage{ 5 | DoubleDecay(X, lmd_c, lmd_s) 6 | } 7 | \arguments{ 8 | \item{X}{matrix representing the risk drivers.} 9 | 10 | \item{lmd_c}{numeric representing the low decay (long 11 | half-life) for the correlations.} 12 | 13 | \item{lmd_s}{numeric representing the high decay (short 14 | half-life) for the volatilities.} 15 | } 16 | \value{ 17 | m matrix of zeros, representing the expectation of the 18 | risk drivers. 19 | 20 | S matrix representing the double-decay estimation for the 21 | correlation matrix of the risk drivers. 22 | } 23 | \description{ 24 | This function computes a double-decay covariance matrix 25 | for the risk drivers provided, as described in A. Meucci, 26 | "Personalized Risk Management: Historical Scenarios with 27 | Fully Flexible Probabilities" GARP Risk Professional, Dec 28 | 2010, p 47-51 29 | } 30 | \author{ 31 | Xavier Valls \email{flamejat@gmail.com} 32 | } 33 | \references{ 34 | \url{http://www.symmys.com/node/150} See Meucci script 35 | for "DoubleDecay.m" 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/EfficientFrontierPrices.Rd: -------------------------------------------------------------------------------- 1 | \name{EfficientFrontierPrices} 2 | \alias{EfficientFrontierPrices} 3 | \title{Computes the mean-variance efficient frontier (on prices) by quadratic programming} 4 | \usage{ 5 | EfficientFrontierPrices(NumPortf, Covariance, 6 | ExpectedValues, Current_Prices, Budget) 7 | } 8 | \arguments{ 9 | \item{NumPortf}{[scalar] number of portfolio in the 10 | efficient frontier} 11 | 12 | \item{Covariance}{[matrix] (N x N) covariance matrix} 13 | 14 | \item{ExpectedValues}{[vector] (N x 1) expected returns} 15 | 16 | \item{Current_Prices}{[vector] (N x 1) current prices} 17 | 18 | \item{Budget}{[scalar] budget constraint} 19 | } 20 | \value{ 21 | ExpectedValue [vector] (NumPortf x 1) expected values of 22 | the portfolios 23 | 24 | Std_Deviation [vector] (NumPortf x 1) standard deviations 25 | of the portfolios 26 | 27 | Composition [matrix] (NumPortf x N) optimal portfolios 28 | } 29 | \description{ 30 | Compute the mean-variance efficient frontier (on prices) 31 | by quadratic programming, as described in A. Meucci "Risk 32 | and Asset Allocation", Springer, 2005 33 | } 34 | \author{ 35 | Xavier Valls \email{flamejat@gmail.com} 36 | } 37 | \references{ 38 | A. Meucci - "Exercises in Advanced Risk and Portfolio 39 | Management" \url{http://symmys.com/node/170}. 40 | 41 | See Meucci's script for "EfficientFrontierReturns.m". 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/EfficientFrontierReturns.Rd: -------------------------------------------------------------------------------- 1 | \name{EfficientFrontierReturns} 2 | \alias{EfficientFrontierReturns} 3 | \title{Compute the mean-variance efficient frontier (on returns) by quadratic programming.} 4 | \usage{ 5 | EfficientFrontierReturns(NumPortf, Covariance, 6 | ExpectedValues, Constraints = NULL) 7 | } 8 | \arguments{ 9 | \item{NumPortf}{[scalar] number of portfolio in the 10 | efficient frontier} 11 | 12 | \item{Covariance}{[matrix] (N x N) covariance matrix} 13 | 14 | \item{ExpectedValues}{[vector] (N x 1) expected returns} 15 | 16 | \item{Constraints}{[struct] set of constraints. Default: 17 | weights sum to one, and no-short positions} 18 | } 19 | \value{ 20 | ExpectedValue [vector] (NumPortf x 1) expected values of 21 | the portfolios 22 | 23 | Volatility [vector] (NumPortf x 1) standard deviations of 24 | the portfolios 25 | 26 | Composition [matrix] (NumPortf x N) optimal portfolios 27 | } 28 | \description{ 29 | Compute the mean-variance efficient frontier (on returns) 30 | by quadratic programming, as described in A. Meucci "Risk 31 | and Asset Allocation", Springer, 2005 32 | } 33 | \author{ 34 | Xavier Valls \email{flamejat@gmail.com} 35 | } 36 | \references{ 37 | A. Meucci - "Exercises in Advanced Risk and Portfolio 38 | Management" \url{http://symmys.com/node/170}. 39 | 40 | See Meucci's script for "EfficientFrontierReturns.m". 41 | } 42 | 43 | -------------------------------------------------------------------------------- /man/EfficientFrontierReturnsBenchmark.Rd: -------------------------------------------------------------------------------- 1 | \name{EfficientFrontierReturnsBenchmark} 2 | \alias{EfficientFrontierReturnsBenchmark} 3 | \title{Computes the mean-variance efficient frontier (on returns) by quadratic programming.} 4 | \usage{ 5 | EfficientFrontierReturnsBenchmark(NumPortf, Covariance, 6 | ExpectedValues, Benchmark, Constraints = NULL) 7 | } 8 | \arguments{ 9 | \item{NumPortf}{[scalar] number of portfolio in the 10 | efficient frontier} 11 | 12 | \item{Covariance}{[matrix] (N x N) covariance matrix} 13 | 14 | \item{ExpectedValues}{[vector] (N x 1) expected returns} 15 | 16 | \item{Benchmark}{[vector] (N x 1) of benchmark weights} 17 | 18 | \item{Constraints}{[struct] set of constraints. Default: 19 | weights sum to one, and no-short positions} 20 | } 21 | \value{ 22 | ExpectedValue [vector] (NumPortf x 1) expected values of 23 | the portfolios 24 | 25 | Volatility [vector] (NumPortf x 1) standard deviations of 26 | the portfolios 27 | 28 | Composition [matrix] (NumPortf x N) optimal portfolios 29 | } 30 | \description{ 31 | Compute the mean-variance efficient frontier (on returns) 32 | by quadratic programming, as described in A. Meucci "Risk 33 | and Asset Allocation", Springer, 2005 34 | } 35 | \author{ 36 | Xavier Valls \email{flamejat@gmail.com} 37 | } 38 | \references{ 39 | A. Meucci - "Exercises in Advanced Risk and Portfolio 40 | Management" \url{http://symmys.com/node/170}. 41 | 42 | See Meucci's script for 43 | "EfficientFrontierReturnsBenchmark.m" 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/Equities.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{Equities} 3 | \alias{Equities} 4 | \title{daily stock prices from the utility sector in the S&P 500} 5 | \description{ 6 | daily stock prices from the utility sector in the S&P 7 | 500. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, Exercises in Advanced Risk and Portfolio 14 | Management. \url{http://symmys.com/node/170} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/FDButterflies.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{FDButterflies} 3 | \alias{FDButterflies} 4 | \title{Factor Distribution Butterflies} 5 | \description{ 6 | Factor Distribution Butterflies 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, "Fully Flexible Views: Theory and Practice", 13 | The Risk Magazine, October 2008, p 100-106. 14 | \url{http://symmys.com/node/158} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/Fit2Moms.Rd: -------------------------------------------------------------------------------- 1 | \name{Fit2Moms} 2 | \alias{Fit2Moms} 3 | \title{Uses Entropy Pooling to compute a double-decay covariance matrix.} 4 | \usage{ 5 | Fit2Moms(X, m, S) 6 | } 7 | \arguments{ 8 | \item{X}{matrix representing the risk drivers.} 9 | 10 | \item{m}{matrix of zeros, representing the expectation of 11 | the risk drivers.} 12 | 13 | \item{S}{matrix representing the double-decay estimation 14 | for the correlation matrix of the risk drivers.} 15 | } 16 | \value{ 17 | p list containing the vector of posterior probabilities 18 | and information about the optimization performance. 19 | } 20 | \description{ 21 | This function uses Entropy Pooling to compute a 22 | double-decay covariance matrix, as described in A. 23 | Meucci, "Personalized Risk Management: Historical 24 | Scenarios with Fully Flexible Probabilities" GARP Risk 25 | Professional, Dec 2010, p 47-51 26 | } 27 | \author{ 28 | Xavier Valls \email{flamejat@gmail.com} 29 | } 30 | \references{ 31 | \url{http://www.symmys.com/node/150} See Meucci script 32 | for "S_MainFullFlexProbs.m" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/FitExpectationMaximization.Rd: -------------------------------------------------------------------------------- 1 | \name{FitExpectationMaximization} 2 | \alias{FitExpectationMaximization} 3 | \title{Expectation-Maximization (EM) algorithm to recover missing observations in a time series.} 4 | \usage{ 5 | FitExpectationMaximization(X) 6 | } 7 | \arguments{ 8 | \item{X}{: [matrix] (T x N) of data} 9 | } 10 | \value{ 11 | E_EM : [vector] (N x 1) expectation 12 | 13 | S_EM : [matrix] (N x N) covariance matrix 14 | 15 | Y : [matrix] (T x N) updated data 16 | 17 | CountLoop : [scalar] number of iterations of the 18 | algorithm 19 | } 20 | \description{ 21 | Expectation-Maximization (EM) algorithm to recover 22 | missing observations in a time series , as described in 23 | A. Meucci, "Risk and Asset Allocation", Springer, 2005, 24 | section 4.6.2 "Missing data". 25 | } 26 | \author{ 27 | Xavier Valls \email{flamejat@gmail.com} 28 | } 29 | \references{ 30 | A. Meucci - "Exercises in Advanced Risk and Portfolio 31 | Management" \url{http://symmys.com/node/170}, "E 177 - 32 | Expectation-Maximization algorithm for missing data: 33 | formulas" See Meucci's script for 34 | "FitExpectationMaximization.m" 35 | 36 | Dempster, A. P. and Laird, M. N. and Rubin, D. B. - 37 | "Maximum Likelihood from Incomplete Data Via the EM 38 | Algorithm", Journal of the Royal Statistical Society, 39 | 1977 vol 39 pag. 1-22. 40 | 41 | Bilmes, J. A.- "A Gentle Tutorial of the EM Algorithm and 42 | its Application to Parameter Estimation for Gaussian 43 | Mixture and Hidden Markov Models", 1998. 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/FitMultivariateGarch.Rd: -------------------------------------------------------------------------------- 1 | \name{FitMultivariateGarch} 2 | \alias{FitMultivariateGarch} 3 | \title{Estimation of multivariate GARCH models} 4 | \usage{ 5 | FitMultivariateGarch(returns, demean = 1, eps = 0, 6 | df = 500) 7 | } 8 | \arguments{ 9 | \item{returns}{: [matrix] (T x N) returns so rows must 10 | correspond to time and columns to assets} 11 | 12 | \item{demean}{: [scalar] specifies whether returns should 13 | be demeaned (if demean = 1) or not to estimate the model; 14 | default value is 1.} 15 | 16 | \item{eps}{: [scalar] used in enforcing a_ii + b_ii <= 1 17 | - eps; the default value is zero} 18 | 19 | \item{df}{: [scalar] degree of freedom for the 20 | t-distribution; the default value is 500 to make it, 21 | basically, normal} 22 | } 23 | \value{ 24 | mu : [vector] 25 | 26 | ATMF : [matrix] coefficient matrix A-tilde (in the 27 | notation of the paper) 28 | 29 | BTMF : [matrix] coefficient matrix B-tilde (in the 30 | notation of the paper) 31 | 32 | CTMF : [matrix] coefficient matrix C-tilde (in the 33 | notation of the paper) 34 | 35 | Hhat : [matrix] forecasted conditional covariance matrix 36 | } 37 | \description{ 38 | Estimation of multivariate GARCH models 39 | } 40 | \note{ 41 | Code for MATLAB initially written by Olivier Ledoit and 42 | Michael Wolf 43 | } 44 | \author{ 45 | Xavier Valls \email{flamejat@gmail.com} 46 | } 47 | \references{ 48 | A. Meucci - "Exercises in Advanced Risk and Portfolio 49 | Management" \url{http://symmys.com/node/170}, "E 136 - 50 | Equity market: multivariate GARCH process". 51 | 52 | See Meucci's script for "FitMultivariateGarch.m" 53 | } 54 | 55 | -------------------------------------------------------------------------------- /man/FitOU.Rd: -------------------------------------------------------------------------------- 1 | \name{FitOU} 2 | \alias{FitOU} 3 | \title{Fit the Ornstein-uhlenbeck process to model the behavior for different values of the timestep.} 4 | \usage{ 5 | FitOU(Y, tau) 6 | } 7 | \arguments{ 8 | \item{Y}{a matrix containing the value of a process at 9 | various time steps.} 10 | 11 | \item{tau}{a numeric containing the timestep} 12 | } 13 | \value{ 14 | a list containing 15 | 16 | Mu a vector containing the expectation of the process 17 | 18 | Sig a matrix containing the covariance of the resulting 19 | fitted OU process 20 | 21 | Th a transition matrix required for defining the fitted 22 | OU process 23 | 24 | \deqn{ x_{t+ \tau } = \big(I- e^{- \theta \tau } \big) 25 | \mu + e^{- \theta \tau } x_{t}, vec \big( \Sigma _{ \tau 26 | } \big) \equiv \big( \Theta \oplus \Theta \big) ^{-1} 27 | \big(I- e^{( \Theta \oplus \Theta ) \tau } \big) vec 28 | \big( \Sigma \big) } 29 | } 30 | \description{ 31 | Fit the Ornstein-uhlenbeck process to model the behavior 32 | for different values of the timestep. 33 | } 34 | \author{ 35 | Manan Shah \email{mkshah@cmu.edu} 36 | } 37 | \references{ 38 | A. Meucci - "Review of Statistical Arbitrage, 39 | Cointegration, and Multivariate Ornstein-Uhlenbeck" - 40 | Formula (8),(9) \url{http://ssrn.com/abstract=1404905} 41 | } 42 | 43 | -------------------------------------------------------------------------------- /man/FitOrnsteinUhlenbeck.Rd: -------------------------------------------------------------------------------- 1 | \name{FitOrnsteinUhlenbeck} 2 | \alias{FitOrnsteinUhlenbeck} 3 | \title{Fits a multivariate Ornstein - Uhlenbeck process at estimation step tau.} 4 | \usage{ 5 | FitOrnsteinUhlenbeck(Y, tau) 6 | } 7 | \arguments{ 8 | \item{Y}{: [matrix] (T x N)} 9 | 10 | \item{tau}{: [scalar] time step} 11 | } 12 | \value{ 13 | Mu : [vector] long-term means 14 | 15 | Th : [matrix] whose eigenvalues have positive real part / 16 | mean reversion speed 17 | 18 | Sig : [matrix] Sig = S * S', covariance matrix of 19 | Brownian motions 20 | } 21 | \description{ 22 | Fit a multivariate OU process at estimation step tau, as 23 | described in A. Meucci "Risk and Asset Allocation", 24 | Springer, 2005 25 | } 26 | \note{ 27 | o dY_t = -Th * (Y_t - Mu) * dt + S * dB_t where o dB_t: 28 | vector of Brownian motions 29 | } 30 | \author{ 31 | Xavier Valls \email{flamejat@gmail.com} 32 | } 33 | \references{ 34 | A. Meucci - "Exercises in Advanced Risk and Portfolio 35 | Management" \url{http://symmys.com/node/170}. 36 | 37 | See Meucci's script for "FitOrnsteinUhlenbeck.m" 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/GenFirstEigVect.Rd: -------------------------------------------------------------------------------- 1 | \name{GenFirstEigVect} 2 | \alias{GenFirstEigVect} 3 | \title{This function generates the first eigen vector} 4 | \usage{ 5 | GenFirstEigVect(S, A) 6 | } 7 | \arguments{ 8 | \item{S}{Covariance Matrix} 9 | 10 | \item{A}{Conditioning Matrix} 11 | } 12 | \value{ 13 | e First Eigen Vector 14 | } 15 | \description{ 16 | This function generates the first eigen vector 17 | } 18 | \author{ 19 | Manan Shah \email{mkshah@cmu.edu} 20 | } 21 | \references{ 22 | A. Meucci - "Managing Diversification", Risk Magazine, 23 | June 2009 \url{http://ssrn.com/abstract=1358533} 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/GenPCBasis.Rd: -------------------------------------------------------------------------------- 1 | \name{GenPCBasis} 2 | \alias{GenPCBasis} 3 | \title{This function computes the conditional principal portfolios} 4 | \usage{ 5 | GenPCBasis(S, A) 6 | } 7 | \arguments{ 8 | \item{S}{Covariance Matrix} 9 | 10 | \item{A}{Conditioning Matrix} 11 | } 12 | \value{ 13 | a list containing 14 | 15 | E a matrix containing conditional principal portfolios 16 | composition 17 | 18 | L a matrix containing conditional principal portfolios 19 | variances 20 | 21 | G map weights -> conditional diversification distribution 22 | (square root of, not normalized) 23 | 24 | \deqn{ e_{n} \equiv argmax_{ e'e \equiv 1 } \big\{ e' 25 | \Sigma e \big\} s.t. e' \Sigma e_{j} \equiv 0 } 26 | } 27 | \description{ 28 | This function computes the conditional principal 29 | portfolios 30 | } 31 | \author{ 32 | Manan Shah \email{mkshah@cmu.edu} 33 | } 34 | \references{ 35 | A. Meucci - "Managing Diversification", Risk Magazine, 36 | June 2009 - Formula (12) 37 | \url{http://ssrn.com/abstract=1358533} 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/GenerateLogNormalDistribution.Rd: -------------------------------------------------------------------------------- 1 | \name{GenerateLogNormalDistribution} 2 | \alias{GenerateLogNormalDistribution} 3 | \title{Generate arbitrary distribution of a shifted-lognormal invariant} 4 | \usage{ 5 | GenerateLogNormalDistribution(J, a, m, s) 6 | } 7 | \arguments{ 8 | \item{J}{a numeric with the number of scenarios} 9 | 10 | \item{a}{a numeric with the location shift parameter. 11 | Mean of distribution will be exp(a)} 12 | 13 | \item{m}{log of the mean of the distribution} 14 | 15 | \item{s}{log of the standard deviation of the 16 | distribution} 17 | } 18 | \value{ 19 | X a numeric vector with i.i.d. lognormal samples based on 20 | parameters J, a, m, and s where X = a + exp( m + s * Z ) 21 | } 22 | \description{ 23 | \deqn{X = a + e^{ m + sZ }} (formula 14) 24 | } 25 | \author{ 26 | Ram Ahluwalia \email{rahluwalia@gmail.com} 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/GenerateUniformDrawsOnUnitSphere.Rd: -------------------------------------------------------------------------------- 1 | \name{GenerateUniformDrawsOnUnitSphere} 2 | \alias{GenerateUniformDrawsOnUnitSphere} 3 | \title{Generate a uniform sample on the unit hypersphere.} 4 | \usage{ 5 | GenerateUniformDrawsOnUnitSphere(J, N) 6 | } 7 | \arguments{ 8 | \item{J}{: [scalar] number of draws} 9 | 10 | \item{N}{: [scalar] dimension} 11 | } 12 | \value{ 13 | X : [matrix] (T x N) of draws 14 | } 15 | \description{ 16 | Generate a uniform sample on the unit hypersphere, as 17 | described in A. Meucci, "Risk and Asset Allocation", 18 | Springer, 2005. 19 | } 20 | \note{ 21 | Initial MATLAB's script by Xiaoyu Wang - Dec 2006 22 | 23 | We decompose X=U*R, where U is a uniform distribution on 24 | unit sphere and 25 | } 26 | \author{ 27 | Xavier Valls \email{flamejat@gmail.com} 28 | } 29 | \references{ 30 | A. Meucci - "Exercises in Advanced Risk and Portfolio 31 | Management" \url{http://symmys.com/node/170}. See 32 | Meucci's script for "GenerateUniformDrawsOnUnitSphere.m" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/HorizonPricing.Rd: -------------------------------------------------------------------------------- 1 | \name{HorizonPricing} 2 | \alias{HorizonPricing} 3 | \title{Compute the pricing in the horizon as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", 4 | The Risk Magazine, October 2008, p 100-106.} 5 | \usage{ 6 | HorizonPricing(Butterflies, X) 7 | } 8 | \arguments{ 9 | \item{Butterflies}{List of securities with some analytics 10 | computed.} 11 | 12 | \item{X}{Panel of joint factors realizations} 13 | } 14 | \value{ 15 | PnL Matrix of profit and loss scenarios 16 | } 17 | \description{ 18 | Compute the pricing in the horizon as it appears in A. 19 | Meucci, "Fully Flexible Views: Theory and Practice", The 20 | Risk Magazine, October 2008, p 100-106. 21 | } 22 | \author{ 23 | Ram Ahluwalia \email{ram@wingedfootcapital.com} and 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci, "Fully Flexible Views: Theory and Practice" 28 | \url{http://www.symmys.com/node/158} See Meucci script 29 | for "ButterflyTrading/HorizonPricing.m" 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/InterExtrapolate.Rd: -------------------------------------------------------------------------------- 1 | \name{InterExtrapolate} 2 | \alias{InterExtrapolate} 3 | \title{Interpolate and extrapolate using n-linear interpolation (tensor product linear).} 4 | \usage{ 5 | InterExtrapolate(V, Xi, nodelist = NULL, method = NULL) 6 | } 7 | \arguments{ 8 | \item{V}{[array] p-dimensional array to be 9 | interpolated/extrapolated at the list of points in the 10 | array Xi.} 11 | 12 | \item{Xi}{[array] (n x p) array of n points to 13 | interpolate/extrapolate. Each point is one row of the 14 | array Xi.} 15 | 16 | \item{nodelist}{[cell array] (optional) cell array of 17 | nodes in each dimension.} 18 | 19 | \item{method}{[string] (optional) chacter string, denotes 20 | the interpolation method used. default method = 'linear'} 21 | } 22 | \value{ 23 | Vpred [array] (n x 1) array of interpolated/extrapolated 24 | values 25 | } 26 | \description{ 27 | Interpolate and extrapolate using n-linear interpolation 28 | (tensor product linear). 29 | } 30 | \note{ 31 | Initially written by John D'Errico. 32 | 33 | Extrapolating long distances outside the support of V is 34 | rarely advisable. 35 | } 36 | \author{ 37 | Xavier Valls \email{flamejat@gmail.com} 38 | } 39 | \references{ 40 | A. Meucci - "Exercises in Advanced Risk and Portfolio 41 | Management" \url{http://symmys.com/node/170}. 42 | 43 | See Meucci's script for "InterExtrapolate.R" 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/LeastInfoKernel.Rd: -------------------------------------------------------------------------------- 1 | \name{LeastInfoKernel} 2 | \alias{LeastInfoKernel} 3 | \title{Computes least information kernel smoothing} 4 | \usage{ 5 | LeastInfoKernel(Y, y, h2) 6 | } 7 | \arguments{ 8 | \item{Y}{Matrix representing the macroeconomic indicator} 9 | 10 | \item{y}{scalar reprenting the target to which Y is 11 | expected to be close in the Generalized Empirical 12 | Distribution} 13 | 14 | \item{h2}{N X N matrix} 15 | } 16 | \value{ 17 | p list containing the vector of posterior probabilities 18 | and information about the optimization performance. 19 | } 20 | \description{ 21 | This script uses Entropy Pooling to compute least 22 | information kernel smoothing, as described in A. Meucci, 23 | "Personalized Risk Management: Historical Scenarios with 24 | Fully Flexible Probabilities" GARP Risk Professional, Dec 25 | 2010, p 47-51 26 | } 27 | \author{ 28 | Xavier Valls \email{flamejat@gmail.com} 29 | } 30 | \references{ 31 | \url{http://www.symmys.com/node/150} See Meucci script 32 | for "LeastInfoKernel.m" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/Log2Lin.Rd: -------------------------------------------------------------------------------- 1 | \name{Log2Lin} 2 | \alias{Log2Lin} 3 | \title{Maps moments of log-returns to linear returns .} 4 | \usage{ 5 | Log2Lin(Mu, Sigma) 6 | } 7 | \arguments{ 8 | \item{Mu}{[vector] (N x 1)} 9 | 10 | \item{Sigma}{[matrix] (N x N)} 11 | } 12 | \value{ 13 | M [vector] (N x 1) 14 | 15 | S [matrix] (N x N) 16 | } 17 | \description{ 18 | Map moments of log-returns to linear returns, as 19 | described in A. Meucci, "Risk and Asset Allocation", 20 | Springer, 2005. 21 | } 22 | \author{ 23 | Xavier Valls \email{flamejat@gmail.com} 24 | } 25 | \references{ 26 | A. Meucci - "Exercises in Advanced Risk and Portfolio 27 | Management" \url{http://symmys.com/node/170}. 28 | 29 | See Meucci's script for "Log2Lin.m" 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/LognormalCopulaPdf.Rd: -------------------------------------------------------------------------------- 1 | \name{LognormalCopulaPdf} 2 | \alias{LognormalCopulaPdf} 3 | \title{Computes the pdf of the copula of the lognormal distribution at the generic point u in the unit hypercube.} 4 | \usage{ 5 | LognormalCopulaPdf(u, Mu, Sigma) 6 | } 7 | \arguments{ 8 | \item{u}{[vector] (J x 1) grades} 9 | 10 | \item{Mu}{[vector] (N x 1) location parameter} 11 | 12 | \item{Sigma}{[matrix] (N x N) scatter parameter} 13 | } 14 | \value{ 15 | F_U [vector] (J x 1) PDF values 16 | } 17 | \description{ 18 | Computes the pdf of the copula of the lognormal 19 | distribution at the generic point u in the unit 20 | hypercube, as described in A. Meucci, "Risk and Asset 21 | Allocation", Springer, 2005. 22 | } 23 | \author{ 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci - "Exercises in Advanced Risk and Portfolio 28 | Management" \url{http://symmys.com/node/170}, "E 36 - Pdf 29 | of the lognormal copula". 30 | 31 | See Meucci's script for "LognormalCopulaPdf.m" 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/LognormalMoments2Parameters.Rd: -------------------------------------------------------------------------------- 1 | \name{LognormalMoments2Parameters} 2 | \alias{LognormalMoments2Parameters} 3 | \title{Computes the mean and standard deviation of a lognormal distribution from its parameters.} 4 | \usage{ 5 | LognormalMoments2Parameters(e, v) 6 | } 7 | \arguments{ 8 | \item{e}{[scalar] expected value of the lognormal 9 | distribution} 10 | 11 | \item{v}{[scalar] variance of the lognormal distribution} 12 | } 13 | \value{ 14 | mu [scalar] expected value of the normal distribution 15 | 16 | sig2 [scalar] variance of the normal distribution 17 | } 18 | \description{ 19 | Computes the mean and standard deviation of a lognormal 20 | distribution from its parameters, as described in A. 21 | Meucci, "Risk and Asset Allocation", Springer, 2005. 22 | 23 | \deqn{\sigma^{2} = \ln \left( 1 + \frac{V}{E^{2}} \right) 24 | , } \deqn{\mu = \ln(E) - \frac{1}{2} \ln \left( 1 + 25 | \frac{V}{E^{2}} \right) .} 26 | } 27 | \note{ 28 | Inverts the formulas (1.98)-(1.99) in "Risk and Asset 29 | Allocation", Springer, 2005. 30 | } 31 | \author{ 32 | Xavier Valls \email{flamejat@gmail.com} 33 | } 34 | \references{ 35 | A. Meucci - "Exercises in Advanced Risk and Portfolio 36 | Management" \url{http://symmys.com/node/170}, "E 25 - 37 | Simulation of a lognormal random variable". 38 | 39 | See Meucci's script for "LognormalMoments2Parameters.m" 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/LognormalParam2Statistics.Rd: -------------------------------------------------------------------------------- 1 | \name{LognormalParam2Statistics} 2 | \alias{LognormalParam2Statistics} 3 | \title{Compute expectation, covariance, standard deviation and correlation for a lognormal distribution.} 4 | \usage{ 5 | LognormalParam2Statistics(Mu, Sigma) 6 | } 7 | \arguments{ 8 | \item{Mu}{: [vector] (N x 1) location parameter} 9 | 10 | \item{Sigma}{: [matrix] (N x N) scale parameter} 11 | } 12 | \value{ 13 | Exp : [vector] (N x 1) expectation 14 | 15 | Cov : [matrix] (N x N) covariance 16 | 17 | Std : [vector] (N x 1) standard deviation 18 | 19 | Corr : [matrix] (N x N) correlation 20 | } 21 | \description{ 22 | Compute expectation, covariance, standard deviation and 23 | correlation for a lognormal distribution, as described in 24 | A. Meucci "Risk and Asset Allocation", Springer, 2005. 25 | } 26 | \author{ 27 | Xavier Valls \email{flamejat@gmail.com} 28 | } 29 | \references{ 30 | A. Meucci - "Exercises in Advanced Risk and Portfolio 31 | Management" \url{http://symmys.com/node/170}, "E 85 - 32 | Correlation in lognormal markets". 33 | 34 | See Meucci's script for "LognormalParam2Statistics.m" 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/LongShortMeanCVaRFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{LongShortMeanCVaRFrontier} 2 | \alias{LongShortMeanCVaRFrontier} 3 | \title{Computes the long-short conditional value at risk frontier as it appears in A. Meucci, 4 | "Fully Flexible Views: Theory and Practice", The Risk Magazine, October 2008, p 100-106} 5 | \usage{ 6 | LongShortMeanCVaRFrontier(PnL, Probs, Butterflies, 7 | Options) 8 | } 9 | \arguments{ 10 | \item{PnL}{Profit and Loss scenarios} 11 | 12 | \item{Probs}{vector of probabilities} 13 | 14 | \item{Butterflies}{list of securities with some analytics 15 | computed.} 16 | 17 | \item{Options}{list of options} 18 | } 19 | \value{ 20 | Exp vector of expected returns for each asset 21 | 22 | SDev vector of security volatilities along the efficient 23 | frontier 24 | 25 | CVaR Conditional Value at Risk for each portfolio 26 | 27 | Composition matrix of compositions (security weights) for 28 | each portfolio along the efficient frontier 29 | } 30 | \description{ 31 | Computes the long-short conditional value at risk 32 | frontier as it appears in A. Meucci, "Fully Flexible 33 | Views: Theory and Practice", The Risk Magazine, October 34 | 2008, p 100-106 35 | } 36 | \author{ 37 | Ram Ahluwalia \email{ram@wingedfootcapital.com}, Xavier 38 | Valls \email{flamejat@gmail.com} 39 | } 40 | \references{ 41 | A. Meucci, "Fully Flexible Views: Theory and Practice" 42 | \url{http://www.symmys.com/node/158} See Meucci script 43 | for "ButterflyTrading/LongShortMeanCVaRFrontier.m" 44 | } 45 | 46 | -------------------------------------------------------------------------------- /man/MaxEntropy.Rd: -------------------------------------------------------------------------------- 1 | \name{MaxEntropy} 2 | \alias{MaxEntropy} 3 | \title{This function computes the extreme frontier} 4 | \usage{ 5 | MaxEntropy(G, w_b, w_0, Constr) 6 | } 7 | \arguments{ 8 | \item{G}{map weights -> conditional diversification 9 | distribution (square root of, not normalized)} 10 | 11 | \item{w_b}{a matrix containing the benchmark weights} 12 | 13 | \item{w_0}{a matrix containing the initial portfolio 14 | weights} 15 | 16 | \item{Constr}{a list containing the equality and 17 | inequality constraints} 18 | } 19 | \value{ 20 | x a numeric containing the maximum entropy 21 | 22 | \deqn{ N_{ent} \equiv exp \big(-\sum_{n=k+1}^N p_{n} ln 23 | p_{n} \big), w_{ \varphi } \equiv argmax_{w \in C, \mu'w 24 | \geq \varphi } N_{ent} \big(w\big) } 25 | } 26 | \description{ 27 | This function computes the extreme frontier 28 | } 29 | \author{ 30 | Manan Shah \email{mkshah@cmu.edu} 31 | } 32 | \references{ 33 | A. Meucci - "Managing Diversification", Risk Magazine, 34 | June 2009 - Formula (18,19) 35 | \url{http://ssrn.com/abstract=1358533} 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/MaxRsqCS.Rd: -------------------------------------------------------------------------------- 1 | \name{MaxRsqCS} 2 | \alias{MaxRsqCS} 3 | \title{Solve for G that maximises sample r-square of X*G'*B' with X under constraints A*G<=D 4 | and Aeq*G=Deq} 5 | \usage{ 6 | MaxRsqCS(X, B, W, A = NULL, D = NULL, Aeq = NULL, Deq, 7 | lb = NULL, ub = NULL) 8 | } 9 | \arguments{ 10 | \item{X}{: [matrix] (T x N)} 11 | 12 | \item{B}{: [matrix] (T x K)} 13 | 14 | \item{W}{: [matrix] (N x N)} 15 | 16 | \item{A}{: [matrix] linear inequality constraints} 17 | 18 | \item{D}{: [matrix]} 19 | 20 | \item{Aeq}{: [matrix] linear equality constraints} 21 | 22 | \item{Deq}{: [matrix]} 23 | 24 | \item{lb}{: [vector] lower bound} 25 | 26 | \item{ub}{: [vector] upper bound} 27 | } 28 | \value{ 29 | G : [matrix] (N x K) 30 | } 31 | \description{ 32 | Solve for G that maximises sample r-square of X*G'*B' 33 | with X under constraints A*G<=D and Aeq*G=Deq (A,D, 34 | Aeq,Deq conformable matrices),as described in A. Meucci, 35 | "Risk and Asset Allocation", Springer, 2005. 36 | } 37 | \note{ 38 | Initial code by Tai-Ho Wang 39 | } 40 | \author{ 41 | Xavier Valls \email{flamejat@gmail.com} 42 | } 43 | \references{ 44 | A. Meucci - "Exercises in Advanced Risk and Portfolio 45 | Management" \url{http://symmys.com/node/170}. Used in "E 46 | 123 - Cross-section factors: generalized cross-section 47 | industry factors". 48 | 49 | See Meucci's script for "MaxRsqCS.m" 50 | } 51 | 52 | -------------------------------------------------------------------------------- /man/MaxRsqTS.Rd: -------------------------------------------------------------------------------- 1 | \name{MaxRsqTS} 2 | \alias{MaxRsqTS} 3 | \title{Solve for B that maximises sample r-square of F'*B' with X under constraints A*G<=D 4 | and Aeq*G=Deq (A,D, Aeq,Deq conformable matrices),as described in A. Meucci, 5 | "Risk and Asset Allocation", Springer, 2005.} 6 | \usage{ 7 | MaxRsqTS(X, F, W, A = NULL, D = NULL, Aeq = NULL, Deq, 8 | lb = NULL, ub = NULL) 9 | } 10 | \arguments{ 11 | \item{X}{: [matrix] (T x N)} 12 | 13 | \item{F}{: [matrix] (T x K)} 14 | 15 | \item{W}{: [matrix] (N x N)} 16 | 17 | \item{A}{: [matrix] linear inequality constraints} 18 | 19 | \item{D}{: [matrix]} 20 | 21 | \item{Aeq}{: [matrix] linear equality constraints} 22 | 23 | \item{Deq}{: [matrix]} 24 | 25 | \item{lb}{: [vector] lower bound} 26 | 27 | \item{ub}{: [vector] upper bound} 28 | } 29 | \value{ 30 | B : [matrix] (N x K) 31 | } 32 | \description{ 33 | Solve for B that maximises sample r-square of F'*B' with 34 | X under constraints A*G<=D and Aeq*G=Deq (A,D, Aeq,Deq 35 | conformable matrices),as described in A. Meucci, "Risk 36 | and Asset Allocation", Springer, 2005. 37 | } 38 | \note{ 39 | Initial MATLAB's code by Tai-Ho Wang. 40 | } 41 | \author{ 42 | Xavier Valls \email{flamejat@gmail.com} 43 | } 44 | \references{ 45 | A. Meucci - "Exercises in Advanced Risk and Portfolio 46 | Management" \url{http://symmys.com/node/170}. See 47 | Meucci's script for "MaxRsqTS.m" 48 | } 49 | 50 | -------------------------------------------------------------------------------- /man/MeanTCEntropyFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{MeanTCEntropyFrontier} 2 | \alias{MeanTCEntropyFrontier} 3 | \title{This function computes the mean diversification efficient frontier} 4 | \usage{ 5 | MeanTCEntropyFrontier(S, Mu, w_b, w_0, Constr) 6 | } 7 | \arguments{ 8 | \item{S}{Covariance Matrix} 9 | 10 | \item{Mu}{a matrix containing the expectations} 11 | 12 | \item{w_b}{a matrix containing the benchmark weights} 13 | 14 | \item{w_0}{a matrix containing the initial portfolio 15 | weights} 16 | 17 | \item{Constr}{a list containing the equality and 18 | inequality constraints} 19 | } 20 | \value{ 21 | a list containing 22 | 23 | Weights 24 | 25 | Ne_s 26 | 27 | R_2_s 28 | 29 | m_s 30 | 31 | s_S 32 | } 33 | \description{ 34 | This function computes the mean diversification efficient 35 | frontier 36 | } 37 | \author{ 38 | Manan Shah \email{mkshah@cmu.edu} 39 | } 40 | \references{ 41 | A. Meucci - "Managing Diversification", Risk Magazine, 42 | June 2009 \url{http://ssrn.com/abstract=1358533} 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/MleRecursionForStudentT.Rd: -------------------------------------------------------------------------------- 1 | \name{MleRecursionForStudentT} 2 | \alias{MleRecursionForStudentT} 3 | \title{Compute recursively the ML estimators of location and scatter of a multivariate Student t distribution with 4 | given degrees of freedom.} 5 | \usage{ 6 | MleRecursionForStudentT(x, Nu, Tolerance = 10^(-10)) 7 | } 8 | \arguments{ 9 | \item{x}{: [matrix] (T x N) observations} 10 | 11 | \item{Nu}{: [scalar] degrees of freedom parameter} 12 | 13 | \item{Tolerance}{: [scalar] tolerance parameter. Default: 14 | 10^(-10)} 15 | } 16 | \value{ 17 | Mu : [vector] (N x 1) mean 18 | 19 | Sigma : [matrix] (N x N) covariance 20 | } 21 | \description{ 22 | Compute recursively the ML estimators of location and 23 | scatter of a multivariate Student t distribution with 24 | given degrees of freedom, as described in A. Meucci, 25 | "Risk and Asset Allocation", Springer, 2005, section 4.3 26 | - "Maximum likelihood estimators" 27 | 28 | Returns \deqn{ \widehat{\mu} = \sum\limits_{t= 1}^{T} 29 | \frac{w_{t}}{\sum\limits_{s= 1}^{T}w_{s}} x_{t} ,} 30 | \deqn{\widehat{\Sigma} = \frac{1}{T}\sum\limits_{t= 31 | 1}^{T}w_{t}(x_{t}-\widehat{\mu})(x_{t}-\widehat{\mu})^\prime} 32 | 33 | where, adapted to the Sudent T distribution, \deqn{ 34 | w_{t}\equiv \frac{\nu+N}{\nu+(x_{t}-\widehat{\mu})^\prime 35 | \widehat{\Sigma}^{-1}( x-\widehat{\mu}) }} 36 | } 37 | \author{ 38 | Xavier Valls \email{flamejat@gmail.com} 39 | } 40 | \references{ 41 | A. Meucci - "Exercises in Advanced Risk and Portfolio 42 | Management" \url{http://symmys.com/node/170}, "E 188 - 43 | Maximum likelihood estimation of a multivariate Student t 44 | distribution". 45 | 46 | See Meucci's script for "MleRecursionForStudentT.m" 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/MvnRnd.Rd: -------------------------------------------------------------------------------- 1 | \name{MvnRnd} 2 | \alias{MvnRnd} 3 | \title{Generate normal simulations whose sample moments match the population moments} 4 | \usage{ 5 | MvnRnd(M, S, J) 6 | } 7 | \arguments{ 8 | \item{M}{: [vector] (N x 1) expectation} 9 | 10 | \item{S}{: [matrix] (N x N) covariance matrix} 11 | 12 | \item{J}{: [scalar] number of draws (even number)} 13 | } 14 | \value{ 15 | X : [matrix] (J x N) of drawsF_U : [vector] (J x 1) PDF 16 | values 17 | } 18 | \description{ 19 | Generate normal simulations whose sample moments match 20 | the population moments, as described in A. Meucci, "Risk 21 | and Asset Allocation", Springer, 2005. 22 | } 23 | \author{ 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci - "Exercises in Advanced Risk and Portfolio 28 | Management" \url{http://symmys.com/node/170}, "E 64 - 29 | Simulation of a multivariate normal random variable with 30 | matching moments". 31 | 32 | See Meucci's script for "MvnRnd.m". 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/NoisyObservations.Rd: -------------------------------------------------------------------------------- 1 | \name{NoisyObservations} 2 | \alias{NoisyObservations} 3 | \title{Generate observations from a two asset covariance matrix and add outliers} 4 | \usage{ 5 | NoisyObservations(numGoodSamples, numOutliers, 6 | covarianceMatrix, shuffle = FALSE) 7 | } 8 | \arguments{ 9 | \item{numGoodSamples}{number of observations drawn from 10 | the covariance matrix} 11 | 12 | \item{numOutliers}{number of outliers added to sample} 13 | 14 | \item{covarianceMatrix}{the covariance matrix for the 15 | asset returns from which good samples will be drawn} 16 | 17 | \item{shuffle}{a boolean suggesting whether order of the 18 | twos should be shuffled} 19 | } 20 | \value{ 21 | sample a matrix of returns consisting of good and bad 22 | sample. Rows are observations, columns are the assets. 23 | } 24 | \description{ 25 | Generate observations from a covariance matrix and add 26 | outliers 27 | } 28 | \author{ 29 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/NormalCopulaPdf.Rd: -------------------------------------------------------------------------------- 1 | \name{NormalCopulaPdf} 2 | \alias{NormalCopulaPdf} 3 | \title{Computes the pdf of the copula of the normal distribution at the generic point u in the unit hypercube} 4 | \usage{ 5 | NormalCopulaPdf(u, Mu, Sigma) 6 | } 7 | \arguments{ 8 | \item{u}{[vector] (J x 1) grade} 9 | 10 | \item{Mu}{[vector] (N x 1) mean} 11 | 12 | \item{Sigma}{[matrix] (N x N) covariance} 13 | } 14 | \value{ 15 | F_U [vector] (J x 1) PDF values 16 | } 17 | \description{ 18 | Computes the pdf of the copula of the normal distribution 19 | at the generic point u in the unit hypercube, as 20 | described in A. Meucci, "Risk and Asset Allocation", 21 | Springer, 2005. 22 | } 23 | \author{ 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci - "Exercises in Advanced Risk and Portfolio 28 | Management" \url{http://symmys.com/node/170}, "E 33 - Pdf 29 | of the normal copula". 30 | 31 | See Meucci's script for "NormalCopulaPdf.m" 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/OUstep.Rd: -------------------------------------------------------------------------------- 1 | \name{OUstep} 2 | \alias{OUstep} 3 | \title{Generate the next element based on Ornstein-Uhlenbeck Process} 4 | \usage{ 5 | OUstep(X_0, t, Mu, Th, Sig) 6 | } 7 | \arguments{ 8 | \item{X_0}{a matrix containing the starting value of each 9 | process} 10 | 11 | \item{t}{a numeric containing the timestep} 12 | 13 | \item{Mu}{a vector containing the unconditional 14 | expectation of the process} 15 | 16 | \item{Th}{a transition matrix, i.e., a fully generic 17 | square matrix that steers the deterministic portion of 18 | the evolution of the process} 19 | 20 | \item{Sig}{a square matrix that drives the dispersion of 21 | the process} 22 | } 23 | \value{ 24 | a list containing 25 | 26 | X_t a vector containing the value of the process after 27 | the given timestep 28 | 29 | Mu_t a vector containing the conditional expectation of 30 | the process 31 | 32 | Sig_t a matrix containing the covariance after the time 33 | step 34 | 35 | \deqn{ X_{t+ \tau } = \big(I- e^{- \theta \tau } \big) 36 | \mu + e^{- \theta \tau } X_{t} + \epsilon _{t, \tau } } 37 | } 38 | \description{ 39 | Generate the next element based on Ornstein-Uhlenbeck 40 | Process 41 | } 42 | \author{ 43 | Manan Shah \email{mkshah@cmu.edu} 44 | } 45 | \references{ 46 | A. Meucci - "Review of Statistical Arbitrage, 47 | Cointegration, and Multivariate Ornstein-Uhlenbeck" - 48 | Formula (2) \url{http://ssrn.com/abstract=1404905} 49 | } 50 | 51 | -------------------------------------------------------------------------------- /man/OUstepEuler.Rd: -------------------------------------------------------------------------------- 1 | \name{OUstepEuler} 2 | \alias{OUstepEuler} 3 | \title{Generate the next element based on Ornstein-Uhlenbeck process using antithetic concept and assuming that the 4 | Brownian motion has Euler discretization} 5 | \usage{ 6 | OUstepEuler(X_0, Dt, Mu, Th, Sig) 7 | } 8 | \arguments{ 9 | \item{X_0}{a matrix containing the starting value of each 10 | process} 11 | 12 | \item{Dt}{a numeric containing the timestep} 13 | 14 | \item{Mu}{a vector containing the unconditional 15 | expectation of the process} 16 | 17 | \item{Th}{a transition matrix, i.e., a fully generic 18 | square matrix that steers the deterministic portion of 19 | the evolution of the process} 20 | 21 | \item{Sig}{a square matrix that drives the dispersion of 22 | the process} 23 | } 24 | \value{ 25 | a list containing 26 | 27 | X_t a vector containing the value of the process after 28 | the given timestep 29 | 30 | Mu_t a vector containing the conditional expectation of 31 | the process 32 | 33 | Sig_t a matrix containing the covariance after the time 34 | step 35 | 36 | \deqn{ X_{t+ \tau } = \big(I- e^{- \theta \tau } \big) 37 | \mu + e^{- \theta \tau } X_{t} + \epsilon _{t, \tau } } 38 | } 39 | \description{ 40 | Generate the next element based on Ornstein-Uhlenbeck 41 | process using antithetic concept and assuming that the 42 | Brownian motion has Euler discretization 43 | } 44 | \author{ 45 | Manan Shah \email{mkshah@cmu.edu} 46 | } 47 | \references{ 48 | A. Meucci - "Review of Statistical Arbitrage, 49 | Cointegration, and Multivariate Ornstein-Uhlenbeck" - 50 | Formula (2) \url{http://ssrn.com/abstract=1404905} 51 | } 52 | 53 | -------------------------------------------------------------------------------- /man/PanicCopula.Rd: -------------------------------------------------------------------------------- 1 | \name{PanicCopula} 2 | \alias{PanicCopula} 3 | \title{Copula-Marginal Algorithm (CMA)} 4 | \usage{ 5 | PanicCopula(N = 20, J = 50000, r_c = 0.3, r = 0.99, 6 | b = 0.02, sig = 0.2, sigma) 7 | } 8 | \arguments{ 9 | \item{N}{number of assets} 10 | 11 | \item{J}{number of samples from joint distribution of 12 | asset returns} 13 | 14 | \item{r_c}{average correlation in a calm market} 15 | 16 | \item{r}{average correlation in a panic market} 17 | 18 | \item{b}{probability of a panic market occurring} 19 | 20 | \item{sigma}{covariance matrix of asset returns} 21 | 22 | \item{sig}{TBD} 23 | } 24 | \value{ 25 | a list with: copula a couplua hist a object of type 26 | histogram p_ the revised probabilities (invisible) 27 | meanReturn the mean return for the portfolio given the 28 | views varianceReturn the variance of the portfolio 29 | returns 30 | } 31 | \description{ 32 | Copula-Marginal Algorithm (CMA) to generate and 33 | manipulate flexible copulas, as described in Meucci A., 34 | "New Breed of Copulas for Risk and Portfolio Management", 35 | Risk, September 2011 Most recent version of article and 36 | code available at http://www.symmys.com/node/335 37 | } 38 | \examples{ 39 | PanicCopula( N = 20 , J = 50000 , r_c = .3 , r = .99 , b = .02 , sig = .2 , sigma ) 40 | } 41 | \author{ 42 | Ram Ahluwalia \email{rahluwalia@gmail.com} 43 | } 44 | \references{ 45 | \url{http://www.symmys.com} 46 | } 47 | 48 | -------------------------------------------------------------------------------- /man/PerformIidAnalysis.Rd: -------------------------------------------------------------------------------- 1 | \name{PerformIidAnalysis} 2 | \alias{PerformIidAnalysis} 3 | \title{Performs simple invariance (i.i.d.) tests on a time series.} 4 | \usage{ 5 | PerformIidAnalysis(Dates = dim(Data)[1], Data, Str = "") 6 | } 7 | \arguments{ 8 | \item{Dates}{: [vector] (T x 1) dates} 9 | 10 | \item{Data}{: [matrix] (T x N) data} 11 | 12 | \item{Str}{: [string] title for the plot} 13 | } 14 | \description{ 15 | This function performs simple invariance (i.i.d.) tests 16 | on a time series, as described in A. Meucci "Risk and 17 | Asset Allocation", Springer, 2005 18 | } 19 | \note{ 20 | it checks the evolution over time 21 | 22 | it checks that the variables are identically distributed 23 | by looking at the histogram of two subsamples 24 | 25 | it checks that the variables are independent by looking 26 | at the 1-lag scatter plot 27 | 28 | under i.i.d. the location-dispersion ellipsoid should be 29 | a circle 30 | } 31 | \author{ 32 | Xavier Valls \email{flamejat@gmail.com} 33 | } 34 | \references{ 35 | A. Meucci - "Exercises in Advanced Risk and Portfolio 36 | Management" \url{http://symmys.com/node/170}. 37 | 38 | See Meucci's script for "PerformIidAnalysis.m" 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/PlotCompositionEfficientFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotCompositionEfficientFrontier} 2 | \alias{PlotCompositionEfficientFrontier} 3 | \title{Plots the efficient frontier} 4 | \usage{ 5 | PlotCompositionEfficientFrontier(Portfolios) 6 | } 7 | \arguments{ 8 | \item{Portfolios}{: [matrix] (M x N) M portfolios of size 9 | N (weights)} 10 | } 11 | \description{ 12 | Plot the efficient frontier, as described in A. Meucci, 13 | "Risk and Asset Allocation", Springer, 2005. 14 | } 15 | \author{ 16 | Xavier Valls \email{flamejat@gmail.com} 17 | } 18 | \references{ 19 | A. Meucci - "Exercises in Advanced Risk and Portfolio 20 | Management" \url{http://symmys.com/node/170}. 21 | 22 | See Meucci's script for 23 | "PlotCompositionEfficientFrontier.m" 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/PlotDistributions.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotDistributions} 2 | \alias{PlotDistributions} 3 | \title{Plot numerical and analytical prior and posterior distributions} 4 | \usage{ 5 | PlotDistributions(X, p, Mu, Sigma, p_, Mu_, Sigma_) 6 | } 7 | \arguments{ 8 | \item{X}{a vector containing the dataset} 9 | 10 | \item{p}{a vector cotaining the prior probability values} 11 | 12 | \item{Mu}{a vector containing the prior means} 13 | 14 | \item{Sigma}{a vector containing the prior standard 15 | deviations} 16 | 17 | \item{p_}{a vector containing the posterior probability 18 | values} 19 | 20 | \item{Mu_}{a vector containing the posterior means} 21 | 22 | \item{Sigma_}{a vector containing the posterior standard 23 | deviations} 24 | } 25 | \description{ 26 | Plot numerical and analytical prior and posterior 27 | distributions 28 | } 29 | \author{ 30 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 31 | } 32 | \references{ 33 | A. Meucci, "Fully Flexible Views: Theory and Practice" 34 | \url{http://www.symmys.com/node/158} See Meucci script 35 | for "PlotDistributions.m" 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/PlotFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotFrontier} 2 | \alias{PlotFrontier} 3 | \title{Plots the efficient frontier, as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", The Risk Magazine, 4 | October 2008, p 100-106.} 5 | \usage{ 6 | PlotFrontier(e, s, w) 7 | } 8 | \arguments{ 9 | \item{e}{the NumPortf x 1 matrix of expected returns for 10 | each portfolio along the efficient frontier} 11 | 12 | \item{s}{the NumPortf x 1 matrix of standard deviation of 13 | returns for each portfolio along the efficient frontier} 14 | 15 | \item{w}{the NumPortf x N matrix of compositions 16 | (security weights) for each portfolio along the efficient 17 | frontier} 18 | } 19 | \description{ 20 | Plots the efficient frontier, as it appears in A. Meucci, 21 | "Fully Flexible Views: Theory and Practice", The Risk 22 | Magazine, October 2008, p 100-106. 23 | } 24 | \author{ 25 | Xavier Valls \email{flamejat@gmail.com} 26 | } 27 | \references{ 28 | A. Meucci, "Fully Flexible Views: Theory and Practice" 29 | \url{http://www.symmys.com/node/158} See Meucci script 30 | for "RankingInformation/PlotFrontier.m" 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/PlotMarginalsNormalInverseWishart.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotMarginalsNormalInverseWishart} 2 | \alias{PlotMarginalsNormalInverseWishart} 3 | \title{Plot the marginals of the normal-inverse-Whishart model. 4 | Described in A. Meucci "Risk and Asset Allocation", Springer, 2005} 5 | \usage{ 6 | PlotMarginalsNormalInverseWishart(Mu_Simul, 7 | InvSigma_Simul, Mu_0, T_0, Sigma_0, Nu_0, Legend) 8 | } 9 | \arguments{ 10 | \item{Mu_Simul}{[]} 11 | 12 | \item{InvSigma_Simul}{[]} 13 | 14 | \item{Mu_0}{[]} 15 | 16 | \item{T_0}{[]} 17 | 18 | \item{Sigma_0}{[]} 19 | 20 | \item{Nu_0}{[]} 21 | 22 | \item{Legend}{[]} 23 | } 24 | \description{ 25 | Plot the marginals of the normal-inverse-Whishart model. 26 | Described in A. Meucci "Risk and Asset Allocation", 27 | Springer, 2005 28 | } 29 | \note{ 30 | Numerically and analytically the marginal pdf of - the 31 | first entry of the random vector Mu - the (1,1)-entry of 32 | the random matrix inv(Sigma) when Mu and Sigma are 33 | jointly normal-inverse-Wishart: Mu ~ St(Mu_0,Sigma/T_0) 34 | inv(Sigma) ~ W(Nu_0,inv(Sigma_0)/Nu_0) 35 | } 36 | \author{ 37 | Xavier Valls \email{flamejat@gmail.com} 38 | } 39 | \references{ 40 | A. Meucci - "Exercises in Advanced Risk and Portfolio 41 | Management" \url{http://symmys.com/node/170}. 42 | 43 | See Meucci's script for 44 | "PlotMarginalsNormalInverseWishart.m" 45 | } 46 | 47 | -------------------------------------------------------------------------------- /man/PlotResults.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotResults} 2 | \alias{PlotResults} 3 | \title{Plots the results of computing the efficient frontier (Expected returns and frontier), as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", The Risk Magazine, 4 | October 2008, p 100-106.} 5 | \usage{ 6 | PlotResults(e, s, w, M, Lower = NULL, Upper = NULL) 7 | } 8 | \arguments{ 9 | \item{e}{the NumPortf x 1 matrix of expected returns for 10 | each portfolio along the efficient frontier} 11 | 12 | \item{s}{the NumPortf x 1 matrix of standard deviation of 13 | returns for each portfolio along the efficient frontier} 14 | 15 | \item{w}{the NumPortf x N matrix of compositions 16 | (security weights) for each portfolio along the efficient 17 | frontier} 18 | 19 | \item{M}{the NumPortf x 1 vector of expected returns for 20 | each asset} 21 | 22 | \item{Lower}{constraints} 23 | 24 | \item{Upper}{constraints} 25 | } 26 | \description{ 27 | Plots the results of computing the efficient frontier 28 | (Expected returns and frontier), as it appears in A. 29 | Meucci, "Fully Flexible Views: Theory and Practice", The 30 | Risk Magazine, October 2008, p 100-106. 31 | } 32 | \author{ 33 | Xavier Valls \email{flamejat@gmail.com} 34 | } 35 | \references{ 36 | A. Meucci, "Fully Flexible Views: Theory and Practice" 37 | \url{http://www.symmys.com/node/158} See Meucci script 38 | for "RankingInformation/PlotResults.m" 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/PlotVolVsCompositionEfficientFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{PlotVolVsCompositionEfficientFrontier} 2 | \alias{PlotVolVsCompositionEfficientFrontier} 3 | \title{Plot the efficient frontier in the plane of portfolio weights versus standard deviation, 4 | as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005.} 5 | \usage{ 6 | PlotVolVsCompositionEfficientFrontier(Portfolios, vol) 7 | } 8 | \arguments{ 9 | \item{Portfolios}{: [matrix] (M x N) of portfolios 10 | weights} 11 | 12 | \item{vol}{: [vector] (M x 1) of volatilities} 13 | } 14 | \description{ 15 | Plot the efficient frontier in the plane of portfolio 16 | weights versus standard deviation, as described in A. 17 | Meucci, "Risk and Asset Allocation", Springer, 2005. 18 | } 19 | \author{ 20 | Xavier Valls \email{flamejat@gmail.com} 21 | } 22 | \references{ 23 | A. Meucci - "Exercises in Advanced Risk and Portfolio 24 | Management" \url{http://symmys.com/node/170}. See 25 | Meucci's script for 26 | "PlotVolVsCompositionEfficientFrontier.m" 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/Prior2Posterior.Rd: -------------------------------------------------------------------------------- 1 | \name{Prior2Posterior} 2 | \alias{Prior2Posterior} 3 | \title{Calculate the full-confidence posterior distributions of Mu and Sigma} 4 | \usage{ 5 | Prior2Posterior(M, Q, M_Q, S, G, S_G) 6 | } 7 | \arguments{ 8 | \item{M}{a numeric vector with the Mu of the normal 9 | reference model} 10 | 11 | \item{Q}{a numeric vector used to construct a view on 12 | expectation of the linear combination QX} 13 | 14 | \item{M_Q}{a numeric vector with the view of the 15 | expectations of QX} 16 | 17 | \item{S}{a covariance matrix for the normal reference 18 | model} 19 | 20 | \item{G}{a numeric vector used to construct a view on 21 | covariance of the linear combination GX} 22 | 23 | \item{S_G}{a numeric with the expectation associated with 24 | the covariance of the linear combination GX} 25 | } 26 | \value{ 27 | a list with 28 | 29 | M_ a numeric vector with the full-confidence posterior 30 | distribution of Mu 31 | 32 | S_ a covariance matrix with the full-confidence posterior 33 | distribution of Sigma 34 | } 35 | \description{ 36 | \deqn{ \tilde{ \mu } \equiv \mu + \Sigma Q' {\big(Q 37 | \Sigma Q' \big)}^{-1} \big( \tilde{\mu}_{Q} - Q \mu 38 | \big), \\ \tilde{ \Sigma } \equiv \Sigma + \Sigma G' 39 | \big({\big(G \Sigma G' \big)}^{-1} \tilde{ \Sigma }_G 40 | {\big(G \Sigma G' \big)}^{-1} - {\big(G \Sigma G' 41 | \big)}^{-1} \big) G \Sigma } 42 | } 43 | \author{ 44 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 45 | } 46 | \references{ 47 | \url{http://www.symmys.com/node/158} 48 | \url{http://ssrn.com/abstract=1213325} A. Meucci - "Fully 49 | Flexible Views: Theory and Practice". See formula (21) 50 | and (22) on page 7 See Meucci script Prior2Posterior.m 51 | attached to Entropy Pooling Paper 52 | } 53 | 54 | -------------------------------------------------------------------------------- /man/ProjectionStudentT.Rd: -------------------------------------------------------------------------------- 1 | \name{ProjectionStudentT} 2 | \alias{ProjectionStudentT} 3 | \title{Perform the horizon projection of a Student t invariant} 4 | \usage{ 5 | ProjectionStudentT(nu, m, s, T) 6 | } 7 | \arguments{ 8 | \item{nu}{[scalar] degree of freedom} 9 | 10 | \item{s}{[scalar] scatter parameter} 11 | 12 | \item{m}{[scalar] location parameter} 13 | 14 | \item{T}{[scalar] multiple of the estimation period to 15 | the invesment horizon} 16 | } 17 | \value{ 18 | x_Hor [scalar] probabilities at horizon 19 | 20 | f_Hor [scalar] horizon discretized pdf (non-standarized) 21 | 22 | F_Hor [scalar] horizon discretized cdf (non-standarized) 23 | } 24 | \description{ 25 | Perform the horizon projection of a Student t invariant, 26 | as described in A. Meucci "Risk and Asset Allocation", 27 | Springer, 2005 28 | } 29 | \author{ 30 | Xavier Valls \email{flamejat@gmail.com} 31 | } 32 | \references{ 33 | A. Meucci - "Exercises in Advanced Risk and Portfolio 34 | Management" \url{http://symmys.com/node/170}, "E 141 - 35 | Fixed-income market: projection of Student t invariants". 36 | 37 | See Meucci's script for "ProjectionStudentT.m" 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/QuantileMixture.Rd: -------------------------------------------------------------------------------- 1 | \name{QuantileMixture} 2 | \alias{QuantileMixture} 3 | \title{Computes the quantile of a mixture distribution by linear interpolation/extrapolation of the cdf.} 4 | \usage{ 5 | QuantileMixture(p, a, m_Y, s_Y, m_Z, s_Z) 6 | } 7 | \arguments{ 8 | \item{p}{[scalar] in [0,1], probability} 9 | 10 | \item{a}{[scalar] in (0,1), mixing probability} 11 | 12 | \item{m_Y}{[scalar] mean of normal component} 13 | 14 | \item{s_Y}{[scalar] standard deviation of normal 15 | component} 16 | 17 | \item{m_Z}{[scalar] first parameters of the log-normal 18 | component} 19 | 20 | \item{s_Z}{[scalar] second parameter of the log-normal 21 | component} 22 | } 23 | \value{ 24 | Q [scalar] quantile 25 | } 26 | \description{ 27 | Computes the quantile of a mixture distribution by linear 28 | interpolation/extrapolation of the cdf. The confidence 29 | level p can be vector. If this vector is uniformly 30 | distributed on [0,1] the sample Q is distributed as the 31 | mixture. Described in A. Meucci "Risk and Asset 32 | Allocation", Springer, 2005. 33 | } 34 | \author{ 35 | Xavier Valls \email{flamejat@gmail.com} 36 | } 37 | \references{ 38 | A. Meucci - "Exercises in Advanced Risk and Portfolio 39 | Management" \url{http://symmys.com/node/170}, "E 184 - 40 | Estimation of a quantile of a mixture I". 41 | 42 | See Meucci's script for "QuantileMixture.m" 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/RIEfficientFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{RIEfficientFrontier} 2 | \alias{RIEfficientFrontier} 3 | \title{Generates an efficient frontier based on Meucci's Ranking Information version and returns a A list with 4 | NumPortf efficient portfolios whos returns are equally spaced along the whole range of the efficient frontier, 5 | as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", The Risk Magazine, October 2008, 6 | p 100-106.} 7 | \usage{ 8 | RIEfficientFrontier(X, p, Options) 9 | } 10 | \arguments{ 11 | \item{X}{a matrix with the joint-scenario probabilities 12 | by asset (rows are joint-scenarios, columns are assets)} 13 | 14 | \item{p}{a vector of probabilities associated with each 15 | scenario in matrix X} 16 | 17 | \item{Options}{a list of options....TBD} 18 | } 19 | \value{ 20 | Exps the NumPortf x 1 vector of expected returns for each 21 | asset 22 | 23 | Covs the NumPortf x N vector of security volatilities 24 | along the efficient frontier 25 | 26 | w the NumPortf x N matrix of compositions (security 27 | weights) for each portfolio along the efficient frontier 28 | 29 | e the NumPortf x 1 matrix of expected returns for each 30 | portfolio along the efficient frontier 31 | 32 | s the NumPortf x 1 matrix of standard deviation of 33 | returns for each portfolio along the efficient frontier 34 | } 35 | \description{ 36 | Most recent version of article and MATLAB code available 37 | at http://www.symmys.com/node/158 38 | } 39 | \author{ 40 | Ram Ahluwalia \email{ram@wingedfootcapital.com} and 41 | Xavier Valls \email{flamejat@gmail.com} 42 | } 43 | \references{ 44 | A. Meucci, "Fully Flexible Views: Theory and Practice" 45 | \url{http://www.symmys.com/node/158} See Meucci script 46 | for "RankingInformation/EfficientFrontier.m" 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/RandNormalInverseWishart.Rd: -------------------------------------------------------------------------------- 1 | \name{RandNormalInverseWishart} 2 | \alias{RandNormalInverseWishart} 3 | \title{Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution.} 4 | \usage{ 5 | RandNormalInverseWishart(Mu_0, T_0, Sigma_0, nu_0, J) 6 | } 7 | \arguments{ 8 | \item{Mu_0}{[vector] location parameter.} 9 | 10 | \item{T_0}{[scalar] number of observations.} 11 | 12 | \item{Sigma_0}{[matrix] scatter parameter.} 13 | 14 | \item{nu_0}{[scalar] degrees of freedom.} 15 | 16 | \item{J}{[scalar] number of simulations to compute.} 17 | } 18 | \value{ 19 | Mu [vector] location parameter from the 20 | normal-inverse-Wishart distribution. 21 | 22 | Sigma [matrix] dispersion parameter from the 23 | normal-inverse-Wishart distribution. 24 | 25 | InvSigma [matrix] inverse of the dispersion parameter 26 | from the normal-inverse-Wishart distribution. 27 | } 28 | \description{ 29 | Generates a multivariate i.i.d. sample of lenght J from 30 | the normal-inverse-Wishart distribution, as described in 31 | A. Meucci "Risk and Asset Allocation", Springer, 2005. 32 | } 33 | \note{ 34 | \deqn{\mu\| \Sigma \sim N(\mu_{0}, \frac{\Sigma}{T_{0}}) 35 | }{Mu|Sigma ~ N(Mu_0,Sigma/T_0)} \deqn{\Sigma^{-1} \sim 36 | W(\nu_{0},\frac{\Sigma_{0}^{-1}}{\nu_{0}})}{inv(Sigma) ~ 37 | W(Nu_0,inv(Sigma_0)/Nu_0)} 38 | } 39 | \author{ 40 | Xavier Valls \email{flamejat@gmail.com} 41 | } 42 | \references{ 43 | A. Meucci - "Exercises in Advanced Risk and Portfolio 44 | Management" \url{http://symmys.com/node/170}. See 45 | Meucci's script for "RandNormalInverseWishart.m" 46 | } 47 | 48 | -------------------------------------------------------------------------------- /man/Raw2Central.Rd: -------------------------------------------------------------------------------- 1 | \name{Raw2Central} 2 | \alias{Raw2Central} 3 | \title{Transforms the first n raw moments into the first n central moments} 4 | \usage{ 5 | Raw2Central(mu_) 6 | } 7 | \arguments{ 8 | \item{mu_}{: [vector] (length N corresponding to order N) 9 | corresponding raw moments} 10 | } 11 | \value{ 12 | mu : [vector] (length N corresponding to order N) central 13 | moments 14 | } 15 | \description{ 16 | Step 6 of projection process: 17 | } 18 | \details{ 19 | compute multi-period central moments. 20 | 21 | Note the first central moment defined as expectation. 22 | 23 | \deqn{\tilde{ \mu } ^ {\big(n\big)} _{X} \equiv E \big\{ 24 | X^{n} \big\}, \\ \mu ^{ \big(n\big) }_{X} \equiv 25 | \sum_0^{n-1} \big(-1\big)^{n-k} \mu ^{n-k}_{X} \tilde{ 26 | \mu }^{k}_{X} + \tilde{ \mu }_{X}^{n} } 27 | } 28 | \author{ 29 | Ram Ahluwalia \email{rahluwalia@gmail.com} 30 | } 31 | \references{ 32 | A. Meucci - "Exercises in Advanced Risk and Portfolio 33 | Management" \url{http://symmys.com/node/170}, "E 16- Raw 34 | Moments to central moments". 35 | 36 | See Meucci's script for "Raw2Central.m" 37 | } 38 | 39 | -------------------------------------------------------------------------------- /man/Raw2Cumul.Rd: -------------------------------------------------------------------------------- 1 | \name{Raw2Cumul} 2 | \alias{Raw2Cumul} 3 | \title{Transforms raw moments into cumulants} 4 | \usage{ 5 | Raw2Cumul(mu_) 6 | } 7 | \arguments{ 8 | \item{mu_}{: [vector] (length N corresponding to order N) 9 | corresponding raw moments} 10 | } 11 | \value{ 12 | ka : [vector] (length N corresponding to order N) 13 | cumulative moments 14 | } 15 | \description{ 16 | Step 3 of the projection process: From the non-central 17 | moments of X-t, we compute the cumulants. 18 | } 19 | \details{ 20 | This process follows from the Taylor approximations for 21 | any small z and ln(1+x)~x for any small x, and from the 22 | definition of the first cumulant in (17). The we apply 23 | recursively the identity in formula (21). See Kendall and 24 | Stuart (1969) 25 | 26 | \deqn{ \kappa^{ \big(n\big) }_{X} \equiv \tilde{ \mu } ^{ 27 | \big(n\big) }_{X} - \sum_{k=1}^{n-1} (n-1)C_{k-1} 28 | \kappa_{X}^{ \big(k\big) } \tilde{ \mu } ^{n-k}_{X} } 29 | } 30 | \author{ 31 | Ram Ahluwalia \email{rahluwalia@gmail.com} 32 | } 33 | \references{ 34 | A. Meucci - "Annualization and General Projection of 35 | Skewness, Kurtosis and All Summary Statistics" - formula 36 | (21) Symmys site containing original MATLAB source code 37 | \url{http://www.symmys.com/node/136} 38 | 39 | A. Meucci - "Exercises in Advanced Risk and Portfolio 40 | Management" \url{http://symmys.com/node/170}. See 41 | Meucci's script for "Raw2Cumul.m" 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/RejectOutlier.Rd: -------------------------------------------------------------------------------- 1 | \name{RejectOutlier} 2 | \alias{RejectOutlier} 3 | \title{Finds the "worst" outlier in a multivariate time series} 4 | \usage{ 5 | RejectOutlier(sample) 6 | } 7 | \arguments{ 8 | \item{sample}{a vector containing the input dataset with 9 | outliers} 10 | } 11 | \value{ 12 | rejected a numeric indicating which observation in the 13 | index to reject 14 | } 15 | \description{ 16 | Finds the "worst" outlier in a multivariate time-series 17 | We aim at finding the the observation x_t such that if we 18 | remove it from the set {x_1 ... x_t } the determinant of 19 | the resulting sample covariance is reduced the most This 20 | means that by dropping that observation the 21 | location-dispersion ellipsoid defined by the sample mean 22 | and covariance shrinks the most See Sec. 4.6.1 of "Risk 23 | and Asset Allocation" - Springer (2005), by A. Meucci for 24 | the theory and the routine implemented below 25 | } 26 | \author{ 27 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 28 | } 29 | \references{ 30 | \url{http://www.symmys.com} See Meucci script for 31 | "RejectOutlier.m" 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/SimulateJumpDiffusionMerton.Rd: -------------------------------------------------------------------------------- 1 | \name{SimulateJumpDiffusionMerton} 2 | \alias{SimulateJumpDiffusionMerton} 3 | \title{Simulates a Merton jump-diffusion process.} 4 | \usage{ 5 | SimulateJumpDiffusionMerton(m, s, l, a, D, ts, J) 6 | } 7 | \arguments{ 8 | \item{m}{[scalar] deterministic drift of diffusion} 9 | 10 | \item{s}{[scalar] standard deviation of diffusion} 11 | 12 | \item{l}{[scalar] Poisson process arrival rate} 13 | 14 | \item{a}{[scalar] drift of log-jump} 15 | 16 | \item{D}{[scalar] st.dev of log-jump} 17 | 18 | \item{ts}{[vector] time steps} 19 | 20 | \item{J}{[scalar] number of simulations} 21 | } 22 | \value{ 23 | X [matrix] (J x length(ts)) of simulations 24 | } 25 | \description{ 26 | This function simulates a jump diffusion process, as 27 | described in A. Meucci "Risk and Asset Allocation", 28 | Springer, 2005. 29 | } 30 | \author{ 31 | Xavier Valls \email{flamejat@gmail.com} 32 | } 33 | \references{ 34 | A. Meucci - "Exercises in Advanced Risk and Portfolio 35 | Management" \url{http://symmys.com/node/170}, "E 132 - 36 | Simulation of a jump-diffusion process". 37 | 38 | See Meucci's script for "SimulateJumpDiffusionMerton.m" 39 | 40 | Merton, R. C., 1976. "Option pricing when underlying 41 | stocks are discontinuous". Journal of Financial Economics 42 | 3, 125-144. 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/StockSeries.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{StockSeries} 3 | \alias{StockSeries} 4 | \title{Stock Series} 5 | \description{ 6 | Stock Series 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/StudentTCopulaPdf.Rd: -------------------------------------------------------------------------------- 1 | \name{StudentTCopulaPdf} 2 | \alias{StudentTCopulaPdf} 3 | \title{Pdf of the copula of the Student t distribution at the generic point u in the unit hypercube} 4 | \usage{ 5 | StudentTCopulaPdf(u, nu, Mu, Sigma) 6 | } 7 | \arguments{ 8 | \item{u}{: [vector] (J x 1) grade} 9 | 10 | \item{nu}{: [numerical] degrees of freedom} 11 | 12 | \item{Mu}{: [vector] (N x 1) mean} 13 | 14 | \item{Sigma}{: [matrix] (N x N) scatter} 15 | } 16 | \value{ 17 | F_U : [vector] (J x 1) PDF values 18 | } 19 | \description{ 20 | Pdf of the copula of the Student t distribution at the 21 | generic point u in the unit hypercube, as described in A. 22 | Meucci, "Risk and Asset Allocation", Springer, 2005. 23 | } 24 | \author{ 25 | Xavier Valls \email{flamejat@gmail.com} 26 | } 27 | \references{ 28 | A. Meucci - "Exercises in Advanced Risk and Portfolio 29 | Management" \url{http://symmys.com/node/170}, "E 88 - 30 | Copula vs. Correlation". 31 | 32 | See Meucci's script for "StudentTCopulaPdf.m" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/SummStats.Rd: -------------------------------------------------------------------------------- 1 | \name{SummStats} 2 | \alias{SummStats} 3 | \title{Compute summary stats} 4 | \usage{ 5 | SummStats(X, N) 6 | } 7 | \arguments{ 8 | \item{X}{an invariant} 9 | 10 | \item{N}{the number of order statistics to collect} 11 | } 12 | \value{ 13 | ga standardized statistics 14 | 15 | mu central moments 16 | } 17 | \description{ 18 | Step 0 in projection process: Compute summary stats 19 | (mean, skew, kurtosis, etc.) of the invariant X-t step 1 20 | in the project process We collect the first 'n' central 21 | moments of the invariant X-t. 22 | } 23 | \author{ 24 | Ram Ahluwalia \email{rahluwalia@gmail.com} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/TimeSeries.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{TimeSeries} 3 | \alias{TimeSeries} 4 | \title{Time Series} 5 | \description{ 6 | Time Series 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/Tweak.Rd: -------------------------------------------------------------------------------- 1 | \name{Tweak} 2 | \alias{Tweak} 3 | \title{tweak a matrix} 4 | \usage{ 5 | Tweak(A, b, g) 6 | } 7 | \arguments{ 8 | \item{A}{matrix A consisting of inequality constraints ( 9 | Ax <= b )} 10 | 11 | \item{b}{matrix b consisting of inequality constraint 12 | vector b ( Ax <= b )} 13 | 14 | \item{g}{TODO: TBD} 15 | } 16 | \value{ 17 | db 18 | } 19 | \description{ 20 | tweak a matrix 21 | } 22 | \author{ 23 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/TwoDimEllipsoid.Rd: -------------------------------------------------------------------------------- 1 | \name{TwoDimEllipsoid} 2 | \alias{TwoDimEllipsoid} 3 | \title{Computes the location-dispersion ellipsoid of the normalized first diagonal and off-diagonal elements 4 | of a 2x2 Wishart distribution as a function of the inputs} 5 | \usage{ 6 | TwoDimEllipsoid(Location, Square_Dispersion, Scale = 1, 7 | PlotEigVectors = FALSE, PlotSquare = FALSE) 8 | } 9 | \arguments{ 10 | \item{Location}{: [vector] (2 x 1) location vector 11 | (typically the expected value} 12 | 13 | \item{Square_Dispersion}{: [matrix] (2 x 2) scatter 14 | matrix Square_Dispersion (typically the covariance 15 | matrix)} 16 | 17 | \item{Scale}{: [scalar] a scalar Scale, that specifies 18 | the scale (radius) of the ellipsoid} 19 | 20 | \item{PlotEigVectors}{: [boolean] true then the 21 | eigenvectors (=principal axes) are plotted} 22 | 23 | \item{PlotSquare}{: [boolean] true then the enshrouding 24 | box is plotted. If Square_Dispersion is the covariance} 25 | } 26 | \value{ 27 | E : [figure handle] 28 | } 29 | \description{ 30 | This function computes the location-dispersion ellipsoid 31 | of the normalized (unit variance, zero expectation)first 32 | diagonal and off-diagonal elements of a 2x2 Wishart 33 | distribution as a function of the inputs, as described in 34 | A. Meucci, "Risk and Asset Allocation", Springer, 2005, 35 | Chapter 2. 36 | } 37 | \author{ 38 | Xavier Valls \email{flamejat@gmail.com} 39 | } 40 | \references{ 41 | A. Meucci - "Exercises in Advanced Risk and Portfolio 42 | Management" \url{http://symmys.com/node/170}. 43 | 44 | See Meucci's script for "TwoDimEllipsoid.m" 45 | } 46 | 47 | -------------------------------------------------------------------------------- /man/UsSwapRates.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{UsSwapRates} 3 | \alias{UsSwapRates} 4 | \title{US Swap Rates} 5 | \description{ 6 | US Swap Rates 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/ViewCurveSlope.Rd: -------------------------------------------------------------------------------- 1 | \name{ViewCurveSlope} 2 | \alias{ViewCurveSlope} 3 | \title{Process views for the expectations and binding constraints as it appears in A. Meucci, 4 | "Fully Flexible Views: Theory and Practice", The Risk Magazine, October 2008, 5 | p 100-106} 6 | \usage{ 7 | ViewCurveSlope(X, p) 8 | } 9 | \arguments{ 10 | \item{X}{: panel of joint factors realizations} 11 | 12 | \item{p}{: vector of probabilities} 13 | } 14 | \value{ 15 | p_ : vector of posterior probabilities 16 | } 17 | \description{ 18 | Process views for the expectations and binding 19 | constraints as it appears in A. Meucci, "Fully Flexible 20 | Views: Theory and Practice", The Risk Magazine, October 21 | 2008, p 100-106 22 | } 23 | \author{ 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci, "Fully Flexible Views: Theory and Practice" 28 | \url{http://www.symmys.com/node/158} See Meucci script 29 | for "ButterflyTrading/ViewCurveSlope.m" 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/ViewImpliedVol.Rd: -------------------------------------------------------------------------------- 1 | \name{ViewImpliedVol} 2 | \alias{ViewImpliedVol} 3 | \title{Process the inequality view, as it appears in A. Meucci, "Fully Flexible Views: Theory and Practice", 4 | The Risk Magazine, October 2008, p 100-106.} 5 | \usage{ 6 | ViewImpliedVol(X, p) 7 | } 8 | \arguments{ 9 | \item{X}{: panel of joint factors realizations} 10 | 11 | \item{p}{: vector of probabilities} 12 | } 13 | \value{ 14 | p_ : vector of posterior probabilities 15 | } 16 | \description{ 17 | Process the inequality view, as it appears in A. Meucci, 18 | "Fully Flexible Views: Theory and Practice", The Risk 19 | Magazine, October 2008, p 100-106. 20 | } 21 | \author{ 22 | Ram Ahluwalia \email{ram@wingedfootcapital.com} and 23 | Xavier Valls \email{flamejat@gmail.com} 24 | } 25 | \references{ 26 | A. Meucci, "Fully Flexible Views: Theory and Practice" 27 | \url{http://www.symmys.com/node/158} See Meucci script 28 | for "ButterflyTrading/ViewRealizedVol.m" 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/ViewRanking.Rd: -------------------------------------------------------------------------------- 1 | \name{ViewRanking} 2 | \alias{ViewRanking} 3 | \title{Computes posterior probabilities to view the rankings, as it appears in A. Meucci, 4 | "Fully Flexible Views: Theory and Practice", The Risk Magazine, October 2008, p 100-106.} 5 | \usage{ 6 | ViewRanking(X, p, Lower, Upper) 7 | } 8 | \arguments{ 9 | \item{X}{a vector containing returns for all the asset 10 | classes} 11 | 12 | \item{p}{a vector containing the prior probability 13 | values} 14 | 15 | \item{Lower}{a vector of indexes indicating which column 16 | is lower than the corresponding column number in Upper} 17 | 18 | \item{Upper}{a vector of indexes indicating which column 19 | is lower than the corresponding column number in Upper} 20 | } 21 | \description{ 22 | Computes posterior probabilities to view the rankings, as 23 | it appears in A. Meucci, "Fully Flexible Views: Theory 24 | and Practice", The Risk Magazine, October 2008, p 25 | 100-106. 26 | } 27 | \author{ 28 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 29 | } 30 | \references{ 31 | A. Meucci, "Fully Flexible Views: Theory and Practice" 32 | \url{http://www.symmys.com/node/158} See Meucci script 33 | for "RankingInformation/ViewRanking.m" 34 | } 35 | 36 | -------------------------------------------------------------------------------- /man/ViewRealizedVol.Rd: -------------------------------------------------------------------------------- 1 | \name{ViewRealizedVol} 2 | \alias{ViewRealizedVol} 3 | \title{Process the relative inequality view on median, as it appears in A. Meucci, 4 | "Fully Flexible Views: Theory and Practice", The Risk Magazine, October 2008, 5 | p 100-106} 6 | \usage{ 7 | ViewRealizedVol(X, p) 8 | } 9 | \arguments{ 10 | \item{X}{: panel of joint factors realizations} 11 | 12 | \item{p}{: vector of probabilities} 13 | } 14 | \value{ 15 | p_ : vector of posterior probabilities 16 | } 17 | \description{ 18 | Process the relative inequality view on median, as it 19 | appears in A. Meucci, "Fully Flexible Views: Theory and 20 | Practice", The Risk Magazine, October 2008, p 100-106 21 | } 22 | \author{ 23 | Ram Ahluwalia \email{ram@wingedfootcapital.com} and 24 | Xavier Valls \email{flamejat@gmail.com} 25 | } 26 | \references{ 27 | A. Meucci, "Fully Flexible Views: Theory and Practice" 28 | \url{http://www.symmys.com/node/158} See Meucci script 29 | for "ButterflyTrading/ViewRealizedVol.m" 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/bondAttribution.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{bondAttribution} 3 | \alias{bondAttribution} 4 | \title{bondAttribution} 5 | \description{ 6 | bondAttribution 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/butterfliesAnalytics.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{butterfliesAnalytics} 3 | \alias{butterfliesAnalytics} 4 | \title{list of securities with analytics computed.} 5 | \description{ 6 | list of securities with analytics computed. 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, "Fully Flexible Views: Theory and Practice", 13 | The Risk Magazine, October 2008, p 100-106. 14 | \url{http://symmys.com/node/158} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/covNRets.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{covNRets} 3 | \alias{covNRets} 4 | \title{covNRets} 5 | \description{ 6 | covNRets 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/db.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{db} 3 | \alias{db} 4 | \title{db} 5 | \description{ 6 | db 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/dbFFP.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{dbFFP} 3 | \alias{dbFFP} 4 | \title{Historical Scenarios with Fully Flexible Probabilities dataset.} 5 | \description{ 6 | Data for the Historical Scenarios with Fully Flexible 7 | Probabilities paper. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, "Personalized Risk Management: Historical 14 | Scenarios with Fully Flexible Probabilities" GARP Risk 15 | Professional, Dec 2010, p 47-51. 16 | \url{http://www.symmys.com/node/150} 17 | } 18 | \keyword{data} 19 | \keyword{datasets} 20 | 21 | -------------------------------------------------------------------------------- /man/db_FX.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{db_FX} 3 | \alias{db_FX} 4 | \title{fX} 5 | \description{ 6 | fX 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/derivatives.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{derivatives} 3 | \alias{derivatives} 4 | \title{implied vol for options on SPX} 5 | \description{ 6 | implied vol for options on SPX for different time to 7 | maturity and moneyness. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, Exercises in Advanced Risk and Portfolio 14 | Management. \url{http://symmys.com/node/170} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/efficientFrontier.Rd: -------------------------------------------------------------------------------- 1 | \name{efficientFrontier} 2 | \alias{efficientFrontier} 3 | \title{Construct the mean-variance efficient frontier using a quadratic solver} 4 | \usage{ 5 | efficientFrontier(discretizations, cov, mu, 6 | longonly = FALSE) 7 | } 8 | \arguments{ 9 | \item{discretizations}{number of portfolios to generate 10 | along efficient frontier (where each portfolio is equally 11 | distanced in return spaced)} 12 | 13 | \item{cov}{arithmetic covariance matrix of asset returns} 14 | 15 | \item{mu}{a vector of arithmetic returns for each asset} 16 | 17 | \item{longonly}{a boolean which constrains weights to > 0 18 | if true} 19 | } 20 | \value{ 21 | a list of portfolios along the frontier from least risky 22 | to most risky The indices in each list correspond to each 23 | other returns the expected portfolio returns along the 24 | frontier volatility the variance of the portfolio along 25 | the frontier weights the weights of the portfolio 26 | components along the frontier 27 | } 28 | \description{ 29 | Construct a number of long-only or long-short portfolios 30 | on the mean-variance efficient frontier where each 31 | portfolio is equally distanced in return space 32 | } 33 | \author{ 34 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 35 | } 36 | \references{ 37 | Attilio Meucci, 2011, Robust Bayesian Allocation 38 | \url{http://papers.ssrn.com/sol3/papers.cfm?abstract_id=681553} 39 | } 40 | \seealso{ 41 | \url{http://symmys.com/node/102} 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/fILMR.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{fILMR} 3 | \alias{fILMR} 4 | \title{Fully Integrated Liquidity and Market Risk Model dataset.} 5 | \description{ 6 | Data for the Fully Integrated Liquidity and Market Risk 7 | Model paper. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, "A Fully Integrated Liquidity and Market Risk 14 | Model", Financial Analyst Journal, 68, 6, 35-47 (2012) 15 | \url{http://www.symmys.com/node/350} 16 | } 17 | \keyword{data} 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/factorsDistribution.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{factorsDistribution} 3 | \alias{factorsDistribution} 4 | \title{Panel X of joint factors realizations and vector p of respective probabilities for factors} 5 | \description{ 6 | Panel X of joint factors realizations and vector p of 7 | respective probabilities for factors 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, "Fully Flexible Views: Theory and Practice", 14 | The Risk Magazine, October 2008, p 100-106. 15 | \url{http://symmys.com/node/158} 16 | } 17 | \keyword{data} 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/fixedIncome.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{fixedIncome} 3 | \alias{fixedIncome} 4 | \title{US government yield curve and bond yield data} 5 | \description{ 6 | US government yield curve and bond yield data for 7 | different dates. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, Exercises in Advanced Risk and Portfolio 14 | Management. \url{http://symmys.com/node/170} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/freaqEst.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{freaqEst} 3 | \alias{freaqEst} 4 | \title{scenarios table and prior distribution for changes in SWAP2YR SWAP10YR CDXIG S&P500 DollarIndex Crude Gold VIX 10YRInflationSwapRate} 5 | \description{ 6 | scenarios table and prior distribution for changes in 7 | SWAP2YR SWAP10YR CDXIG S&P500 DollarIndex Crude Gold VIX 8 | 10YRInflationSwapRate 9 | } 10 | \author{ 11 | Xavier Valls\email{flamejat@gmail.com} 12 | } 13 | \references{ 14 | A. Meucci, "Stress-Testing with Fully Flexible Causal 15 | Inputs" \url{http://symmys.com/node/152} 16 | } 17 | \keyword{data} 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/garch1f4.Rd: -------------------------------------------------------------------------------- 1 | \name{garch1f4} 2 | \alias{garch1f4} 3 | \title{Fit a GARCH(1,1) model with student-t errors} 4 | \usage{ 5 | garch1f4(x, eps, df) 6 | } 7 | \arguments{ 8 | \item{x}{: [vector] (T x 1) data generated by a 9 | GARCH(1,1) process} 10 | 11 | \item{eps}{: [scalar] used in enforcing a_ii + b_ii <= 1 12 | - eps; the default value is zero} 13 | 14 | \item{df}{: [scalar] degree of freedom for the 15 | t-distribution; the default value is 500 to make it, 16 | basically, normal} 17 | } 18 | \value{ 19 | q : [vector] (4 x 1) parameters of the GARCH(1,1) process 20 | 21 | qerr : [vector] (4 x 1) standard error of parameter 22 | estimates 23 | 24 | hf : [scalar] current conditional heteroskedasticity 25 | estimate 26 | 27 | hferr : [scalar] standard error on hf 28 | } 29 | \description{ 30 | Fit a GARCH(1,1) model with student-t errors 31 | } 32 | \note{ 33 | MATLAB's script initially written by Olivier Ledoit, 34 | 4/28/1997 35 | 36 | Uses a conditional t-distribution with fixed degrees of 37 | freedom 38 | 39 | Difference with garch1f: errors come from the score alone 40 | } 41 | \author{ 42 | Xavier Valls \email{flamejat@gmail.com} 43 | } 44 | \references{ 45 | A. Meucci - "Exercises in Advanced Risk and Portfolio 46 | Management" \url{http://symmys.com/node/170}. 47 | 48 | See Meucci's script for "FitMultivariateGarch.m" 49 | } 50 | 51 | -------------------------------------------------------------------------------- /man/gaussHermiteMesh.Rd: -------------------------------------------------------------------------------- 1 | \name{gaussHermiteMesh} 2 | \alias{gaussHermiteMesh} 3 | \title{Generates grid reprensentation of a distribution according to the method suggested by Meucci and inspired from 4 | Gauss-Hermite quadratures.} 5 | \usage{ 6 | gaussHermiteMesh(J) 7 | } 8 | \arguments{ 9 | \item{J}{a numeric containing the number of points on the 10 | grid} 11 | } 12 | \value{ 13 | x a matrix containing the zeroes of Hermite polynomials 14 | as a function of polynomial degree 15 | } 16 | \description{ 17 | Grid representation by this method is an alternative to 18 | representing distribution of the market, such as 19 | importance sampling or stratified sampling.However, these 20 | techniques focus on sub-domains of the distribution, and 21 | thus, in order to apply such methods, we must forego the 22 | full flexibility on the specification of the views. A 23 | different approach, which preserves the generality of the 24 | views specification, consists in selecting the scenarios 25 | x_j deterministically as a grid and then associate with 26 | each of them the suitable probability p_j ( integrated 27 | over I_j ). The the generic interval _j contains the j-th 28 | point of the grid. Once the grid is defined, the entropy 29 | optimization can be applied to replace p_j with the new 30 | posterior probabilities to reflect the views. We generate 31 | the grid here using the Gauss-Hermite quadrature method. 32 | } 33 | \author{ 34 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 35 | } 36 | \references{ 37 | A. Meucci - "Fully Flexible Extreme Views". 38 | \url{http://ssrn.com/abstract=1542083} 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/hermitePolynomial.Rd: -------------------------------------------------------------------------------- 1 | \name{hermitePolynomial} 2 | \alias{hermitePolynomial} 3 | \title{Generate a Hermite Polynomial of order n} 4 | \usage{ 5 | hermitePolynomial(n) 6 | } 7 | \arguments{ 8 | \item{n}{A numeric defining the order of the Hermite 9 | Polynomial} 10 | } 11 | \value{ 12 | p A vector containing the Hermite Polynomial of order n 13 | \deqn{ H_{j} (x) \equiv (-1)^{J} e^{ \frac{ -x^{2} }{2} } 14 | \frac{ d^{J} e^{ \frac{ -x^{2} }{2} }}{ dx^{J} } } 15 | } 16 | \description{ 17 | Generate a Hermite Polynomial of order n 18 | } 19 | \author{ 20 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 21 | } 22 | \references{ 23 | A. Meucci - "Fully Flexible Extreme Views" - See formula 24 | (20) \url{http://ssrn.com/abstract=1542083} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/highYieldIndices.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{highYieldIndices} 3 | \alias{highYieldIndices} 4 | \title{highYieldIndices} 5 | \description{ 6 | highYieldIndices 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/implVol.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{implVol} 3 | \alias{implVol} 4 | \title{implVol} 5 | \description{ 6 | implVol 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/integrateSubIntervals.Rd: -------------------------------------------------------------------------------- 1 | \name{integrateSubIntervals} 2 | \alias{integrateSubIntervals} 3 | \title{Integrate the subinterval for the given cumulative distribution function to get the equivalent probability} 4 | \usage{ 5 | integrateSubIntervals(x, cdf) 6 | } 7 | \arguments{ 8 | \item{x}{a vector containing the data points} 9 | 10 | \item{cdf}{the cumulative distribution function} 11 | } 12 | \value{ 13 | p a vector containing the cdf evaluated for each of the 14 | subintervals 15 | } 16 | \description{ 17 | Integrate the subinterval for the given cumulative 18 | distribution function to get the equivalent probability 19 | } 20 | \author{ 21 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/kernelbw.Rd: -------------------------------------------------------------------------------- 1 | \name{kernelbw} 2 | \alias{kernelbw} 3 | \title{Generates bandwidth of a Gaussian Kernel Density Estimator based on Silverman's rule of thumb} 4 | \usage{ 5 | kernelbw(xi) 6 | } 7 | \arguments{ 8 | \item{xi}{a vector containing the data set for which the 9 | bandwidth has to be calculated} 10 | } 11 | \value{ 12 | bw a numeric signifying the bandwidth 13 | } 14 | \description{ 15 | Generates bandwidth of a Gaussian Kernel Density 16 | Estimator based on Silverman's rule of thumb 17 | } 18 | \author{ 19 | Manan Shah \email{mkshah@tepper.cmu.edu} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/kernelcdf.Rd: -------------------------------------------------------------------------------- 1 | \name{kernelcdf} 2 | \alias{kernelcdf} 3 | \title{Evaluates cumulative distribution function for the input numeric value} 4 | \usage{ 5 | kernelcdf(x, xi, bw, wi) 6 | } 7 | \arguments{ 8 | \item{x}{a vector containing the numeric values for which 9 | cumulative distribution function has to be evaluated} 10 | 11 | \item{xi}{a vector containing the data set} 12 | 13 | \item{bw}{a numeric value containing Silverman bandwidth 14 | of the given data set} 15 | 16 | \item{wi}{a vector containing weights} 17 | } 18 | \value{ 19 | p a numeric containing the cumulative probability 20 | distribution value of length equal to x 21 | } 22 | \description{ 23 | Evaluates cumulative distribution function for the input 24 | numeric value 25 | } 26 | \author{ 27 | Manan Shah \email{mkshah@tepper.cmu.edu} 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/kernelinv.Rd: -------------------------------------------------------------------------------- 1 | \name{kernelinv} 2 | \alias{kernelinv} 3 | \title{Evaluates inverse probability distribution function for the input probability in order to get the data point} 4 | \usage{ 5 | kernelinv(p, xi, bw, wi) 6 | } 7 | \arguments{ 8 | \item{p}{a vector containing the probabilities 9 | corresponding to which the data points have to be 10 | evaluated} 11 | 12 | \item{xi}{a vector containing the data set} 13 | 14 | \item{bw}{a numeric value containing Silverman bandwidth 15 | of the given data set} 16 | 17 | \item{wi}{a vector containing weights} 18 | } 19 | \value{ 20 | x a vector containing the evaluated numeric values of 21 | length equal to p 22 | } 23 | \description{ 24 | Evaluates inverse probability distribution function for 25 | the input probability in order to get the data point 26 | } 27 | \author{ 28 | Manan Shah \email{mkshah@tepper.cmu.edu} 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/kernelpdf.Rd: -------------------------------------------------------------------------------- 1 | \name{kernelpdf} 2 | \alias{kernelpdf} 3 | \title{Evaluates probability distribution function for the input numeric value} 4 | \usage{ 5 | kernelpdf(x, xi, bw, wi) 6 | } 7 | \arguments{ 8 | \item{x}{a vector containing the numeric values for which 9 | probability distribution function has to be evaluated} 10 | 11 | \item{xi}{a vector containing the data set} 12 | 13 | \item{bw}{a numeric value containing Silverman bandwidth 14 | of the given data set} 15 | 16 | \item{wi}{a vector containing weights} 17 | } 18 | \value{ 19 | p a vector containing the probability distribution 20 | function value of length equal to x 21 | } 22 | \description{ 23 | Evaluates probability distribution function for the input 24 | numeric value 25 | } 26 | \author{ 27 | Manan Shah \email{mkshah@tepper.cmu.edu} 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/linearModel.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{linearModel} 3 | \alias{linearModel} 4 | \title{parameters for the explicit factors / implicit loadings linear model} 5 | \description{ 6 | parameters for the explicit factors / implicit loadings 7 | linear model. 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, Exercises in Advanced Risk and Portfolio 14 | Management. \url{http://symmys.com/node/170} 15 | } 16 | \keyword{data} 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/linreturn.Rd: -------------------------------------------------------------------------------- 1 | \name{linreturn} 2 | \alias{linreturn} 3 | \title{Generate arithmetric returns and arithmetric covariance matrix given a distribution of log returns} 4 | \usage{ 5 | linreturn(mu, sigma) 6 | } 7 | \arguments{ 8 | \item{mu}{a numeric containing the expected logarithmic 9 | returns for each security} 10 | 11 | \item{sigma}{a covariance matrix of log returns} 12 | } 13 | \value{ 14 | a list containing two elements: 15 | 16 | arithmeticMean a numeric containing the mean arithmetic 17 | returns 18 | 19 | arithmeticCovariance a variance-covariance matrix in 20 | simple arithmetic return terms \deqn{ M_{ \tau }^{i} = 21 | e^{ \mu ^{\tau} _{i} + \frac{1}{2} \Sigma^{ii} _{\tau} }, 22 | \\ S^{ij} = e^{ \mu ^{\tau} _{i} + \mu ^{\tau} _{j} + 23 | \frac{1}{2} \big(\Sigma^{ii} _{\tau} + \Sigma^{jj} 24 | _{\tau}\big) } \big(e^{\Sigma^{ij} _{\tau}} - 1\big) } 25 | } 26 | \description{ 27 | Generate arithmetric returns and arithmetric covariance 28 | matrix given a distribution of log returns 29 | } 30 | \author{ 31 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 32 | } 33 | \references{ 34 | # formula (7) and (8) on page 5 of Appendix to "Meucci - 35 | A Common Pitfall in Mean-Variance Estimation" 36 | \url{http://www.wilmott.com/pdfs/011119_meucci.pdf} 37 | } 38 | 39 | -------------------------------------------------------------------------------- /man/normalizeProb.Rd: -------------------------------------------------------------------------------- 1 | \name{normalizeProb} 2 | \alias{normalizeProb} 3 | \title{Generates the normalized probability for an input probability value} 4 | \usage{ 5 | normalizeProb(p) 6 | } 7 | \arguments{ 8 | \item{p}{a numeric value containing the probability value 9 | required to be normalized} 10 | } 11 | \value{ 12 | normalizedp a numeric value containing the normalized 13 | probability value 14 | } 15 | \description{ 16 | Generates the normalized probability for an input 17 | probability value 18 | } 19 | \author{ 20 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/pHist.Rd: -------------------------------------------------------------------------------- 1 | \name{pHist} 2 | \alias{pHist} 3 | \title{Generates histogram} 4 | \usage{ 5 | pHist(X, p, nBins, freq = FALSE) 6 | } 7 | \arguments{ 8 | \item{X}{a vector containing the data points} 9 | 10 | \item{p}{a vector containing the probabilities for each 11 | of the data points in X} 12 | 13 | \item{nBins}{expected number of Bins the data set is to 14 | be broken down into} 15 | 16 | \item{freq}{a boolean variable to indicate whether the 17 | graphic is a representation of frequencies} 18 | } 19 | \value{ 20 | a list with f the frequency for each midpoint x the 21 | midpoints of the nBins intervals 22 | } 23 | \description{ 24 | Generates histogram 25 | } 26 | \author{ 27 | Ram Ahluwalia \email{ram@wingedfootcapital.com} and 28 | Xavier Valls \email{flamejat@gmail.com} 29 | } 30 | \references{ 31 | \url{http://www.symmys.com} See Meucci script pHist.m 32 | used for plotting 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/pHistPriorPosterior.Rd: -------------------------------------------------------------------------------- 1 | \name{pHistPriorPosterior} 2 | \alias{pHistPriorPosterior} 3 | \title{Plot prior and posterior distributions.} 4 | \usage{ 5 | pHistPriorPosterior(X, p, p_) 6 | } 7 | \arguments{ 8 | \item{X}{: [matrix] (J x N) simulations} 9 | 10 | \item{p}{: [vector] (J x 1) prior probabilities} 11 | 12 | \item{p_}{: [vector] (J x 1) posterior probabilities} 13 | } 14 | \description{ 15 | Plot prior and posterior distributions, as described in 16 | A. Meucci, "Risk and Asset Allocation", Springer, 2005. 17 | } 18 | \author{ 19 | Xavier Valls \email{flamejat@gmail.com} 20 | } 21 | \references{ 22 | A. Meucci - "Exercises in Advanced Risk and Portfolio 23 | Management" \url{http://symmys.com/node/170}. 24 | 25 | See Meucci's script for "pHistPriorPosterior.m" 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/private_fun.Rd: -------------------------------------------------------------------------------- 1 | \name{private_fun} 2 | \alias{private_fun} 3 | \title{Evaluates the difference between calculated cumulative distribution function for a data point and the 4 | true value} 5 | \usage{ 6 | private_fun(x, xi, bw, wi, p) 7 | } 8 | \arguments{ 9 | \item{x}{a vector containing the data points for which 10 | cdf has to be evaluated} 11 | 12 | \item{xi}{a vector containing the data set} 13 | 14 | \item{bw}{a numeric value containing Silverman bandwidth 15 | of the given data set} 16 | 17 | \item{wi}{a vector containing weights} 18 | 19 | \item{p}{a vector containing the true probabilities} 20 | } 21 | \value{ 22 | f a vector containing the difference between x and p 23 | which is of length equal to x or p 24 | } 25 | \description{ 26 | Evaluates the difference between calculated cumulative 27 | distribution function for a data point and the true value 28 | } 29 | \author{ 30 | Manan Shah \email{mkshah@tepper.cmu.edu} 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/returnsDistribution.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{returnsDistribution} 3 | \alias{returnsDistribution} 4 | \title{Panel X of joint returns realizations and vector p of respective probabilities for returns} 5 | \description{ 6 | Panel X of joint returns realizations and vector p of 7 | respective probabilities for returns 8 | } 9 | \author{ 10 | Xavier Valls\email{flamejat@gmail.com} 11 | } 12 | \references{ 13 | A. Meucci, "Fully Flexible Views: Theory and Practice", 14 | The Risk Magazine, October 2008, p 100-106. 15 | \url{http://symmys.com/node/158} 16 | } 17 | \keyword{data} 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/sectorsSnP500.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{sectorsSnP500} 3 | \alias{sectorsSnP500} 4 | \title{data from the sectors in the S&P 500} 5 | \description{ 6 | data from the sectors in the S&P 500 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | Attilio Meucci, 2011, "Robust Bayesian Allocation". 13 | \url{http://symmys.com/node/102} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/sectorsTS.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{sectorsTS} 3 | \alias{sectorsTS} 4 | \title{stock returns by sectors} 5 | \description{ 6 | stock returns by sectors 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/securitiesIndustryClassification.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{securitiesIndustryClassification} 3 | \alias{securitiesIndustryClassification} 4 | \title{Stock Indices} 5 | \description{ 6 | Stock Indices 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/securitiesTS.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{securitiesTS} 3 | \alias{securitiesTS} 4 | \title{Stock Returns.} 5 | \description{ 6 | Stock Returns. 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/std.Rd: -------------------------------------------------------------------------------- 1 | \name{std} 2 | \alias{std} 3 | \title{Calculates the population standard deviation} 4 | \usage{ 5 | std(x) 6 | } 7 | \arguments{ 8 | \item{x}{a generic numeric vector} 9 | } 10 | \value{ 11 | std a numeric with the population standard deviaiton of 12 | the generic numeric 13 | } 14 | \description{ 15 | Calculates the population standard deviation dividing by 16 | 'n' instead of 'n-1' equivalent to Matlab 17 | } 18 | \author{ 19 | Ram Ahluwalia \email{rahluwalia@gmail.com} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/subIntervals.Rd: -------------------------------------------------------------------------------- 1 | \name{subIntervals} 2 | \alias{subIntervals} 3 | \title{Generate the intervals containing jth point of the grid.} 4 | \usage{ 5 | subIntervals(x) 6 | } 7 | \arguments{ 8 | \item{x}{a vector containing the scenarios} 9 | } 10 | \value{ 11 | a list containing 12 | 13 | xLB a vector containing the lower bound of each interval 14 | 15 | xUB a vector containing the upper bound of each interval 16 | \deqn{ I_{j} \equiv \big[ x_{j} - \frac{x_{j} - x_{j-1} 17 | }{2}, x_{j} + \frac{x_{j+1} - x_{j}}{2} \big) } 18 | } 19 | \description{ 20 | Generate the intervals containing jth point of the grid. 21 | } 22 | \author{ 23 | Ram Ahluwalia \email{ram@wingedfootcapital.com} 24 | } 25 | \references{ 26 | A. Meucci - "Fully Flexible Extreme Views" - See formula 27 | (17) \url{http://ssrn.com/abstract=1542083} 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/swap2y4y.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{swap2y4y} 3 | \alias{swap2y4y} 4 | \title{Swaps for 2y and 4y} 5 | \description{ 6 | Swaps for 2y and 4y 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/swapParRates.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{swapParRates} 3 | \alias{swapParRates} 4 | \title{swapParRates} 5 | \description{ 6 | swapParRates 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | -------------------------------------------------------------------------------- /man/swaps.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{swaps} 3 | \alias{swaps} 4 | \title{swaps} 5 | \description{ 6 | swaps 7 | } 8 | \author{ 9 | Xavier Valls\email{flamejat@gmail.com} 10 | } 11 | \references{ 12 | A. Meucci, Exercises in Advanced Risk and Portfolio 13 | Management. \url{http://symmys.com/node/170} 14 | } 15 | \keyword{data} 16 | \keyword{datasets} 17 | 18 | --------------------------------------------------------------------------------