Cannot initialize python function
<p>I have (re)wrote a back-test function in python using pandas</p>

<pre><code>def backtest(positions,price,initial_capital=10000):
    #creating protfolio
    portfolio =positions*price['price']    
    pos_diff=positions.diff()

    #creating holidings
    portfolio['holidings']=(positions*price['price'].sum(axis=1)
    portfolio['cash']=initial_capital-(pos_diff*price['price']).sum(axis=1).cumsum()

    #full account equity
    portfolio['total']=portfolio['cash']+ portfolio['holidings']
    portfolio['return']=portfolio['total'].pct_change()
    return portfolio
</code></pre>

<p>where <strong>positions</strong> and <strong>price</strong> are both dataframe of 1 column and 5 column respectively .</p>

<p>Inorder for checking error I run this function alone in my python but it is returning this error</p>

<pre><code>File "", line 8
    portfolio['cash']=initial_capital-(pos_diff*price['price']).sum(axis=1).cumsum()

SyntaxError: invalid syntax
</code></pre>

<p>missing trailing parenthesis on line before:</p>

<pre><code>portfolio['holidings']=(positions*price['price'].sum(axis=1)
                                               ^ need ) here
</code></pre>

<p>should be:</p>

<pre><code>portfolio['holidings']=(positions*price['price']).sum(axis=1)
</code></pre>

<p>Whenever you get a syntax error, look at the line before if the error and line in question look fine and doesn't make sense</p>

python pandas