[R] Non-linear optimisation
ehxpieterse
eduard.pieterse at macquarie.com
Thu Feb 5 18:28:00 CET 2009
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: http://www.nabble.com/Non-linear-optimisation-tp21856818p21856818.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list