Why it raises error when print the return values of function for non-linear equations
<p>I use fsolve to solve equations, but when I put the solution into the KMV() function again, it raises an exception. I can not figure it out... </p>

<pre><code>def KMV(x, *args):
    valueToEquity = float(x[0])
    volOfValue = float(x[1])
    equityToDebt, volOfEquity, riskFreeRate, TimeToMaturity = args
    d1 = (np.log(equityToDebt * equityToDebt) + (riskFreeRate + 0.5 *    volOfEquity**0.5)
      * TimeToMaturity) / (volOfEquity * TimeToMaturity**0.5)
    d2 = (np.log(abs(equityToDebt * equityToDebt)) + (riskFreeRate - 0.5 * volOfEquity**0.5)
      * TimeToMaturity) / (volOfEquity * TimeToMaturity**0.5)
    f1 = valueToEquity * norm.cdf(d1) - np.exp(-riskFreeRate * TimeToMaturity) * norm.cdf(d2) / equityToDebt - 1
    f2 = norm.cdf(d1) * valueToEquity * volOfValue - volOfEquity
    return f1, f2



def solver():
    equityToDebt = 1
    volOfEquity = 0.2
    riskFreeRate = 0.03
    TimeToMaturity = 1
    args = equityToDebt, volOfEquity, riskFreeRate, TimeToMaturity
    x0 = [1, 0.2]
    sol = fsolve(KMV, x0, args=args)
    print(sol)
</code></pre>

<p>The solutions I get is </p>

<pre><code>[ 1.29409904  0.17217742]
</code></pre>

<p>However if I use the following code:</p>

<pre><code>print(KMV(sol, args=args))
</code></pre>

<p>The exception is shown as below:</p>

<pre><code>    print(KMV(sol, args = args))
TypeError: KMV() got an unexpected keyword argument 'args'
</code></pre>

<p>Then I changed into another way to call KMV():</p>

<pre><code>print(KMV(sol, args))
</code></pre>

<p>The exception is another one:</p>

<pre><code>ValueError: need more than 1 value to unpack
</code></pre>

<p>Just take a look at this quick reminder...</p>

<pre><code>def func(arg1):
    print(arg1)

func('hello') # output 'hello'

def func(*args):
    # you can call this function with as much arguments as you want !
    # type(args) == tuple
    print(args)

func('some', 'args', 5) # output ('some', 'args', 5)

def func(required_arg, optional_arg=False, other_optional_arg='something'):
    print(required_arg, optional_arg, other_optional_arg)

    # so, say you just want to specify the value of other_optional_arg, and let optional_arg have its default value (here False)
    # with python, you can do this

func('the value for the required arg', other_optional_arg='My super great value') # output ('the value for the required arg', False, 'My super great value')

def func(**kwargs):
    # type(kwargs) = dict
    print(kwargs )

func(arg1='hello', arg2='world', arg3='!') # output {'arg3': '!', 'arg2': 'world', 'arg1': 'hello'}
</code></pre>

python scipy