0

I am trying to replicate some matlab code as a part of my master thesis from the paper Zhu, H. (2014). Do dark pools harm price discovery?

I have a system of two equations which i solve using the "NLsolve" package in Julia. The issue is that NLsolve returns a different solution for f[1] each time i run the code and sometimes it returns a "NaN".

I am not sure what is causing this?

Here is a code excerpt:

using NLsolve;

function G(x)
    min(1,x/C)
end;

function Ginv(x)
    min(C,x*C) 
end;

function F(x)
    1-exp(-x/2)
end;

μᵤ = 60;
σᵤ = sqrt(μᵤ);
a = [0 0];
b = [3*μᵤ 3*μᵤ];
r_bar = 0.91;
μ_bar  = 20;
C = 2;
x₀ = [μ_bar, 1.0];

function f_temp!(x,f)
   f[1] = μ_bar*F((1-G(1))*μᵤ*x[2]/(x[1]+(1-G(1))μᵤ))-x[1]
   f[2] = 1-x[1]/(x[1]+(1-G(1))μᵤ)-r_bar
end;

x = nlsolve(f_temp!, x₀)

Best regards, Rasmus

1 Answer 1

2

You have a wrong order of arguments in f_temp!. Use:

function f_temp!(f, x)
   f[1] = μ_bar*F((1-0.5)*μᵤ*x[2]/(x[1]+(1-0.5)μᵤ))-x[1]
   f[2] = 1-x[1]/(x[1]+(1-0.5)μᵤ)-r_bar
end;

and all should be fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.