testscripts/qEfficientFrontierUnitTest.R

#' K Means Unit Test
#' Simulating test data that Qlik will send to opencpu to validate the R code is working
#' 
#' Load in the necessary Libraries
library("quadprog", lib.loc="~/R/win-library/3.1")
library("rjson", lib.loc="~/R/win-library/3.1")
library("qEfficientFrontier", lib.loc="~/R/win-library/3.1")

#' Simulating test data that Qlik will send to openCPU
QlikJson <- 
  '{"data":{
      "Date":["41950","41949","41948","41947","41946","41943","41942","41941","41940","41939","41936","41935","41934","41933","41932","41929","41928","41927"],
      "SPY":["0.000935269505291547","0.0040031629929822","0.00631620828567181","-0.00346929672399277","0.000545472577605954","0.0114354498946736","0.00641057998081873","-0.00151202056347954","0.0114702283849919","-0.00137453545792399","0.00769507002513725","0.0116248897192381","-0.00711083629618181","0.019810825013137","0.00970976813285951","0.0118108122617704","-0.000858230971410134","-0.00676611614278089"],
      "EFA":["0.000477554918815626","-0.0053831538948701","0.00190355329949243","-0.00567823343848584","-0.00860046911649737","0.0184742793438446","0.00721847930702602","-0.00764087870105057","0.0151906916612798","-0.00562429696287958","0.00549361770883827","0.0096247960848288","-0.00728744939271264","0.0119632907243525","0.0062664907651715","0.0186460608096757","-0.00931935430188058","-0.00595533498759304"],
      "IWM":["0.00154466660945674","0.00430923037145559","0.00181315834916251","-0.00464077002406327","-0.00171585449553879","0.0147122834508575","0.00851624231782266","-0.00236489445563626","0.0284659039726149","-0.000540199873953262","0.00171356421356417","0.0177145479577787","-0.0142947616031847","0.0164612837962113","0.0117231112765164","-0.00296846011131724","0.0112570356472796","0.0100435853704754"],
      "VWO":["0.00649975926817525","-0.0142382534409112","-0.00589761736258554","0.000944510035419066","-0.00680112570356473","0.00803782505910178","0.0114777618364419","-0.00190930787589494","0.0209551656920077","-0.0103689414034241","0.009493670886076","0.000974658869395739","-0.00797679477882518","0.00461389023797953","0.000729040097205313","0.0127984248092541","-0.00999025341130599","-0.0139356078808265"],
      "LQD":["0.00633660020277116","-0.00303234501347704","-0.00184967210358167","0.00143133787993599","-0.00477626948215193","-0.000167560321715832","0.000670690811535923","-0.00184100418410038","-0.00333611342785656","0.00125260960334028","0.00041771094402665","-0.00191778537480203","-0.00166486306501279","-0.000582362728785424","0.00183363893982325","-0.000416562526035169","-0.0022443890274314","0.000748689792862578"],
      "HYG":["0.000975609756097562","0.00260841212911633","-0.000217320438987256","-0.00314124783362213","-0.00226953420512277","0.000865332612222769","-0.000432479186939005","-0.000756266205704459","0.00162320095227786","-0.00409526888673362","0.00280989949205668","-0.000432105433725738","-0.00654646919939916","0.00811424862057764","0.00719189277541687","0.00846153846153852","0.00563598187645042","0.000221067757267601"]
  },
    "type":{
      "Date":"dimension",
      "SPY":"expression",
      "EFA":"expression",
      "IWM":"expression",
      "VWO":"expression",
      "LQD":"expression",
      "HYG":"expression"
  },
    "param":{
      "short":"0",
      "max_allocation": "0.4",
      "risk_premium_up": ".5",
      "risk_increment": ".005"
  }
}'

#' OpenCPU will automatically convert it to a list using fromJSON
OpenCpuData <- fromJSON(QlikJson)




#' List is pass to the function and return back to Qlik in JSON format
eff_frontier(OpenCpuData)
samuelpena/qEfficientFrontier documentation built on May 29, 2019, 1:45 p.m.