def get_simulation(ticker,name):
data=pd.DataFrame()
data[ticker]=wb.DataReader(ticker,data_source='yahoo',start='2020-1-1')['Adj Close']
log_return =np.log(1+data.pct_change())
u=log_return.mean()
var=log_return.var()

drift=u-(0.5*var)
stdev=log_returns.std()

t_intervals=365
iteration =10

daily_returns =np.exp(drift.value+ stdev.values*norm.ppf(np.random.rand(t_intervals,iterations))
S0=data.iloc[-1]
price_list=np.zeros_like(daily_returns)
price_list[0]=S0

for t in range(1,t_intervals):
price_list[t]=price_list[t-1]+daily_returns[t]

plt.figure(figsize=(10,6))
plt.title("1 year Monte Carlo Simulation"+name)
plt.ylabe("Price(P)")
plt.xlab("Time (Day)")
plt.plot(price_list)
plt.show()
get_simulation("MSFT","Microsoft Coperation")
Exemplo n.º 2
0
def plot_estimated_deriviative():
    def square(x):
        return x * x

    def derivative(x):
        return 2 * x

    derivative_estimate = lambda x: difference_quotient(square, x, h=0.00001)

    import mathplotlib.pyplot as plot
    x = range(-10, 10)
    plt.plot(x, map(derivative, x), 'rx')
    plt.plot(x, map(derivative_estimate, x), 'b+')
    plot.show()
Exemplo n.º 3
0
     def init():
     line.set_data([], [])
     return line,
     def animate(i):
     	# We let the particle evolve for 0.1 time units
     	simulator.evolve(0.01)
     	X = [p.x for p in simulator.particles]
     	Y = [p.y for p in simulator.particles]
     	line.set_data(X, Y)
     	return line,
 	# Call the animate function each 10 ms
 	anim = animation.FuncAnimation(fig, animate,  
   	init_func=init, blit=True,# Efficient animation
                                interval=10)
 	plt.show()
Exemplo n.º 4
0
import mathplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines["left"].set_position("center")
ax.spines["bottom"].set_position("zero")

ax.spines["right"].set_color("none")
ax.spines["top"].set_color("none")

xs = [x for x in range(-10, 11)]
ys = [x**2 for x in xs]

plt.plot(xs, ys)
plt.show()
Exemplo n.º 5
0
def test_run():
    df = pd.read_csv('data/APPL.csv')
    print df['Adj Close']
    df[['Adj Close', 'Close']].plot()
    plt.show()
Exemplo n.º 6
0
def print_img(img):
  plt.imshow(np.array(img))
  plt.show()
Exemplo n.º 7
0
 def show(self):
     """display the pseudocolor representation of the CA"""
     pyplot.show()