0

I have a large set of with a matrix given by dataTS1 that is a 1069x25828 matrix. I have stored it as a time series/ financial time series using the fints command from the tool box.

I am not exactly sure how to implement a loop to work with this but I need something like an if statement but apparently, it doesn't let me combine inequalities for fints in Matlab. I have the following code:

 DataperSimple1 = [1; 2; 3; 0; -1; -3; 5; 3];
for n = 1:size(DataperSimple1,1)
    if DataperSimple1(n,1) ~= 0
        if DataperSimple1(n,1) < 0
            DataperSimple1(n+1,1) = -1*DataperSimple1(n+1,1);
        else
            DataperSimple1(n+1,1) = 1*DataperSimple1(n+1,1);
        end
    else
        DataperSimple1(n,1) = 0;
    end
end

I am a bit unsure about how the last condition should be phrased. If i write, DataperSimple1(n+1,1) = 0

then the entire matrix becomes a zero. In reality I only want the next period to be 0 and starting anew again. This would work well with the leadts for fints in Matlab but it doesnt allow me to do so with inequality signs.

In essence I want Matlab to read look at the sign of the value at row n and if it does not equal to 0, then move on to the conditions such that if it is less than 0, then multiply (-1) for the (n+1) row. If it is > 0, then just leave the (n+1) row as is.

Lastly, if the the n = 0, then only apply 0 to the n+1 row but now to have the same result applied to the n+2 row as that would recursively generate a matrix of 0's.

Any advice is appreciated. Thanks

PutsandCalls
  • 997
  • 1
  • 8
  • 11

0 Answers0