Fmincon with Nested Optimization
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have to maximize the sharpe ratio, but my weights are given by an equation. I am not knowing how to connect that with fmincon
function [y] = w2(a) %function for weight
global avrcc avrco avroc avroo avrrvp avrtvl rcc rco roc roo tvl rvp i j n
y = a(1)*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(2)*(roo(i,j)-avroo(i))./n...
+ a(3)*(roc(i-1,j)-avroc(i-1))./n ...
+ a(4)*(rco(i,j)-avrco(i))./n...
+ a(5)*(tvl(i-1,j)/avrtvl(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(6)*(tvl(i-1,j)/avrtvl(i-1, j))*(roo(i,j)-avroo(i))./n...
+ a(7)*(tvl(i-1,j)/avrtvl(i-1,j))*(roc(i,j)-avroc(i-1))./n...
+ a(8)*(tvl(i-1,j)/avrtvl(i-1,j))*(rco(i,j)-avrco(i))./n...
+ a(9)*(rvp(i-1,j)/avrrvp(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(10)*(rvp(i-1,j)/avrrvp(i-1,j))*(roo(i,j)-avroo(i))./n...
+ a(11)*(rvp(i-1,j)/avrrvp(i-1,j))*(roc(i-1,j)-avroc(i-1))./n...
+ a(12)*(rvp(i-1,j)/avrrvp(i-1,j))*(rco(i,j)-avrco(i))./n;
end
My function for sharpe ratio is as follows
function [y] = msharper(mu,Q,rf)
y = mu-rf/sqrt(w2(a)'*Q*w2(a));
end
I do not know how to apply fmincon such a way that I find the values of a vector.
2 Commenti
Walter Roberson
il 12 Set 2018
It is not clear which variable you are optimizing over? Is it a ? If so then it should be an input to msharper()
Risposta accettata
Matt J
il 12 Set 2018
Modificato: Matt J
il 12 Set 2018
My approach would be to modify the functions as follows, taking into account Walter's remarks and also getting rid of the global variables,
function [y] = w2(a, avrcc, avrco, avroc, avroo, avrrvp,...
avrtvl, rcc, rco, roc, roo, tvl, rvp, i, j, n)
y = a(1)*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(2)*(roo(i,j)-avroo(i))./n...
+ a(3)*(roc(i-1,j)-avroc(i-1))./n ...
+ a(4)*(rco(i,j)-avrco(i))./n...
+ a(5)*(tvl(i-1,j)/avrtvl(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(6)*(tvl(i-1,j)/avrtvl(i-1, j))*(roo(i,j)-avroo(i))./n...
+ a(7)*(tvl(i-1,j)/avrtvl(i-1,j))*(roc(i,j)-avroc(i-1))./n...
+ a(8)*(tvl(i-1,j)/avrtvl(i-1,j))*(rco(i,j)-avrco(i))./n...
+ a(9)*(rvp(i-1,j)/avrrvp(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(10)*(rvp(i-1,j)/avrrvp(i-1,j))*(roo(i,j)-avroo(i))./n...
+ a(11)*(rvp(i-1,j)/avrrvp(i-1,j))*(roc(i-1,j)-avroc(i-1))./n...
+ a(12)*(rvp(i-1,j)/avrrvp(i-1,j))*(rco(i,j)-avrco(i))./n;
end
function [y] = msharper(a, mu,Q,rf,weightfun)
y = mu-rf/sqrt(weightfun(a)'*Q*weightfun(a));
end
and then in the main workspace,
weightfun=@(a) w2(a, avrcc, avrco, avroc, avroo, avrrvp,...
avrtvl, rcc, rco, roc, roo, tvl, rvp, i, j, n);
a_opt = fmincon @(a) msharper(a, mu,Q,rf,weightfun), __________ );
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!