Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Optimizing parameters trading system
Replies: 5   Last Post: Jul 24, 2012 4:20 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Sargondjani

Posts: 176
Registered: 8/30/11
Re: Optimizing parameters trading system
Posted: Jul 24, 2012 9:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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)



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.