Mar-21-2018, 06:18 AM
I'm beginner of Python and has tried finance analytic with the book 'python for Finance'.
The following codes from the book output a syntax error:invalid error.
Does anyone know why this is outputting the error?
------------------------------------------------------------------------------
def print_statistics(a1, a2):
''' Prints selected statistics.
Parameters
==========
a1, a2 : ndarray objects
results object from simulation
'''
sta1 = scs.describe(a1)
sta2 = scs.describe(a2)
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
print 45 * "-"
print "%14s %14.3f %14.3f" % ('size', sta1[0], sta2[0])
print "%14s %14.3f %14.3f" % ('min', sta1[1][0], sta2[1][0])
print "%14s %14.3f %14.3f" % ('max', sta1[1][1], sta2[1][1])
print "%14s %14.3f %14.3f" % ('mean', sta1[2], sta2[2])
print "%14s %14.3f %14.3f" % ('std', np.sqrt(sta1[3]), np.sqrt(sta2[3]))
print "%14s %14.3f %14.3f" % ('skew', sta1[4], sta2[4])
print "%14s %14.3f %14.3f" % ('kurtosis', sta1[5], sta2[5])
------------------------------------------------------------------------------
File "<ipython-input-42-2f1e93a3fe96>", line 11
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
^
SyntaxError: invalid syntax
The following codes from the book output a syntax error:invalid error.
Does anyone know why this is outputting the error?
------------------------------------------------------------------------------
def print_statistics(a1, a2):
''' Prints selected statistics.
Parameters
==========
a1, a2 : ndarray objects
results object from simulation
'''
sta1 = scs.describe(a1)
sta2 = scs.describe(a2)
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
print 45 * "-"
print "%14s %14.3f %14.3f" % ('size', sta1[0], sta2[0])
print "%14s %14.3f %14.3f" % ('min', sta1[1][0], sta2[1][0])
print "%14s %14.3f %14.3f" % ('max', sta1[1][1], sta2[1][1])
print "%14s %14.3f %14.3f" % ('mean', sta1[2], sta2[2])
print "%14s %14.3f %14.3f" % ('std', np.sqrt(sta1[3]), np.sqrt(sta2[3]))
print "%14s %14.3f %14.3f" % ('skew', sta1[4], sta2[4])
print "%14s %14.3f %14.3f" % ('kurtosis', sta1[5], sta2[5])
------------------------------------------------------------------------------
File "<ipython-input-42-2f1e93a3fe96>", line 11
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
^
SyntaxError: invalid syntax