Hi all
just put together this little bit of code... I am sure it is heavily flawed:(... but can someone please point out to me the reason why it becomes slower after every loop. thanks!!!
** ....i am using "globals()[]" to try and create dynamic variables.. i am guessing that this a very bad way to do it?
thanks again!
just put together this little bit of code... I am sure it is heavily flawed:(... but can someone please point out to me the reason why it becomes slower after every loop. thanks!!!
** ....i am using "globals()[]" to try and create dynamic variables.. i am guessing that this a very bad way to do it?
Code:
j = 0
while j < x:
s = 0
while s < len(securityNamesList):
globals()[securityNamesList[s] + 'adjustedHPR'] = []
k = 0
while k < len(globals()[securityNamesList[0] + 'dollarHPRS']):
globals()[securityNamesList[s] + 'adjustedHPR'].append(globals()[securityNamesList[s] + 'FinalDistribution'][j] * globals()[securityNamesList[s] + 'dollarHPRS'][k])
k = k + 1
s = s + 1
k = 0
while k < len(globals()[securityNamesList[0] + 'adjustedHPR']):
s = 0
todaysHPR = 0
while s < len(securityNamesList):
todaysHPR = todaysHPR + globals()[securityNamesList[s] + 'adjustedHPR'][k]
s = s + 1
portfolioHPR.append( 1 + todaysHPR )
k = k + 1
portfolioDailyMeanReturn = stats.lmean(portfolioHPR)
portfolioDailyStandardDeviation = stats.stdev(portfolioHPR)
portfolioAnnualStandardDeviation = portfolioDailyStandardDeviation * 16
portfolioDailyEstimatedGeometricMean = math.sqrt(portfolioDailyMeanReturn ** 2 - portfolioDailyStandardDeviation ** 2 )
portfolioAnnualEstimatedGemoetricMean = portfolioDailyEstimatedGeometricMean ** 256
portfolioSharpeRatio = (portfolioAnnualEstimatedGemoetricMean - 1) / portfolioAnnualStandardDeviation
sharpeRatioList.append(portfolioSharpeRatio)
j = j + 1
Comment