W_sd_sr_out: Compute the optimal power-law parameter and the portfolio...

View source: R/Portfolio_management_crypto.R

W_sd_sr_outR Documentation

Compute the optimal power-law parameter and the portfolio weights according to the approach proposed by Kristoufek (2013) - [out-of-sample]

Description

This function computes the optimal power-law parameter and the portfolio weights according to the approach proposed by Kristoufek (2013) using out-of-sample data. Default lag for portfolio weights is 1, but it can be modified by the user.

Usage

W_sd_sr_out(V, alpha, ret_data, rf = 0.005, type = "StdDev", lag_ws = 1)

Arguments

V

a zoo object containing the Google Trends search terms (cryptocurrency ticker or other type)

alpha

is a vector of possible values for the power-law parameter alpha (usually between -2 and +2)

ret_data

a zoo object containing the return data of the selected cryptocurrencies

rf

is the risk-free rate needed for the computation of the SharpeRatio

type

one of "StdDev" or "VaR" or "ES" to use as the denominator for computing the SharpeRatio

lag_ws

the lag to be applied to the portfolio weights for computing the out-of-sample analysis

Details

This function computes the optimal power-law parameter alpha that min the std. dev or max the Sharpe ratio for the given dataset, using (pseudo) out-of-sample data. The portfolio weights (computed for a given alpha) are lagged by a quantity defined by lag_ws.

Value

a list containing the following objects:

sd_all

a vector of all standard deviations obtained in-sample for each value of alpha

min_sd

value of alpha that min the standard deviation in-sample

sr_all

a vector of all Sharpe Ratios obtained in-sample for each value of alpha

min_sr

value of alpha that max the Sharpe Ratio in-sample

References

Kristoufek, L. (2013). Can Google Trends search queries contribute to risk diversification?. Scientific reports, 3, 2713.

Examples

## Not run: 
library(PerformanceAnalytics)
data(crypto_google_data)
R <- crypto_google_data[,2:6]
R<- zoo::zoo( apply(R, 2, QuantTools::returns), order.by=lubridate::ymd(crypto_google_data[,1]))
R<-R[2:nrow(R),]
alpha <- seq(from = -2, to = 2, by = 0.1)
V=zoo::zoo(crypto_google_data[,7:11], order.by=lubridate::ymd(crypto_google_data[,1]) )
V<-V[2:nrow(V),]
google_port_out=W_sd_sr_out(V, alpha, ret_data=R, rf=0.003, type="StdDev", lag_ws=4)
#Plots
plot(y = google_port_out$sd_all,
     x = alpha,
     xlab = "Discrimination parameter",
     ylab = "StdDev",pch=21)
plot(y = google_port_out$sr_all,
     x = alpha,
     xlab = "Discrimination parameter",
     ylab = "SharpeRatio")
     
## End(Not run)


deanfantazzini/bitcoinFinance documentation built on June 12, 2024, 4:10 p.m.