Comparing corresponding elements in two different matrixes
Ältere Kommentare anzeigen
Hello, I am currently working on a moving average crossover strategy. I have to large matrixes based on simulated stock returns , one with a short simple moving average based on 10 days. The other is based on a long term moving average of 50 days. Each row is is the simulated stock index value on a given day, while each column represents a separate simulation. Small parts of my matrixes can illustrate my problem:
movingaverageShort =
103.1030 101.1964
103.3101 101.2887
103.4311 101.3664
103.5291 101.4792
103.6529 101.4991
movingaverageLong =
105.2479 98.6675
105.8271 98.7421
106.2024 98.7601
106.8475 98.7827
107.3027 98.7431
When the short term moving average is greater then the long term moving average a buy signal is created. While when the long term moving average is greater the short term moving average a sell signal is created. I would like to return a matrix of signals, in this case it would be:
Signal= [Sell, Buy
Sell, Buy
Sell, Buy
Sell, Buy
Sell, Buy]
I have tried using if loops without any success. I am new to Matlab and would really appreciate any help=) Kind regards S. Tyssedal
Antworten (1)
sell = (movingaverageShort <= movingaverageLong);
Now an element which is true means a selling signal, false mean buying.
If you post your code, the readers could suggest an improvement and help you to recognize the bugs. The term "if loops" is confusing, because such a construct doe not exist in Matlab.
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!