movavg is different using loop and matrix

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

movavg is different using loop and matrix

Octave - General mailing list
hi, look this esample:

DevPeriod=16;
Equity=magic(100);

   for hh=1:columns(Equity)
      ma1=movavg(Equity(:,hh),DevPeriod,DevPeriod,0);
  endfor

 ma2=movavg(Equity,DevPeriod,DevPeriod,0);


ma1 and ma2 are different from each other





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: movavg is different using loop and matrix

Dmitri A. Sergatskov
On Thu, Sep 5, 2019 at 4:35 PM gigiolone123 via Help list for GNU
Octave <[hidden email]> wrote:

>
> hi, look this esample:
>
> DevPeriod=16;
> Equity=magic(100);
>
>    for hh=1:columns(Equity)
>       ma1=movavg(Equity(:,hh),DevPeriod,DevPeriod,0);
>   endfor
>
>  ma2=movavg(Equity,DevPeriod,DevPeriod,0);
>
>
> ma1 and ma2 are different from each other
>

ma1 is a vector (100x1) and ma2 is a matrix (100x100)

Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: movavg is different using loop and matrix

siko1056
On 9/6/19 7:33 AM, Dmitri A. Sergatskov wrote:

> On Thu, Sep 5, 2019 at 4:35 PM gigiolone123 via Help list for GNU
> Octave <[hidden email]> wrote:
>>
>> hi, look this esample:
>>
>> DevPeriod=16;
>> Equity=magic(100);
>>
>>    for hh=1:columns(Equity)
>>       ma1=movavg(Equity(:,hh),DevPeriod,DevPeriod,0);
>>   endfor
>>
>>  ma2=movavg(Equity,DevPeriod,DevPeriod,0);
>>
>>
>> ma1 and ma2 are different from each other
>>
>
> ma1 is a vector (100x1) and ma2 is a matrix (100x100)
>
> Dmitri.
> --
>
>

`ma1` is a vector, because in each for-loop-iteration you are
overwriting `ma1` with another vector.  You have 99 pointless
computations and only hh=100 is available after the for-loop.

I think you intend something like:

```
pkg load financial

DevPeriod = 16;
Equity = magic(100);

for hh=1:columns(Equity)
  ma1(:,hh) = movavg(Equity(:,hh), DevPeriod, DevPeriod, 0);
endfor

ma2 = movavg (Equity, DevPeriod, DevPeriod, 0);
```

Note that there is an issue with movavg.  It cannot process matrices
like for `ma2`.  Please see https://savannah.gnu.org/bugs/?56829 for
details.

HTH,
Kai



Reply | Threaded
Open this post in threaded view
|

Re: movavg is different using loop and matrix

Octave - General mailing list