Learn R Programming

portsort (version 0.1.0)

conditional.sort: Conditional Portfolio Sort

Description

Calculates out-of-sample mean sub-portfolio returns and the composition of each sub-portfolio using the conditional portfolio sorting method.

Usage

conditional.sort(Fa,Fb=NULL,Fc=NULL,R.Forward,dimA,dimB=NULL,dimC=NULL,type = 7)

Arguments

Fa

xts-object containing data for the first dimension of sort

Fb

xts-object containing data for the second dimension of sort (optional)

Fc

xts-object containing data for the third dimension of sort (optional)

R.Forward

xts-object containing forward returns

dimA

vector of break points between 0 and 1

dimB

vector of break points between 0 and 1 (optional)

dimC

vector of break points between 0 and 1 (optional)

type

pass-through parameter to the quantile function

Value

returns

Out-of-sample sub-portfolio returns

portfolio

List of the sub-portfolio constituents over time

Details

The conditional sort function sorts assets based on each factor (Fa to Fc) from low to high in a dependent fashion at each time t. Based on the sorted assets in each sub-portfolio at time t, mean out-of-sample sub-portfolio returns are computed for time t+1. After each dimension of sort, the subsequent sort is done only within each prior sorted sub-portfolio. Hence, the first factor that is sorted on yields greater influence on the overall sorting procedure. The function outputs out-of-sample returns for each sub-portfolio in columns and a list of the sub-portfolio constituents at each rebalancing point.

Examples

Run this code
# NOT RUN {
# Load the included data
library(portsort)
data(Factors)

# Specifiy the sort dimension - in this case, a double sort on lagged returns and Bitcoin volumes
# with 4 breakpoints (a 4v4 sort)
dimA = c(0,0.25,0.5,0.75,1)
dimB = c(0,0.25,0.5,0.75,1)

# Specify the factors for the double sort
# Lagged returns, lagged volumes are stored in the Factors list

R.Forward = Factors[[1]]; R.Lag = Factors[[2]]; V.Lag = Factors[[3]]

# Subset the data from late 2017
R.Forward = R.Forward["2017-12-01/"]
R.Lag = R.Lag["2017-11-30/2018-09-05"]
V.Lag = V.Lag["2017-11-30/2018-09-05"]

Fa = R.Lag
Fb = V.Lag

# Conduct a conditional sort
sort.output <- conditional.sort(Fa,Fb,Fc=NULL,R.Forward = R.Forward,dimA = dimA,dimB = dimB)

# }

Run the code above in your browser using DataLab