Subject: Momentum Strategy From: Steven Date: 14 May, 2012 12:39:08 Message: 1 of 9 Hey guys I've been trying to implement a momentum strategy in Matlab. What I'm trying to do is look at a bunch of stocks, find their past return, rank them and then invest in the two with the highest return. Then every quarter I want to invest let's say 200 in this (100 in each asset). Up until here my code works fine. Now let's say I have 1000 to invest, so at the first quarter I would have 800 left to invest. this would then be invested at a risk free rate. But then at the second quarter, the code should take out 200 from the risk free and invest this in the assets, so I never have more than 1000 invested. When there is nothing left from the risk free asset, the code should stop. Can anyone help me with this? That would be great. Steven
 Subject: Momentum Strategy From: Sargondjani Date: 14 May, 2012 13:09:08 Message: 2 of 9 lets say you have X invested in risk free asset, and you take dX (normally 200) to invest in another asset class: dX=min(200,max(0,X)); this way dX will be 200 when X>200, and X(>=0) when X<200
 Subject: Momentum Strategy From: Steven Date: 14 May, 2012 13:24:07 Message: 3 of 9 "Sargondjani" wrote in message ... > lets say you have X invested in risk free asset, and you take dX (normally 200) to invest in another asset class: > > dX=min(200,max(0,X)); > > this way dX will be 200 when X>200, and X(>=0) when X<200 Hi, thanks for your answer. I'm not sure how I would include this in my code though. could I send you my code by email? thanks
 Subject: Momentum Strategy From: Sargondjani Date: 14 May, 2012 18:13:08 Message: 4 of 9 you can post the core calculations here.... i really wonder which part you dont get, haha
 Subject: Momentum Strategy From: Steven Date: 14 May, 2012 19:06:07 Message: 5 of 9 OK my code so far is: but actually, I think I explained the supposed outcome wrong earlier. what I want is there to be a quarterly investment from the risk free asset in the other asset. so you start at the beginning of the year with in investment of 200 in the asset and 800 in the risk free. then after the 2nd quarter, as I said you have 400 and 600 ratio, then 600 400 and then at the end of the year you would have an 800 200 ratio. the point then, is not to invest the 200 in the asset as well and just keep it at a 1000 but to see how well the basket performed over the year, and then invest the remainder in the next year. sorry for this change! ret=zeros(31,1); retrf=zeros(31,1); weightsasset=zeros(31,1); weightsriskfree=zeros(31,1); for t=13:3:105     for b = 1:noofassets         m(b,:)=[b mean(returns((t-12):(t-1),b))];     end % end b          m=sortrows(m,2);          % to get money for each time period     for s=0:1:31         % money aset         weightsasset((t-1)/3-3,1)= weightsasset((t-1)/3-3,1)+200000+200000*s;                           %money risk free         weightsriskfree((t-1)/3-3,1)= weightsriskfree((t-1)/3-3,1)+800000-200000*s;              end          % returns of the asset     for a=1:2                  % Calculation of Portfolio Returns              ret((t-1)/3-3,1)=ret((t-1)/3-3,1)+(1/2*((assets(t+11,m(57-a,1))/assets(t,m(57-a, 1)))-1));              end % end a          % return of the risk-free     for t=13:3:105              retrf((t-1)/3-3,1)=retrf((t-1)/3-3,1)*(riskfree(t,1)/12);          end          %gain and loss for both asset and risk free     gain_loss((t-1)/3-3,1)=weightsasset((t-1)/3-3,1).*ret((t-1)/3-3,1);          gain_lossrf((t-1)/3-3,1)=weightsriskfree((t-1)/3-3,1).*retrf((t-1)/3-3,1); end % end t % cumulative K(1, 1) = 0; for a = 2:size(gain_loss,1)+1     K(a,1)=K(a-1,1)+gain_loss(a-1,1)+gain_lossrf(a-1,1); end
 Subject: Momentum Strategy From: Sargondjani Date: 15 May, 2012 11:08:06 Message: 6 of 9 "Steven" wrote in message ... > OK my code so far is: but actually, I think I explained the supposed outcome wrong earlier. what I want is there to be a quarterly investment from the risk free asset in the other asset. so you start at the beginning of the year with in investment of 200 in the asset and 800 in the risk free. then after the 2nd quarter, as I said you have 400 and 600 ratio, then 600 400 and then at the end of the year you would have an 800 200 ratio. the point then, is not to invest the 200 in the asset as well and just keep it at a 1000 but to see how well the basket performed over the year, and then invest the remainder in the next year. sorry for this change! > can you be a bit more specific about the actual strategy?? i mean, the only think i got from the above is: first year: invest 200 every quarter in the other asset second year: invest remainder in next year. i mean, the first is easy, but what rule do you want to use for the second year?? where does the momentum kick in?? also im abit confused by this part:     for s=0:1:31         % money aset         weightsasset((t-1)/3-3,1)= weightsasset((t-1)/3-3,1)+200000+200000*s;                           %money risk free         weightsriskfree((t-1)/3-3,1)= weightsriskfree((t-1)/3-3,1)+800000-200000*s;              end i think you want to initialize the weights for period 1 (outside the loop), and then add substract from that, because now it seems you add the initial state every time you go through this loop
 Subject: Momentum Strategy From: Steven Date: 15 May, 2012 11:48:09 Message: 7 of 9 the momentum just keeps coming from the fact that you always look at which assets performs best and then invest in those. so in the second year, you invest the remainder in this.
 Subject: Momentum Strategy From: Sargondjani Date: 15 May, 2012 19:30:07 Message: 8 of 9 "Steven" wrote in message ... > the momentum just keeps coming from the fact that you always look at which assets performs best and then invest in those. > so in the second year, you invest the remainder in this. ok. so just determine which return is higher? and determine what the remainder is? both are very basic operations. for the first you can us an if statement: if ret_asset>ret_riskfree  .... %invest remainder in asset else ... %invest remainder in asset end if you later want to use more assets then [value,index]=max(vector_of_returns); is more practical... the second thing (determine 'remainder) you can solve yourself, i suppose
 Subject: Momentum Strategy From: Steven Date: 16 May, 2012 07:02:09 Message: 9 of 9 OK thank you, that helps

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.