Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Replies: 5   Last Post: Jul 24, 2012 4:20 PM

 Messages: [ Previous | Next ]
 Sargondjani Posts: 176 Registered: 8/30/11
Posted: Jul 24, 2012 9:59 AM

"Jelle" wrote in message <jum90t\$hlm\$1@newscl01ah.mathworks.com>...
>
> I need some help on an optimization problem:
> I constructed a Dual Moving Average trading system (DMA) using 2 moving averages derived from a stock. Now I want to optimize the trading system by changing the periods of the moving averages, in order to maximize my sharpe ratio (i.e. risk-adjusted profit). Below I added some brief backround info of my trading model (1) and the thoughts on optimizing the moving averages (2). I need help with the optimization part....
>
>
> (1) --------Some basic backround info of my trading model------------
>
> I used the following function to define the trade signals
> Short = 1 * 1 day moving average
> Long = 30 * 30 day moving average
>
> [Short, Long] = movavg(Data.ClosingPrices(:,1), Short, Long)
>
> for k=2:length(Long)
> if Short(k,:) > Long(k,:) && Short(k-1,:) < Long(k-1,:)
> elseif Short(k,:) < Long(k,:) && Short (k-1,:) > Long(k-1,:)
> TradeSignal(k,:) = 1; % Sell
> end
> end
>
> sh = sharpe(Compounded_return,1.42)
>
> -----------------------------------Optimization-------------------------------
> I tried to optimize the Long indicator first using the following script, derived from a matlab tutrial webinar (Algorithmic Trading with MATLAB for Financial Applications )
>
> sh = nan(100,1);
> for m = 2:100
> [~,~,sh(m)] = movavg(Data.Closing(:,1), Short, m)
> end
>
> [~,mxInd] = max(sh)
> movavg(Data.Closing(:,1), Short, mxInd)
>
> I get the following error:
> ??? Error using ==> movavg
> Too many output arguments.

movavg has two output arguments [short,long], but you ask for 3: [~,~,sh(m)], that's why you get an error i think (i dont know about the function 'movavg' but it looks like this)

Date Subject Author
7/24/12 Jelle
7/24/12 Sargondjani
7/24/12 Jelle
7/24/12 Jelle
7/24/12 Sargondjani
7/24/12 Jelle