<jupyter_start><jupyter_text>Machines Manufacturing Captal Budgeting Model (Project 1)Insert your description of the model here and add any additional sections below:- [**Setup**](Setup): Runs any imports and other setup- [**Inputs**](Inputs): Defines the inputs for the model  SetupSetup for the later calculations are here. The necessary packages are imported.<jupyter_code>from dataclasses import dataclass
import numpy_financial as npf<jupyter_output><empty_output><jupyter_text>InputsAll of the inputs for the model are defined here. A class is constructed to manage the data, and an instance of the class containing the default inputs is created.<jupyter_code>@dataclass
class ModelInputs:
    n_phones: float = 100000
    price_scrap: float = 50000
    price_phone: float = 2000
    cost_machine_adv: float = 1000000
    cogs_phone: float = 250
    n_life: int = 10
    n_machines: int = 5
    d_1: float = 100000
    g_d: float = 0.2
    max_year: float = 20
    interest: float = 0.05
        
    # Inputs for bonus problem
    elasticity: float = 100
    demand_constant: float = 300000
        
model_data = ModelInputs()
model_data<jupyter_output><empty_output><jupyter_text>Oulinescashflows = revenues - costs1. Revenues    - sales of phones         - number of goods sold * phones price    - sales of depreciated machines2. Costs    - purchases of machines    - costs of manuefacturing the phones    - costs of advertisementNotes:1. no need to replace the machines (no machines purchases after year 5?)2. number of goods sold is the lower one between demand and production3. launching the ads after machines purchases are done (ads costs are induced every year after year 5?)4. demand grows by g_d = 20% if there is advertisementLogic:for every year:1. identify if there are ads costs. if there are, demand increase2. whether there are scraped machines3. how many phones have been sold<jupyter_code># determine the number of operating machines and scraped machines for each year
def op_sp_machines(year):
    '''
    return two lists one contains the number of machines in operation,
    the other contains the scraped machines.
    '''
    
    op = []
    sp = []
    
    if year <= model_data.n_machines:    # purchase one machine per year before year 5
        op = list(range(year))
    elif model_data.n_life >= year > model_data.n_machines:    # always have 5 operating machines between year 5 and 10
        op = list(range(model_data.n_machines))
    elif model_data.n_machines+model_data.n_life >= year > model_data.n_life:   # one depreciated machine per year between year 11 and 15
        sp = list(range(year-model_data.n_life))
        op = list(range(model_data.n_machines-len(sp)))
    else:    # no operating and scraped machines after year 15
        op = []
    
    return op, sp
# determine if there is advertisement
def is_ads(year):
    '''
    return a Bool value indicating whether advertisement exist
    '''
    
    ads = False
    
    if year > model_data.n_machines:    # having ads every year after year 5
        ads = True
    
    return ads
# determine the number of goods sold each year
def n_goods_sold(production, demand):
    '''
    return the lower value between each year's production and demand
    '''
    return production if production<=demand else demand
# calculate the total revenues each year
def total_revenues(n_goods_sold, sp_machines):
    '''
    return the total revenues, which consists of sales from goods and from scraped machines
    '''
    
    sales_from_goods = n_goods_sold * model_data.price_phone
    
    if sp_machines > 0:
        sales_from_machines = model_data.cost_machine_adv
    else:
        sales_from_machines = 0
    
    return sales_from_goods+sales_from_machines
# calculate the total costs per year
def total_costs(n_goods_sold, op_machines, sp_machines, ads_costs):
    '''
    return the total costs per year.
    which consists of ads costs, purchases of machines and phones manufacturing
    '''
    
    if op_machines>0 and sp_machines==0:    # only need to purchase machines when there are less than 5 operating machines and no scraped machines
        machines_costs = model_data.cost_machine_adv
    else:
        machines_costs = 0
    
    phones_costs = n_goods_sold * model_data.cogs_phone
    
    return machines_costs+phones_costs+ads_costs
# calculate each year's cashflow
def cashflow():
    '''
    return a list that contains each year's cashflows throughout the project years
    '''
    cashflows = []
    demand = model_data.d_1
    
    for year in range(1, model_data.max_year+1):
        op_machines = len(op_sp_machines(year)[0])
        sp_machines = len(op_sp_machines(year)[1])
        
        if is_ads(year) == True:
            cost_ads = model_data.cost_machine_adv
            demand *= (1+model_data.g_d)
        else:
            cost_ads = 0
        
        production = op_machines * model_data.n_phones
        goods_sold = n_goods_sold(production, demand)
        revenues = total_revenues(goods_sold, sp_machines)
        
        costs = total_costs(goods_sold, op_machines, sp_machines, cost_ads)
        
        cash_flow = revenues - costs
        cashflows.append(cash_flow)
    
    return cashflows
cash_flows = cashflow() # this should ultimately be set to the list containing your cash flow numbers in each year
npv = npf.npv(model_data.interest, cash_flows) # this should ultimately be set to the overally model npv number 
cash_flows
npv
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(7, 4))
plt.plot(cash_flows)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06601597160603372, 'fraction_numerical': 0.0163265306122449, 'mean_word_length': 3.263237518910741, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '144141', 'license': 'MIT', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1646, 'n_words': 581, 'path': 'financial_modeling/project 1/Project_1.ipynb', 'repo_name': 'linusqzdeng/pyfinance', 'size': '5635'}