Error using eval Undefined function 'function' for input arguments of type 'double'.

Hi everyone,
When I try to run the following lines of code I keep getting the error that the function is undefined for input arguments of type 'double'. I have read online that this can be caused by a licensing issue with the package or that the directory is not correct. However, neither of these issues are the case here. What else can cause this error? Thanks in advance!
CODE:
% VaR Evaluation w/o mean
forecastdata = dataf(T+1:N-22+1,1);
eval(['forecastdata',num2str(jj),' = dataf(',num2str(T),'+',num2str(jj),':',num2str(N),'-22+',num2str(jj),');']);
eval(['TT',num2str(jj),' =size(forecastdata',num2str(jj),');']);
eval(['[LRPF95',num2str(jj),',LRPF95pv',num2str(jj),',LRPF99',num2str(jj),',LRPF99pv',num2str(jj),',LRind95',num2str(jj),',LRind95pv',num2str(jj),',LRind99',num2str(jj),',LRind99pv',num2str(jj),',LRcc95',num2str(jj),',LRcc95pv',num2str(jj),',LRcc99',num2str(jj),',LRcc99pv',num2str(jj),',TUFF95',num2str(jj),',TUFF99',num2str(jj),',PF95',num2str(jj),',PF99',num2str(jj),'] = VaRLRtest(forecastdata',num2str(jj),',VaR95',num2str(jj),',VaR99',num2str(jj),');']);
eval(['[RLF95',num2str(jj),',FLF95',num2str(jj),',RLF99',num2str(jj),',FLF99',num2str(jj),'] = VaRLossFUN(forecastdata',num2str(jj),',VaR95',num2str(jj),',VaR99',num2str(jj),');']);
ERROR:
Error using eval
Undefined function 'VaRLRtest' for input arguments of type 'double'.
Error in var_oos_evaluation (line 137)

15 Comments

If a software package forces you to write code that way, then you are better off without that software.
I was not able to locate any software package that matches what you are doing. I found one PUDN contribution that I cannot reach at the moment, that gave a name that I searched on and that in turn hinted that just maybe this has to do with code that was in Studies in Nonlinear Dynamics & Econometrics from 1996; https://sites.google.com/site/jurimarcucci/publications/hints-for-mrsgarch-program
Yes, I am using the code provided by Mr. Marcucci. So i'm assuming that this code has run in the past or earlier versions of Matlab
If you get the zip from https://sites.google.com/site/jurimarcucci/snde1145_supplementary_1.zip?attredirects=0 then that expands to a directory Marcucci_Programs_and_Data which has several files inside it, including VaRLRtest.m
Please confirm that that directory is on your MATLAB path. You can use MATLAB's pathtool to add it to your path.
Yes, i'm currently using the 'var_oos_evaluation.m' file and have the entire directory including the VaRLRtest.m file on my MATLAB path.
And, if you didn't already know, now you do why Walter's first comment! :)
Set a breakpoint at the offending line and inspect the content of the string being passed to eval to make sure it is what looks to be reasonable (probably).
See what the working path is when running the code and various diagnostics in that context like
which -all VaRLRtest
etc., to see what is returned. Is there some licensing agreement that goes with this code, perchance, that you haven't downloaded?
If you can run the function interactively, then it is something to do with the built command; if you can't get to the function at command line, then it has to do with install issues of some sort.
First I had to fix mrsgarchestfor_con_all -- change a size(x0) to size(x0,1), and comment out a couple of the optimset lines for options no longer supported.
I am waiting for that to finish running before I can see which other functions I need to execute in order to create the files needed for var_oos_evaluation to run (it needs a .mat that another function creates, and that other function needs files that other functions create, and ...)
"What else can cause this error?"
Badly written, badly designed, very smelly code that relies on counter-productive coding practices.
Throw that code in the binary-bin where it belongs.
Thanks for the comments everyone, I'm hoping that @Walter Roberson finds the solution in a bit. As I do need the code and I don't see anything wrong with the directory or other installment issues
Well, I'd suggest don't wait on Walter to solve your problems for you... :)
He gave you the road map to where issues lie, pick up and run with it.
When pick up a piece of code like that is, whether it's worth the effort to debug it or just write the needed functionality is often a hard choice. If the original author has orphaned it weighs a decision weighted to the latter in my view.
I am having to repair multiple places in the code as I go, and each run takes several hours. And then it fails a different way and I have to run for hours again. I also have no guidance about which programs have to be run in which order so that all the needed files get created. It would help if you told us the specific sequence of programs to run.
Yes of course! First, the 'garchest_for_con_all.m' and 'mrsgarchest_for_c_on_all.m' files have to be run. For these indeed size(x0) had to be changed to size(x0,1) in both files and I changed the optim functions to:
options = optimoptions('fmincon','MaxFunctionEvaluations',5000,'MaxIterations',2500,'Algorithm','interior-point','Display','iter','Diagnostics','on');
which seemed to do the trick for me. Besides this, some storing directories had to be changed. After these 2 files have completed (take the most time to run), the 'insampleevaluation.m' file should be run, runs very quickly and works fine. Then the 'var_forec_mrsg_var.m' file is up next. This file has some issues with the GEDinv function on line 122. I wasn't sure how to fix this properly. After this file has run, we arrive at the 'var_oos_evaluation.m', in which my problem lies.
I believe the error is caused by this piece of code in the 'var_forec_mrsg_var.m' file:
% computing multiperiod returns
load sp100_88_03_for.txt;
[y]=sp100_88_03_for;
T=3585; % In-Sample: 1/1/1988-9/28/2001
N = size(y,1);
dataf = 100*(log(y(2:N))-log(y(1:N-1))); % data to be forecast
N = N - 1; % You loose 1 obs'n in taking the lag
clear y;
for hh=[1 5 10 22]
for jj=0:510
eval(['forecastdata',num2str(hh),'(jj+1,1)=sum(dataf(T+jj+1:T+jj+hh));']);
end
eval(['save VaR_MRSGARCH forecastdata',num2str(hh),' -append;']);
end
As this line causes the forecastdata variable to be of a certain dimension different to the VaR95 variable later on. However, I still haven't found the solution how to change this..
@Deegan Huisman: given how badly-written that code is, you are likely to save time by writing the functionality yourself.
(Note: we have been gardening this weekend, so response is delayed)
The problem has been resolved. Rewriting the code was the way to go! Thanks everybody and I hope the gardening turned out good! ;p

Sign in to comment.

Answers (0)

Categories

Find more on Word games in Help Center and File Exchange

Asked:

on 5 Jun 2021

Commented:

on 7 Jun 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!