Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def daily_demand(mean, sd, probability): | |
| random_num = np.random.uniform(0, 1) | |
| if random_num > probability: | |
| return 0 | |
| else: | |
| return np.exp(np.random.normal(mean, sd)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def monte_carlo_ray(M, product, review_period=30): | |
| inventory = product.starting_stock | |
| mean = product.mean | |
| sd = product.sd | |
| lead_time = product.lead_time | |
| probability = product.probability | |
| demand_lead = product.demand_lead | |
| q = 0 | |
| stock_out = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_profit(data, product): | |
| unit_cost = product.unit_cost | |
| selling_price = product.selling_price | |
| holding_cost = product.holding_cost | |
| order_cost = product.ordering_cost | |
| size = product.size | |
| days = 365 | |
| revenue = sum(data['units_sold']) * selling_price | |
| Co = len(data['orders']) * order_cost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cc_monte_carlo_ray(product, q, r): | |
| inventory = product.starting_stock | |
| mean = product.mean | |
| sd = product.sd | |
| lead_time = product.lead_time | |
| probability = product.probability | |
| order_placed = False | |
| order_time = 0 | |
| stock_out = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| # get a list of stocks | |
| ticker_df = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies') | |
| stocks_df = ticker_df[0] | |
| # dataframe output | |
| stocks_df.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas_datareader as pdr | |
| from datetime import datetime | |
| # get a list of ticker names | |
| tickers = [tick for tick in stocks_df['Symbol']] | |
| # initialize start and end times | |
| start = datetime(2019, 12, 1) | |
| end = datetime.today() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from collections import defaultdict | |
| # creating a returns data frame | |
| returns = pd.DataFrame() | |
| # computes the percentage change from the immediately previous row by default | |
| for key in stock_dict.keys(): | |
| returns[key + ' Return'] = stock_dict[key]['Adj Close'].pct_change() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # dictionary to store all the values | |
| discount_dict = {} | |
| def calculate_discount(df): | |
| max_price = df['Adj Close'].describe()['75%'] | |
| min_price = df['Adj Close'].min() | |
| return (max_price - min_price)/max_price | |
| for tick in stock_dict.keys(): | |
| discount_dict[tick] = calculate_discount(stock_dict[tick]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import pandas as pd | |
| # calculating volatility | |
| risk_df = pd.DataFrame(returns.std(), columns = ['returns']) | |
| # output | |
| risk_df.head() |
OlderNewer