def profile(self, path_input=None):
"""
Calculate the profile made by your portfolio. It will give out the number of money you made, instead of pecentage.
"""
profile = []
profileratio = []
sum_of_profile = 0
for stock_single in self.stocklist:
print("Now processing:", stock_single)
self.stockdata[stock_single] = ts.get_hist_data(stock_single, self.start, self.end)['close']
profileratio.append((self.stockdata[stock_single].loc[self.end]-self.stockdata[stock_single].loc[self.start])/self.stockdata[stock_single].loc[self.start])
for i in range(0, len(self.stocklist)):
profile.append(self.moneyallocation[i] * float(profileratio[i]))
if math.isnan(profile[i]) != True:
sum_of_profile = profile[i] + sum_of_profile
else:
pass
for i in range(0, len(profile)):
print(self.stocklist[i], profile[i],"\n")
print("Totel profile is", sum_of_profile)
# Update: 2017-08-12
try:
if path_input != None:
_profile_stock_list = self.stocklist.append('Totel profile')
_profile_single_stock = profile.append(sum_of_profile)
_profile_data = {'List':_profile_stock_list, 'Profile':_profile_stock_list}
_profile = pd.DataFrame(_profile_data)
_profile.to_csv(path_input+'profile.csv')
elif self.defaultpath:
_profile_stock_list = self.stocklist.append('Totel profile')
_profile_single_stock = profile.append(sum_of_profile)
_profile_data = {'List':_profile_stock_list, 'Profile':_profile_stock_list}
_profile = pd.DataFrame(_profile_data)
_profile.to_csv(self.defaultpath+'profile.csv')
else:
pass
except IOError:
print('Path not exists!')
评论列表
文章目录