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")
Esempio n. 2
0
import sys
sys.path.append('/usr/local/anaconda3/lib/python3.6/site-packages')
from math import sqrt
from numpy import cos ** 2 (x/2), linspace

def f(x):
    return cos**2(x/2)

x = linspace(0, 4, 11)
print(x)
#y = sin(x)
y = f(x)
print(y)

legend[]

from mathplotlib import pyplot as plt
plt.grid()
plt.xlabel("x")
plt.ylabel("y")
plt.title("Cosinus funkcija un taas atvasinaajumi")
plt.plot(x, y, "k")
legend.append("$scos**2(x/2)$ funkcija")

plt.plot(x, y, "go")
legend.append("$cos**2(x/2)$ funkcija(dazhi punkti)")
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()
Esempio n. 4
0
    print(plt._doc_)
AttributeError: module 'matplotlib.pyplot' has no attribute '_doc_'
>>> print(plt.__doc__)

`matplotlib.pyplot` is a state-based interface to matplotlib. It provides
a MATLAB-like way of plotting.

pyplot is mainly intended for interactive plots and simple cases of programmatic
plot generation::

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.arange(0, 5, 0.1)
    y = np.sin(x)
    plt.plot(x, y)

The object-oriented API is recommended for more complex plots.

>>> 
================= RESTART: /home/user/RTR105/Atvasinajums.py =================
Traceback (most recent call last):
  File "/home/user/RTR105/Atvasinajums.py", line 30, in <module>
    print(plt.legend._doc_)
AttributeError: 'function' object has no attribute '_doc_'
>>> 
================= RESTART: /home/user/RTR105/Atvasinajums.py =================
Traceback (most recent call last):
  File "/home/user/RTR105/Atvasinajums.py", line 30, in <module>
    print(plt.legend._doc_)
AttributeError: 'function' object has no attribute '_doc_'
Esempio n. 5
0

def wald(table):
    N = np.sum(table)
    rowsums = [np.sum(x) for x in table]
    colsums = [np.sum(x) for x in table.T]
    p1 = table[0][0] / colsums[0]
    p2 = table[0][1] / colsums[1]
    p = rowsums[0] / N
    return (p1 - p2) / np.sqrt(p * (1 - p) *
                               (1.0 / rowsums[0] + 1.0 / rowsums[1]))


N, m, n = 14, 2, 2
position = [posi for posi in range(N + m * n - 1)]
walds = []
chis = []
stars = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
for x in permutations(balls):
    i = 0
    t = [0, 0, 0, 0]
    for s in stars:
        if (s == 0):
            i += 1
        t[i] += 1
    table = np.array([[t[0], t[1]], [t[2], t[3]]])
    walds.append(wald(table))
    chis.append(chisquare(table))
print len(waltl)
plt.plot(chis, walds)
Esempio n. 6
0
================= RESTART: /home/user/RTR105/atvasinajums.py =================
>>> print(plt.__doc__)

`matplotlib.pyplot` is a state-based interface to matplotlib. It provides
a MATLAB-like way of plotting.

pyplot is mainly intended for interactive plots and simple cases of programmatic
plot generation::

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.arange(0, 5, 0.1)
    y = np.sin(x)
    plt.plot(x, y)

The object-oriented API is recommended for more complex plots.

>>> print(plt.plot__doc__)
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    print(plt.plot__doc__)
AttributeError: module 'matplotlib.pyplot' has no attribute 'plot__doc__'
>>> print(plt.plot.__doc__)
Plot lines and/or markers to the
:class:`~matplotlib.axes.Axes`.  *args* is a variable length
argument, allowing for multiple *x*, *y* pairs with an
optional format string.  For example, each of the following is
legal::
Esempio n. 7
0
        colsums = [np.sum(x) for x in table.T]
        n = np.outer(rowsums,colsums)*1.0/N
        return np.sum( (table - n )**2/n)

def wald(table):
        N = np.sum(table)
        rowsums = [np.sum(x) for x in table]
        colsums = [np.sum(x) for x in table.T]
        p1= table[0][0]/colsums[0]
        p2=table[0][1]/colsums[1]
        p= rowsums[0]/N
        return (p1-p2)/np.sqrt(p*(1-p)*(1.0/rowsums[0]+1.0/rowsums[1]))

N,m,n=14,2,2
position = [posi for posi in range(N+m*n-1)]
walds = []
chis = []
stars=[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
for x in permutations(balls):
    i = 0
    t = [0,0,0,0]
    for s in stars:
          if(s ==0):
                i+=1
          t[i]+=1 
    table = np.array([[t[0],t[1]],[t[2],t[3]]])
    walds.append(wald(table))
    chis.append(chisquare(table))
print len(waltl)
plt.plot(chis,walds)
Esempio n. 8
0
# our model for the forward pass
def forward(x):
    return x * w


# loss function
def loss(x, y):
    y_pred = forward(x)
    return (y_pred - y) * (y_pred - y)


w_list = []
mse_list = []

for w in np.arrange(0.0, 4.1, 0.1):
    print("w = ", w)
    l_sum = 0
    for x_val, y_val in zip(x_data, y_data):
        y_pred_val = forward(x_val)
        l = loss(x_val, y_val)
        l_sum += l
        print("\t", x_val, y_val, y_pred_val, 1)
    print("MSE = ", l_sum / 3)
    w_list.append(w)
    mae_list.append(l_sum / 3)

plt.plot(w_list, mae_list)
plt.ylabel("Loss")
plt.xlabel("w")
plt.show()
Esempio n. 9
0
import mathplotlib.pyplot as plt
import numpy as np


plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show 


data = {'a' : np.arange(50),
        'c' : np.random.randint(0,50,50),
        'd' : np.random.randn(50),

data['b']=data['a']+ 10*np.random.randn(50)
data['d']=np.abs(data[d])*100

plt.scatter('a','b',c='c',s='d',data=data)
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()