Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve r interface #61

Merged
merged 17 commits into from
Feb 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update compute_indicators
TolisChal committed Feb 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a6f18e0ff5a866bd9a3177bab4b41c4f2d3cb995
10 changes: 7 additions & 3 deletions R-proj/R/compute_indicators.R
Original file line number Diff line number Diff line change
@@ -8,18 +8,22 @@
#' @param win_length Optional. The length of the sliding window. The default value is 60.
#' @param m Optional. The number of slices for the copula. The default value is 100.
#' @param n Optional. The number of points to sample. The default value is \eqn{5\cdot 10^5}.
#' @param nwarning Optional. The number of consecutive indicators larger than 1 required to declare a warning period. The default value is 60.
#' @param ncrisis Optional. The number of consecutive indicators larger than 1 required to declare a crisis period. The default value is 100.
#'
#' @references \cite{L. Cales, A. Chalkis, I.Z. Emiris, V. Fisikopoulos,
#' \dQuote{Practical volume computation of structured convex bodies, and an application to modeling portfolio dependencies and financial crises,} \emph{Proc. of Symposium on Computational Geometry, Budapest, Hungary,} 2018.}
#'
#' @return A list that contains the indicators and the corresponding vector that label each time period with respect to the market state: a) normal, b) crisis, c) warning.
#'
#' @export
compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL) {
compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL, nwarning = NULL, ncrisis = NULL) {

if (is.null(win_length)) win_length = 60
if (is.null(m)) m = 100
if (is.null(n)) n = 500000
if (is.null(nwarning)) nwarning = 60
if (is.null(ncrisis)) ncrisis = 100

nrows = dim(returns)[1]
nassets = dim(returns)[2]
@@ -72,9 +76,9 @@ compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL) {
set_index = TRUE
} else if (indicators[i]<1) {
if(set_index){
if(i-index+1>30 && i-index+1<60){
if(i-index+1 > nwarning && i-index+1 < ncrisis){
col[index:i] = "warning"
} else if(i-index+1>60) {
} else if(i-index+1 > ncrisis) {
col[index:i] = "crisis"
}
}
7 changes: 6 additions & 1 deletion R-proj/man/compute_indicators.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.