By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,055 Members | 569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,055 IT Pros & Developers. It's quick & easy.

Correct return in plot but not when printing values of function

P: 1
Hi. My code below:


Expand|Select|Wrap|Line Numbers
  1. def simulate_stock(start,rate,vol,days):
  2.     daily_yields=np.random.normal(loc=(rate/252),scale=(vol/(252**0.5)),size=days)
  3.     cumulative_yields=np.cumsum(daily_yields)
  4.     daily_multipliers=np.exp(cumulative_yields)
  5.     simulated_prices = np.round(start * daily_multipliers, 2)
  6.     simulated_prices = np.concatenate(([start],simulated_prices))
  7.     return simulated_prices
  8.  
  9.  
  10. def find_yield(run):
  11.     sim_price_length = len(simulated_prices)
  12.     final_price = simulated_prices[sim_price_length-1]
  13.     init_price = simulated_prices[0]
  14.     annual_yield = math.log(final_price/init_price, math.e)*(252/(days))
  15.     return annual_yield
  16.  
  17. i = 0
  18. yield_list = []
  19. for i in range(25):
  20.     simulations = simulate_stock(100,0.06,0.4,200)
  21.     plt.plot(simulations)
  22.     yield_val = find_yield(simulations)
  23.     yield_list.append(yield_val)

Now when I plot different graphs as needed. When I print yield_list*I see a single array with an only value which doesn't make sense. What I am doing wrong?
Regards
1 Week Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.