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
| # 17 roles per meeting | |
| for d in days: | |
| model += pulp.lpSum(x[m][d][r] for m in members for r in roles) == 17 | |
| # every member has at least done a role once | |
| for m in members: | |
| for r in roles: | |
| model += pulp.lpSum(x[m][d][r] for d in days) >= 1 | |
| # only one role per member per meeting |
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
| # objective function | |
| model = pulp.LpProblem("Toastmasters", pulp.LpMaximize) | |
| model += pulp.lpSum(x[si][dj][ri] for si in members for dj in days for ri in roles) |
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 pulp | |
| from pulp import * | |
| members = range(1,27) | |
| days = range(1,28) | |
| roles = range(1,18) | |
| # defining the variables | |
| x = pulp.LpVariable.dicts("x",(members,days,roles),0,1,pulp.LpInteger) |
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() |
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 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
| 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 | |
| # 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
| 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
| 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 |
NewerOlder