jeudi 4 janvier 2018

Random Walk: SyntaxError: 'return' outside function

I am trying to do a Random Walk, so to do a Monte Carlo Simulation afterwards. Unfortunately, I got stuck on the end of the walk. I have checked already to find a solution, but, despite finding many with my same problem, nothing seems to work, but I am really struggling to understand why. My code is the following:

import random

def Financial_wealth(n):
"""Return coordinates after 'n=t' time in financial markets"""
x, y = 0, 0

for i in range(T+start_age):
   (dx, dy) = random.choice([(1, random.normalvariate(r, sigma)), (1, r)])
   x += dx
   y += dy
   return(x, y)

for i in range(T+start_age):
   walk = random_walk(1)
   print (walk, "Period-to-period return = ",
           ((walk[1]-walk[0])/walk[0]))

After running this, I get:

File "<ipython-input-13-a2dc598eb6f6>", line 15
   return(x, y)
   ^
SyntaxError: 'return' outside function

"T+start_age" is 65. I kept it like this in case i'll have to make changes in the future, but it does't seem to me (I really could be wrong) that the issue lies there.




Aucun commentaire:

Enregistrer un commentaire