tests/testthat/test_semidev.R

context("Semideviation") 

test_that("Dimensions", { 
  T = 100
  N = 25
  set.seed(123)
  rets  = matrix(rnorm(T * N), nrow = T, ncol = N)
  
  sig = semidevEstimation(rets)
  expect_equal(length(sig), N)
  
  sig = semidevEstimation(rets, control = list(type = 'naive'))
  expect_equal(length(sig), N)
  
  sig = semidevEstimation(rets, control = list(type = 'ewma'))
  expect_equal(length(sig), N)
  
  sig = semidevEstimation(rets, control = list(type = 'ewma', lambda = 0.9))
  expect_equal(length(sig), N)
}) 

test_that("Positivity", { 
  
  f.test.pos = function(x) {
    out = all(x >= 0)
    return(out)
  }
  
  T = 100
  N = 25
  set.seed(123)
  rets  = matrix(rnorm(T * N), nrow = T, ncol = N)
  
  sig = semidevEstimation(rets)
  expect_true(f.test.pos(sig))
  
  sig = semidevEstimation(rets, control = list(type = 'naive'))
  expect_true(f.test.pos(sig))
  
  sig = semidevEstimation(rets, control = list(type = 'ewma'))
  expect_true(f.test.pos(sig))
  
  sig = semidevEstimation(rets, control = list(type = 'ewma', lambda = 0.9))
  expect_true(f.test.pos(sig))
  
  Sigma = covEstimation(rets)
  expect_true(f.test.pos(sig))
}) 

Try the RiskPortfolios package in your browser

Any scripts or data that you put into this service are public.

RiskPortfolios documentation built on May 17, 2021, 1:10 a.m.