text_plain_output_1.png
from pandas_datareader import data

import math

import matplotlib.pyplot as plt

import numpy as np

ibm = data.DataReader('IBM', 'yahoo', start='1/1/2000')

time_elapsed = (ibm.index[-1] - ibm.index[0]).days

price_ratio = ibm['Adj Close'][-1] / ibm['Adj Close'][1]
inverse_number_of_years = 365.0 / time_elapsed
cagr = price_ratio ** inverse_number_of_years - 1

vol = ibm['Adj Close'].pct_change().std()

number_of_trading_days = 252
vol = vol * math.sqrt(number_of_trading_days)

daily_return_percentages = np.random.normal(cagr / number_of_trading_days, vol / math.sqrt(number_of_trading_days), number_of_trading_days) + 1

price_series = [ibm['Adj Close'][-1]]
for drp in daily_return_percentages:
    price_series.append(price_series[-1] * drp)

number_of_trials = 1000
for i in range(number_of_trials):
    daily_return_percentages = np.random.normal(cagr / number_of_trading_days, vol / math.sqrt(number_of_trading_days), number_of_trading_days) + 1
    price_series = [ibm['Adj Close'][-1]]
    for drp in daily_return_percentages:
        price_series.append(price_series[-1] * drp)

ending_price_points = []
larger_number_of_trials = 9001
for i in range(larger_number_of_trials):
    daily_return_percentages = np.random.normal(cagr / number_of_trading_days, vol / math.sqrt(number_of_trading_days), number_of_trading_days) + 1
    price_series = [ibm['Adj Close'][-1]]
    for drp in daily_return_percentages:
        price_series.append(price_series[-1] * drp)
    ending_price_points.append(price_series[-1])

expected_ending_price_point = round(np.mean(ending_price_points), 2)

top_ten = np.percentile(ending_price_points, 100 - 10)
bottom_ten = np.percentile(ending_price_points, 10)
print('Top 10% : ', str(round(top_ten, 2)))
print('Bottom 10% : ', str(round(bottom_ten, 2)))