|
|
Re: Optimizing parameters trading system
Posted:
Jul 24, 2012 9:59 AM
|
|
"Jelle" wrote in message <jum90t$hlm$1@newscl01ah.mathworks.com>... > Dear Newsreader users, > > 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) > > *Trade signals with 1 = sell and -1 = buy > for k=2:length(Long) > if Short(k,:) > Long(k,:) && Short(k-1,:) < Long(k-1,:) > TradeSignal(k,:) = -1; % Buy > elseif Short(k,:) < Long(k,:) && Short (k-1,:) > Long(k-1,:) > TradeSignal(k,:) = 1; % Sell > else TradeSignal(k,:) = 0; > 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)
|
|