mardi 23 mai 2017

Why I keep getting invalid syntax error in Python while using nested if-else statement?

I am coding for my thesis, and I am new to Python in particular and programming in general. I would be grateful if someone could help me with this error.

File "C:/___/simple test.py", line 107 else: #when the insured portfolio pierce through the floor, all the money we have to be invested in risk-free assets ^ SyntaxError: invalid syntax

Process finished with exit code 1

Here is my part of code. I checked other parts and they were ok. I still do not understand what the problem with my structure of nested if else statement.

Thank you very much!

        if value_of_insured_portfolio[j,i] > pv_floor: #when the insured portfolio doesn't pierce through the floor (see p. 24 Thesis)
            cushion = value_of_insured_portfolio [j,i] - pv_floor
            exposure_to_vn30eq = cushion*m
            rf_asset = value_of_insured_portfolio[j,i]- exposure_to_vn30eq
            if exposure_to_vn30eq > value_of_insured_portfolio[j,i]: # in strong bull market, exceed the limit (see p.23 Thesis)
                value_of_insured_portfolio[j+1,i] = value_of_insured_portfolio[j,i]*np.exp(mc_array_path_return_local[j,i])
            else: #when vice versa, exposure to risky assets is less than the money we have
                value_of_insured_portfolio[j+1,i] = exposure_to_vn30eq*np.exp(mc_array_path_return_local[j,i]+rf_asset*np.exp(risk_free_local*dt) # Antonlovich use /250
        else:  # when the insured portfolio pierces through the floor, all the money we have to be invested in risk-free assets
            value_of_insured_portfolio[j + 1, i] = value_of_insured_portfolio[j, i] * np.exp(risk_free_local * dt)

Aucun commentaire:

Enregistrer un commentaire