Jul-26-2017, 03:10 PM
Hello Guys,
Coming from the matlab world, I am learning Python, so having some difficulties on very simple stuff. I want to know how to store each of these values in an array, inside the loop.
RightNow, when I execute that, it just gives the last value value calculated when I type NelsonSiegel.

Thank you
SB[/i][/i][/i][/i][/i][/i][/i][/i]
Coming from the matlab world, I am learning Python, so having some difficulties on very simple stuff. I want to know how to store each of these values in an array, inside the loop.
RightNow, when I execute that, it just gives the last value value calculated when I type NelsonSiegel.
from datetime import date import numpy as np SettleDate = date(2017,07,14) Bond1MaturityDate = date(2018,7,13) Bond3MaturityDate = date(2020,2,17) Bond5MaturityDate = date(2022,7,21) Bond10MaturityDate = date(2027,1,20) Bond15MaturityDate = date(2031,9,16) Bond20MaturityDate = date(2037,3,17) Yearfraction = [float((Bond1MaturityDate-SettleDate).days)/365,float((Bond3MaturityDate-SettleDate).days)/365, float((Bond3MaturityDate-SettleDate).days)/365, float((Bond5MaturityDate-SettleDate).days)/365, float((Bond10MaturityDate-SettleDate).days)/365, float((Bond15MaturityDate-SettleDate).days)/365, float((Bond20MaturityDate-SettleDate).days)/365] CouponRate = [0,0.0290,0.0321,0.0494,0.0585,0.0624] Beta0=0.01 Beta1=0.01 Beta2=0.01 Beta3=0.01 Lambda1=1 Lambda2=1 for i in range(len(Yearfraction)): NelsonSiegel = Beta0 + (Beta1 * ((1-np.exp(-Yearfraction[i]/Lambda1)/Yearfraction[i]*Lambda1))) + (Beta2 * ((((1-np.exp(-Yearfraction[i]/Lambda1))/(Yearfraction[i]*Lambda1))) - (np.exp(-Yearfraction[i]/Lambda1)))) + (Beta3 * ((((1-np.exp(-Yearfraction[i]/Lambda2))/(Yearfraction[i]*Lambda2))) - (np.exp(-Yearfraction[i]/Lambda2)))) print(NelsonSiegel)if i type NelsonSiegel in my ipython i just get the last value when i want to have a vector. I know its a very basic question.

Thank you
SB[/i][/i][/i][/i][/i][/i][/i][/i]