[Returnanalytics-commits] r3119 - in pkg/Meucci: R demo man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 16 19:24:03 CEST 2013
Author: xavierv
Date: 2013-09-16 19:24:03 +0200 (Mon, 16 Sep 2013)
New Revision: 3119
Modified:
pkg/Meucci/R/BlackScholesCallPrice.R
pkg/Meucci/R/ConvertChangeInYield2Price.R
pkg/Meucci/R/InterExtrapolate.R
pkg/Meucci/R/MaxRsqCS.R
pkg/Meucci/R/PerformIidAnalysis.R
pkg/Meucci/R/ProjectionStudentT.R
pkg/Meucci/demo/S_AutocorrelatedProcess.R
pkg/Meucci/demo/S_BondProjectionPricingNormal.R
pkg/Meucci/demo/S_BondProjectionPricingStudentT.R
pkg/Meucci/demo/S_CallsProjectionPricing.R
pkg/Meucci/demo/S_CrossSectionConstrainedIndustries.R
pkg/Meucci/demo/S_CrossSectionIndustries.R
pkg/Meucci/demo/S_DerivativesInvariants.R
pkg/Meucci/demo/S_EquitiesInvariants.R
pkg/Meucci/demo/S_EquityProjectionPricing.R
pkg/Meucci/demo/S_FactorAnalysisNotOk.R
pkg/Meucci/demo/S_FactorResidualCorrelation.R
pkg/Meucci/demo/S_FixedIncomeInvariants.R
pkg/Meucci/demo/S_HedgeOptions.R
pkg/Meucci/demo/S_HorizonEffect.R
pkg/Meucci/demo/S_WishartLocationDispersion.R
pkg/Meucci/man/BlackScholesCallPrice.Rd
pkg/Meucci/man/ConvertChangeInYield2Price.Rd
pkg/Meucci/man/InterExtrapolate.Rd
pkg/Meucci/man/MaxRsqCS.Rd
pkg/Meucci/man/PerformIidAnalysis.Rd
pkg/Meucci/man/ProjectionStudentT.Rd
Log:
- updated documentation for half chapter 3 demo scripts and its functions
Modified: pkg/Meucci/R/BlackScholesCallPrice.R
===================================================================
--- pkg/Meucci/R/BlackScholesCallPrice.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/BlackScholesCallPrice.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,22 +1,25 @@
-#' Compute the Black-Scholes price of a European call or put option
+#' @title Compute the Black-Scholes price of a European call or put option.
+#'
+#' @description Compute the Black-Scholes price of a European call or put option
#' as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005.
#'
-#' @param spot : [scalar] spot price of underlying
-#' @param K : [scalar] strike of the call optioon
-#' @param r : [scalar] risk free rate as a fraction
-#' @param vol : [scalar] volatility of the underlying as a fraction
-#' @param T : [scalar] time to maturity in years
+#' @param spot [scalar] spot price of underlying
+#' @param K [scalar] strike of the call optioon
+#' @param r [scalar] risk free rate as a fraction
+#' @param vol [scalar] volatility of the underlying as a fraction
+#' @param T [scalar] time to maturity in years
#'
-#' @return c : [scalar] price of European call(s)
-#' @return p : [scalar] price of European put(s)
-#' @return delta : [scalar] delta of the call(s) or put(s)
-#' @return cash : [scalar] cash held in a replicating portfolio
+#' @return c [scalar] price of European call(s)
+#' @return p [scalar] price of European put(s)
+#' @return delta [scalar] delta of the call(s) or put(s)
+#' @return cash [scalar] cash held in a replicating portfolio
#'
#' @note
#' Code is vectorized, so the inputs can be vectors or matrices (but sizes must match)
#'
#' @references
#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#'
#' See Meucci's script for "BlackScholesCallPrice.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -26,9 +29,9 @@
{
d1 = ( log( spot / K ) + ( r + vol * vol / 2) * T) / (vol * sqrt(T));
d2 = d1 - vol * sqrt(T);
- delta = pnorm(d1);
- cash = -K * exp( -r * T ) * pnorm( d2 );
- c = spot * delta + cash;
+ delta = pnorm(d1); # delta of the call
+ cash = -K * exp( -r * T ) * pnorm( d2 ); # cash held in a replicating portfolio
+ c = spot * delta + cash; # price of call
return( list( c = c, delta = delta, cash = cash ) );
}
@@ -40,9 +43,9 @@
{
d1 = ( log( spot / K ) + ( r + vol * vol / 2) * T) / (vol * sqrt(T));
d2 = d1 - vol * sqrt(T);
- delta = pnorm( -d1 );
- cash = -K * exp( -r * T ) * pnorm( d2 );
- p = -( spot * delta + cash );
+ delta = pnorm( -d1 ); # delta of the call
+ cash = -K * exp( -r * T ) * pnorm( d2 ); # cash held in a replicating portfolio
+ p = -( spot * delta + cash ); # price of put
return( list( put = p, delta = delta, cash = cash ) );
}
@@ -54,9 +57,9 @@
{
d1 = ( log( spot / K ) + ( r + vol * vol / 2) * T) / (vol * sqrt(T));
d2 = d1 - vol * sqrt(T);
- cash = -K * exp( -r * T ) * pnorm( d2 );
- c = spot * pnorm( d1 ) + cash;
- p = -( spot * pnorm( -d1 ) + cash);
+ cash = -K * exp( -r * T ) * pnorm( d2 ); # cash held in a replicating portfolio
+ c = spot * pnorm( d1 ) + cash; # price of call
+ p = -( spot * pnorm( -d1 ) + cash ); # price of put
return( list( call = c, put = p, cash = cash ) );
}
Modified: pkg/Meucci/R/ConvertChangeInYield2Price.R
===================================================================
--- pkg/Meucci/R/ConvertChangeInYield2Price.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/ConvertChangeInYield2Price.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,17 +1,21 @@
-#' Convert change in yield-to-maturity to price for fixed-income securities, as described in
+#' @title Convert change in yield-to-maturity to price for fixed-income securities
+#'
+#' @description Convert change in yield-to-maturity to price for fixed-income securities, as described in
#' A. Meucci "Risk and Asset Allocation", Springer, 2005
#'
-#' @param Exp_DY : [vector] (N x 1) expected value of change in yield to maturity
-#' @param Cov_DY : [matrix] (N x N) covariance of change in yield to maturity
-#' @param Times2Mat : [scalar] time to maturity
-#' @param CurrentPrices : [vector] (N x 1) current prices
+#' @param Exp_DY [vector] (N x 1) expected value of change in yield to maturity
+#' @param Cov_DY [matrix] (N x N) covariance of change in yield to maturity
+#' @param Times2Mat [scalar] time to maturity
+#' @param CurrentPrices [vector] (N x 1) current prices
#'
-#' @return Exp_Prices : [vector] (N x 1) expected prices
-#' @return Cov_Prices : [matrix] (N x N) covariance of prices
+#' @return Exp_Prices [vector] (N x 1) expected prices
+#' @return Cov_Prices [matrix] (N x N) covariance of prices
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#'
#' See (6.77)-(6.79) in "Risk and Asset Allocation"-Springer (2005), by A. Meucci
+#'
#' See Meucci's script for "ConvertChangeInYield2Price.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/R/InterExtrapolate.R
===================================================================
--- pkg/Meucci/R/InterExtrapolate.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/InterExtrapolate.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,28 +1,27 @@
#' Interpolate and extrapolate using n-linear interpolation (tensor product linear).
#'
-#' @param V : [array] p-dimensional array to be interpolated/extrapolated at the list of points in the array Xi.
+#' @param V [array] p-dimensional array to be interpolated/extrapolated at the list of points in the array Xi.
# interpne will work in any number of dimensions >= 1
-#' @param Xi : [array] (n x p) array of n points to interpolate/extrapolate. Each point is one row of the array Xi.
-#' @param nodelist : [cell array] (optional) cell array of nodes in each dimension.
+#' @param Xi [array] (n x p) array of n points to interpolate/extrapolate. Each point is one row of the array Xi.
+#' @param nodelist [cell array] (optional) cell array of nodes in each dimension.
# If nodelist is not provided, then by default I will assume nodelist[[i]] = 1:size(V,i). The nodes in
# nodelist need not be uniformly spaced.
-#' @param method : [string] (optional) chacter string, denotes the interpolation method used. default method = 'linear'
+#' @param method [string] (optional) chacter string, denotes the interpolation method used. default method = 'linear'
# 'linear' --> n-d linear tensor product interpolation/extrapolation
# 'nearest' --> n-d nearest neighbor interpolation/extrapolation
# in 2-d, 'linear' is equivalent to a bilinear interpolant
# in 3-d, it is commonly known as trilinear interpolation.
#'
-#' @return Vpred : [array] (n x 1) array of interpolated/extrapolated values
+#' @return Vpred [array] (n x 1) array of interpolated/extrapolated values
#'
#' @note
-#' Initially written by John D'Errico
-#' Vpred = interpne(V,Xi)
-#' Vpred = interpne(V,Xi,nodelist)
-#' Vpred = interpne(V,Xi,nodelist,method)
+#' Initially written by John D'Errico.
+#'
#' Extrapolating long distances outside the support of V is rarely advisable.
#'
#' @references
#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#'
#' See Meucci's script for "InterExtrapolate.R"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -33,12 +32,12 @@
# [x1,x2] = meshgrid(0:.2:1);
# z = exp(x1+x2);
# Xi = rand(100,2)*2-.5;
-# Zi = interpne(z,Xi,{0:.2:1, 0:.2:1},'linear');
+# Zi = InterExtrapolate(z,Xi,{0:.2:1, 0:.2:1},'linear');
# surf(0:.2:1,0:.2:1,z)
# plot3( Xi(:,1),Xi(:,2),Zi,'ro')
#
-InterExtrapolate = function( V, Xi, nodelist, method )
+InterExtrapolate = function( V, Xi, nodelist = NULL, method = NULL )
{
# get some sizes
@@ -147,7 +146,7 @@
# tensor product linear is not too nasty.
Vpred = matrix( 0, nrow(Xi), 1);
# define the 2^ndims corners of a hypercube (MATLAB's corners = (dec2bin(0:(2^ndims-1))== '1');)
- corners = lapply( strsplit( intToBin ( 0 : ( 2^ndims - 1 ) ), split=""), as.integer );
+ corners = lapply( strsplit( intToBin ( 0 : ( 2^ndims - 1 ) ), split = "" ), as.integer );
nc = length( corners );
Modified: pkg/Meucci/R/MaxRsqCS.R
===================================================================
--- pkg/Meucci/R/MaxRsqCS.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/MaxRsqCS.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,4 +1,7 @@
-#' Solve for G that maximises sample r-square of X*G'*B' with X under constraints A*G<=D
+#' @title Solve for G that maximises sample r-square of X*G'*B' with X under constraints A*G<=D
+#' and Aeq*G=Deq
+#'
+#' @description Solve for G that maximises sample r-square of X*G'*B' with X under constraints A*G<=D
#' and Aeq*G=Deq (A,D, Aeq,Deq conformable matrices),as described in A. Meucci,
#' "Risk and Asset Allocation", Springer, 2005.
#'
@@ -19,6 +22,8 @@
#'
#' @references
#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' Used in "E 123 – Cross-section factors: generalized cross-section industry factors".
+#'
#' See Meucci's script for "MaxRsqCS.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/R/PerformIidAnalysis.R
===================================================================
--- pkg/Meucci/R/PerformIidAnalysis.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/PerformIidAnalysis.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,4 +1,6 @@
-#' This function performs simple invariance (i.i.d.) tests on a time series, as described in
+#' @title Performs simple invariance (i.i.d.) tests on a time series.
+#'
+#' @description This function performs simple invariance (i.i.d.) tests on a time series, as described in
#' A. Meucci "Risk and Asset Allocation", Springer, 2005
#'
#' @param Dates : [vector] (T x 1) dates
@@ -6,12 +8,16 @@
#' @param Str : [string] title for the plot
#'
#' @note it checks the evolution over time
-# it checks that the variables are identically distributed by looking at the histogram of two subsamples
-# it checks that the variables are independent by looking at the 1-lag scatter plot
-# under i.i.d. the location-dispersion ellipsoid should be a circle
#'
+#' it checks that the variables are identically distributed by looking at the histogram of two subsamples
+#'
+#' it checks that the variables are independent by looking at the 1-lag scatter plot
+#'
+#' under i.i.d. the location-dispersion ellipsoid should be a circle
+#'
#' @references
#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#'
#' See Meucci's script for "PerformIidAnalysis.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -52,9 +58,5 @@
m = cbind( apply( cbind( X, Y ), 2, mean ));
S = cov( cbind( X, Y ));
TwoDimEllipsoid( m, S, 2, FALSE, FALSE);
- #axisLimits = axis;
- #textX = axisLimits(1:2)*[-0.1,1.1]';
- #textY = axisLimits(3:4)*[0.1,0.9]';
- #text(textX, textY, Str);
}
\ No newline at end of file
Modified: pkg/Meucci/R/ProjectionStudentT.R
===================================================================
--- pkg/Meucci/R/ProjectionStudentT.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/R/ProjectionStudentT.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,17 +1,21 @@
-#' Perform the horizon projection of a Student t invariant, as described in
+#' @title Perform the horizon projection of a Student t invariant
+#'
+#' @description Perform the horizon projection of a Student t invariant, as described in
#' A. Meucci "Risk and Asset Allocation", Springer, 2005
#'
-#' @param nu : [scalar] degree of freedom
-#' @param s : [scalar] scatter parameter
-#' @param m : [scalar] location parameter
-#' @param T : [scalar] multiple of the estimation period to the invesment horizon
+#' @param nu [scalar] degree of freedom
+#' @param s [scalar] scatter parameter
+#' @param m [scalar] location parameter
+#' @param T [scalar] multiple of the estimation period to the invesment horizon
#'
-#' @return x_Hor : [scalar]
-#' @return f_Hor : [scalar]
-#' @return F_Hor : [scalar]
+#' @return x_Hor [scalar] probabilities at horizon
+#' @return f_Hor [scalar] horizon discretized pdf (non-standarized)
+#' @return F_Hor [scalar] horizon discretized cdf (non-standarized)
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 141 – Fixed-income market: projection of Student t invariants".
+#'
#' See Meucci's script for "ProjectionStudentT.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/demo/S_AutocorrelatedProcess.R
===================================================================
--- pkg/Meucci/demo/S_AutocorrelatedProcess.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_AutocorrelatedProcess.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,15 +1,17 @@
-
-#' This script simulates a Ornstein-Uhlenbeck AR(1) process, as described in A. Meucci, "
-#' Risk and Asset Allocation", Springer, 2005, Chapter 3.
+#' This script simulates a Ornstein-Uhlenbeck AR(1) process, as described in A. Meucci,
+#' "Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 133 – Simulation of a Ornstein-Uhlenbeck process".
+#'
#' See Meucci's script for "S_AutocorrelatedProcess.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
##################################################################################################################
### Input parameters
+
theta = 0.1; # reversion speed
m = 0.05; # long term mean
sigma = 0.01; # volatility
@@ -19,7 +21,7 @@
##################################################################################################################
### Determine parameters
var = sigma^2 / 2 / theta * ( 1 - exp( -2 * theta * tau ) );
-sd = sqrt(var);
+sd = sqrt(var);
eps = rnorm( T, 0, sd );
x = matrix( NaN, T, 1);
@@ -30,5 +32,5 @@
x[ t + 1 ] = m + exp( -theta * tau ) * ( x[ t ] - m ) + eps[ t ];
}
-dev.new()
+dev.new();
plot( x, type="l", main = "AR(1) process vs. time" );
Modified: pkg/Meucci/demo/S_BondProjectionPricingNormal.R
===================================================================
--- pkg/Meucci/demo/S_BondProjectionPricingNormal.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_BondProjectionPricingNormal.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,15 +1,15 @@
-
#'This script projects the distribution of the market invariants for the bond markets
#'(i.e. the changes in yield to maturity) from the estimation interval to the investment horizon
#'Then it computes the distribution of prices at the investment horizon as described in A. Meucci,
#'"Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 140 – Fixed-income market: projection of normal invariants".
+#'
#' See Meucci's script for "S_BondProjectionPricingNormal.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
-#'
##################################################################################################################
### Inputs
@@ -61,5 +61,3 @@
BondCov_Prices = cov( BondMarket_Scenarios );
print( BondExp_Prices );
print( BondCov_Prices );
-
-### EOF
\ No newline at end of file
Modified: pkg/Meucci/demo/S_BondProjectionPricingStudentT.R
===================================================================
--- pkg/Meucci/demo/S_BondProjectionPricingStudentT.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_BondProjectionPricingStudentT.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -4,11 +4,12 @@
#'horizon as described in A. Meucci,"Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 141 – Fixed-income market: projection of Student t invariants".
+#'
#' See Meucci's script for "S_BondProjectionPricingStudentT.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
-#'
##################################################################################################################
### Inputs
Modified: pkg/Meucci/demo/S_CallsProjectionPricing.R
===================================================================
--- pkg/Meucci/demo/S_CallsProjectionPricing.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_CallsProjectionPricing.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -3,7 +3,9 @@
#'"Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 143 – Derivatives market: projection of invariants".
+#'
#' See Meucci's script for "S_CallsProjectionPricing.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -27,8 +29,8 @@
J = 10000; # number of simulations
##################################################################################################################
-numCalls = length( Time2Mats );
-timeLength = length( implVol$spot );
+numCalls = length( Time2Mats );
+timeLength = length( implVol$spot );
numSurfPoints = length( implVol$days2Maturity ) * length( implVol$moneyness );
##################################################################################################################
@@ -36,6 +38,7 @@
# variables in X are changes in log(spot) and changes in log(imp.vol)
# evaluated at the 'numSurfPoints' points on the vol surface (vectorized).
X = matrix( 0, timeLength - 1, numSurfPoints + 1 );
+
# log-changes of underlying spot
X[ , 1 ] = diff( log( implVol$spot ) );
@@ -46,12 +49,12 @@
X[ , i+1 ] = diff( log( impVolSeries[ , i ] ) );
}
-muX = apply( X , 2, mean );
+muX = apply( X , 2, mean );
SigmaX = cov( X );
##################################################################################################################
### Project distribution to investment horizon
-muX = muX * tau / tau_tilde;
+muX = muX * tau / tau_tilde;
SigmaX = SigmaX * tau / tau_tilde;
##################################################################################################################
Modified: pkg/Meucci/demo/S_CrossSectionConstrainedIndustries.R
===================================================================
--- pkg/Meucci/demo/S_CrossSectionConstrainedIndustries.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_CrossSectionConstrainedIndustries.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -3,7 +3,9 @@
#' Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 123 – Cross-section factors: generalized cross-section industry factors".
+#'
#' See Meucci's script for "S_CrossSectionConstrainedIndustries.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/demo/S_CrossSectionIndustries.R
===================================================================
--- pkg/Meucci/demo/S_CrossSectionIndustries.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_CrossSectionIndustries.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,7 +2,9 @@
#' "Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 122 – Cross-section factors: unconstrained cross-section industry factors".
+#'
#' See Meucci's script for "S_CrossSectionIndustries.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/demo/S_DerivativesInvariants.R
===================================================================
--- pkg/Meucci/demo/S_DerivativesInvariants.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_DerivativesInvariants.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,7 +2,9 @@
#' in A. Meucci,"Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 142 - Derivatives market: quest for invariance".
+#'
#' See Meucci's script for "S_DerivativesInvariants.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/demo/S_EquitiesInvariants.R
===================================================================
--- pkg/Meucci/demo/S_EquitiesInvariants.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_EquitiesInvariants.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,13 +2,13 @@
#' A. Meucci "Risk and Asset Allocation", Springer, 2005, chapter 3.
#'
#' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 135 – Equity market: quest for invariance".
+#'
#' See Meucci's script for "S_EquitiesInvariants.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
-
-
##################################################################################################################
### Load daily stock prices from the utility sector in the S&P 500
data("equities");
@@ -35,4 +35,3 @@
# fourth invariant
W = P[ 3 : length( P ) ] - 2 * P[ 2: ( length( P ) -1 ) ] + P[ 1 : ( length( P ) -2 ) ];
PerformIidAnalysis( 1 : length( W ), W, 'Analysis for W' );
-
Modified: pkg/Meucci/demo/S_EquityProjectionPricing.R
===================================================================
--- pkg/Meucci/demo/S_EquityProjectionPricing.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_EquityProjectionPricing.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,14 +1,15 @@
-
#' This script projects the distribution of the market invariants for the stock market (i.e. the compounded returns)
#' from the estimation interval (normal assumption) to the investment horizon. Then it computes the distribution of prices
#' at the investment horizon analytically, by full Monte Carlo, and by delta/duration approximation.
-#' Described in A. Meucci "Risk and Asset Allocation", Springer, 2005,
-#' chapter 3.
#'
+#' Described in A. Meucci "Risk and Asset Allocation", Springer, 2005, chapter 3.
+#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
-#' See Meucci's script for "S_EquitiesInvariance.m"
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 138 – Equity market: linear vs. compounded returns projection II".
#'
+#' See Meucci's script for "S_EquityProjectionPricing.m"
+#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
#################################################################################################################
Modified: pkg/Meucci/demo/S_FactorAnalysisNotOk.R
===================================================================
--- pkg/Meucci/demo/S_FactorAnalysisNotOk.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_FactorAnalysisNotOk.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,12 +2,13 @@
#'"Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 111 – Hidden factors: puzzle".
+#'
#' See Meucci's script for "S_FactorAnalysisNotOk.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
-
##################################################################################################################
### Inputs
@@ -36,12 +37,13 @@
FA = factanal(X, K, scores = "Bartlett" );
# factor analysis recovers the structure exactly however...
-S_ = FA$loadings %*% t( FA$loadings ) + diag( FA$uniquenesses, length( FA$uniquenesses) );
+S_ = FA$loadings %*% t( FA$loadings ) + diag( FA$uniquenesses, length( FA$uniquenesses) );
Match = 1 - max( abs( ( S - S_) / S) );
print(Match);
# ...the systematic+idiosyncratic decomposition is NOT recovered
-U_ = X - FA$scores %*% t(FA$loadings); # compute residuals
+U_ = X - FA$scores %*% t(FA$loadings); # compute residuals
S_U = cor( U_ ); # compute correlations
+
# residuals are not idiosyncratic
print( S_U );
\ No newline at end of file
Modified: pkg/Meucci/demo/S_FactorResidualCorrelation.R
===================================================================
--- pkg/Meucci/demo/S_FactorResidualCorrelation.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_FactorResidualCorrelation.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -3,7 +3,9 @@
#' "Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 125 – Correlation factors-residual: normal example".
+#'
#' See Meucci's script for "S_FactorResidualCorrelation.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -14,8 +16,8 @@
nSim = 10000;
mu = 0.1 + 0.3 * runif(N);
sigma = 0.5 * mu;
-dd = matrix(rnorm( N*N ), N, N );
-Corr = cov2cor( dd %*% t( dd ) );
+dd = matrix(rnorm( N*N ), N, N );
+Corr = cov2cor( dd %*% t( dd ) );
Sigma = diag( sigma, length(sigma) ) %*% Corr %*% diag( sigma, length(sigma) );
##################################################################################################################
@@ -24,7 +26,7 @@
##################################################################################################################
### Generate a random vector beta
-beta = matrix(1, N ) + rnorm(N) * 0.1;
+beta = matrix( 1, N ) + rnorm(N) * 0.1;
##################################################################################################################
### Compute factor realization by cross-sectional regression and residuals
Modified: pkg/Meucci/demo/S_FixedIncomeInvariants.R
===================================================================
--- pkg/Meucci/demo/S_FixedIncomeInvariants.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_FixedIncomeInvariants.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,7 +2,9 @@
#' "Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 139 – Fixed-income market: quest for invariance".
+#'
#' See Meucci's script for "S_FixedIncomeInvariants.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
Modified: pkg/Meucci/demo/S_HedgeOptions.R
===================================================================
--- pkg/Meucci/demo/S_HedgeOptions.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_HedgeOptions.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,7 +2,9 @@
#' A. Meucci "Risk and Asset Allocation", Springer, 2005, Chapter 3.
#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 127 – Factors on demand: no-Greek hedging".
+#'
#' See Meucci's script for "S_HedgeOptions.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -23,8 +25,8 @@
##################################################################################################################
### Underlying and volatility surface
-numCalls = length( Time2Mats );
-timeLength = length( implVol$spot );
+numCalls = length( Time2Mats );
+timeLength = length( implVol$spot );
numSurfPoints = length( implVol$days2Maturity ) * length( implVol$moneyness );
##################################################################################################################
Modified: pkg/Meucci/demo/S_HorizonEffect.R
===================================================================
--- pkg/Meucci/demo/S_HorizonEffect.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_HorizonEffect.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -1,16 +1,26 @@
-
#'This script studies horizon effect on explicit factors / implicit loadings linear model, as described in
#'A. Meucci, "Risk and Asset Allocation", Springer, 2005, Chapter 3.
-#'Compounded returns follow the linear model X = tau*muX + D*F + epsilon, where
+#'Compounded returns follow the linear model X = tau*muX + D*F + epsilon, where:
+#'
#' tau: investment horizon (in weeks)
+#'
#' muX: expected weekly compounded returns
+#'
#' F: factor compounded returns, with zero expectation and tau-proportional covariance
+#'
#' D: matrix of factor loadings
+#'
#' epsilon: uncorrelated (idiosyncratic) shocks.
+#'
#' R = exp(X)-1 and Z = exp(F)-1 are the linear returns
#'
+#' @note See "E 116 – Time series factors: analysis of residuals I" from
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#'
#' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 126 – Factors on demand: horizon effect".
+#'
#' See Meucci's script for "S_HorizonEffect.m"
#'
#' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -76,6 +86,7 @@
##################################################################################################################
### Plots
+
# relationship between the constant nd the intercept
dev.new();
plot(tauRangeWeeks, aMinusTauMuX, type= "l", xlab = expression(paste("investment horizon, ", tau,", weeks")),
@@ -85,8 +96,6 @@
dev.new();
plot(tauRangeWeeks, normDminusB, type = "l", xlab = expression(paste("investment horizon, ", tau,", weeks")), main = expression("norm of (D-B)"^t));
-
-
# determine if U idiosyncratic
dev.new();
plot(tauRangeWeeks, maxCorrU, col = "red", type = "l", xlab = expression(paste("investment horizon, ", tau,", weeks")),
Modified: pkg/Meucci/demo/S_WishartLocationDispersion.R
===================================================================
--- pkg/Meucci/demo/S_WishartLocationDispersion.R 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/demo/S_WishartLocationDispersion.R 2013-09-16 17:24:03 UTC (rev 3119)
@@ -22,11 +22,11 @@
###################################################################################################################
### Set input parameters
-W_xx = matrix( NaN, nSim, 1 );
-W_yy = matrix( NaN, nSim, 1 );
-W_xy = matrix( NaN, nSim, 1 );
-Vec_W = matrix( NaN, nSim, 4 );
-Dets = matrix( NaN, nSim, 1 );
+W_xx = matrix( NaN, nSim, 1 );
+W_yy = matrix( NaN, nSim, 1 );
+W_xy = matrix( NaN, nSim, 1 );
+Vec_W = matrix( NaN, nSim, 4 );
+Dets = matrix( NaN, nSim, 1 );
Traces = matrix( NaN, nSim, 1 );
@@ -80,7 +80,7 @@
S = diag( 1 / c( sqrt( var_Wxx ), sqrt( var_Wxy ))) %*% S_xx_xy %*% diag( 1 / c( sqrt( var_Wxx ), sqrt( var_Wxy )));
S_hat = cov( X );
-figure();
+dev.new();
plot( X_1, X_2, xlab = "X_1", ylab = "X_2");
TwoDimEllipsoid(E, S, 1, TRUE, FALSE);
Modified: pkg/Meucci/man/BlackScholesCallPrice.Rd
===================================================================
--- pkg/Meucci/man/BlackScholesCallPrice.Rd 2013-09-16 10:40:00 UTC (rev 3118)
+++ pkg/Meucci/man/BlackScholesCallPrice.Rd 2013-09-16 17:24:03 UTC (rev 3119)
@@ -2,8 +2,7 @@
\alias{BlackScholesCallPrice}
\alias{BlackScholesCallPutPrice}
\alias{BlackScholesPutPrice}
-\title{Compute the Black-Scholes price of a European call or put option
- as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005.}
+\title{Compute the Black-Scholes price of a European call or put option.}
\usage{
BlackScholesCallPrice(spot, K, r, vol, T)
@@ -12,25 +11,25 @@
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/returnanalytics -r 3119
More information about the Returnanalytics-commits
mailing list