[R] Non-linear optimisation

Ravi Varadhan rvaradhan at jhmi.edu
Thu Feb 5 20:37:28 CET 2009


Hi,

I don't understand your Matlab code.  However, let me say this:

 - you could use "L-BFGS-B" algorithm in optim() or nlminb(), if you only have box constraints

 - you could use ConstrOptim(), if you only have linear inequality constraints

 - you could use Rdonlp2 if you have more general equality/inequality constraints

Best,
Ravi.

____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: ehxpieterse <eduard.pieterse at macquarie.com>
Date: Thursday, February 5, 2009 2:03 pm
Subject: [R]  Non-linear optimisation
To: r-help at r-project.org


>  Hi there,
>  
>  I have a piece of Matlab code I use to optimise a trding strategy. If 
> there
>  are any Matlab/R specialists out there, I would appreciate your help 
> in
>  doing the exact same optimisation in R.
>  
>  I suspect I would use nlm() in R but am not sure where to define my
>  constraints.
>  
>  I have attached my Matlab code below for reference.
>  
>  Many thanks.
>  
>  Constraints
>  function [c,ceq]=TriskellConstraints(X)
>  global objFunc_vol;
>  [a,b] = objFunc_vol(X);
>  c(1) = b-6.5;
>  c(2) = std(X(:))-6.5;
>  ceq = [];
>  end
>  
>  Optimise
>  global objFunc_vol
>  objFunc_vol = @(C) compute_strategy_before_fees(prices, C, floor, cap,
>  m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
>  fixed_fees, var_fees);
>  
>  objFunc_vol(C);
>  
>  objFunc = @(C) compute_strategy_before_fees(prices, C, floor, cap,
>  m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
>  fixed_fees, var_fees);
>  
>  objFunc(C);
>  
>  options = optimset('MaxIter',10000000,'MaxFunEvals',10000000);
>  
>  tic;
>  
>  % OPTIMISE
>  
>  %M =
>  fmincon(objFunc,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9), at TriskellConstraints,options);
>  M =
>  fmincon(objFunc_vol,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9), at TriskellConstraints,options);
>  [Z, ZZ] = compute_strategy_after_fees(prices, C, floor, cap, m_ret_reb,
>  prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
>  var_fees, dates, variation_cap_property, eurusd);
>  [Y, YY] = compute_strategy_after_fees(prices, M, floor, cap, m_ret_reb,
>  prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
>  var_fees, dates, variation_cap_property, eurusd);
>  
>  timespent = toc/60; %converts to minutes
>  
>  
>  -- 
>  View this message in context: 
>  Sent from the R help mailing list archive at Nabble.com.
>  
>  ______________________________________________
>  R-help at r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list