import numpy as np
import vizarray as vz
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')

"""
Explanation: Numpy Exercises
End of explanation
"""


def checkerboard(size):
    """Return a 2d checkboard of 0s and 1s as a NumPy array."""


"""
Explanation: Checkerboard
Write a Python function that creates a square (size,size) 2d Numpy array with the values 0.0 and 1.0 in a checkerboard pattern.
End of explanation
"""


def brownian(maxt, n):
    """Return one realization of a Brownian (Wiener) process with n steps and a max time of t."""
    t = np.linspace(0.0,maxt,n)
    h = t[1]-t[0]
    Z = np.random.normal(0.0,1.0,n-1)
    dW = np.sqrt(h)*Z
    W = np.zeros(n)
    W[1:] = dW.cumsum()
    return t, W

t, W = brownian(1.0, 1000)

"""
Explanation: Use vizarray to visualize the checkerboard. 
Using tab completion and ? figure out how to list and change the colormap used by vizarray.
Stochastic Process
Here is a function that produces standard Brownian motion using NumPy.
End of explanation
"""


def geo_brownian(t, W, X0, mu, sigma):
    "Return X(t) for geometric brownian motion with drift mu, volatility sigma."""

"""
Explanation: Visualize the process using plt.plot with t on the x-axis and W(t) on the y-axis:
Use np.diff to compute the changes at each step of the motion and then use plt.hist to visualize the distributions of those changes with 30 bins.
Write a function that takes $W(t)$ and converts it to geometric Brownian motion using the equation:
$$
X(t) = X_0 e^{((\mu - \sigma^2/2)t + \sigma W(t))}
$$
Use Numpy ufuncs in your function.
End of explanation
"""


def my_fact(n):
    """Compute n! = n*(n-1)*...*1 using Numpy."""

"""
Explanation: Use your function to simulate geometric brownian motion for $\mu=0.5$ and $\sigma=0.3$ and visualize it using plt.plot.
Factorial
Write a Python function that computes the factorial of small numbers using np.arange and np.cumprod.
End of explanation
"""


%%writefile temps.txt
## Enter your data below, one value per line

"""
Explanation: Gathering data
Go to http://www.wunderground.com/ and find today's hourly temperature predictions for some location on the planet. Enter that data into a text files named temps.txt using IPython's %%writefile magic command.
End of explanation
"""


