Help : IndexError - probably pretty simple
Steven D. Majewski
sdm7g at Virginia.EDU
Thu Oct 18 11:59:48 EDT 2001
On 18 Oct 2001, JT wrote:
> def CRRBi(ae="a", cp="c", stock=100, strike=100, time=(1.00/12),
> interest=0.6, cc=0.10, vol=1.00, n=10):
> """CRRBi: the Cox-Ross-Rubinstein Binomial Option Pricing Model"""
> ov = []
'ov' initialized to the empty list: len(ov) -> 0
...
> for i in range(n):
> ov[i] = max(0, z * (stock * pow(u, i) * pow(d, n-1) - strike))
default value for n=10: iterate over ov[0] ... ov[9], except len = 0,
so > IndexError: list assignment index out of range
I'm not quite sure exactly what you OUGHT to be doing for this algorithm,
but you might try either initializing ov = [0]*n, (i.e. with n zero's )
or else add values to the list with ov.append.
-- Steve Majewski
More information about the Python-list
mailing list