import math
import pandas as pd
import numpy as np

class MonteCarloSimulation:
    # volatility: 0.25 to 0.6
    def generateStockPrice(self, stockPrice=100., volatility=0.3, days=30., riskfreeRate=0.02):
        np.random.seed()
        
        I = 1

        S0 = stockPrice
        sigma = volatility
        M = days
        r = riskfreeRate
        dt = 1. / 365.
        
        S = np.zeros((M + 1, I))
        S[0] = S0
        for t in range(1, M + 1):
            z = np.random.standard_normal(I)
            S[t] = S[t - 1] * np.exp((r - 0.5 * sigma ** 2) * dt
                                     + sigma * math.sqrt(dt) * z)
        
        return pd.DataFrame(S)
    
