This file contains 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 project(self, start_month, contract_frequency, payment_frequency, number_of_contracts, value, term, name, increase_period=1, increase_percentage=0): | |
for m in range(start_month, self.number_of_months - start_month, contract_frequency): | |
c = contract(m, payment_frequency, value, term, name + str(m), increase_period, increase_percentage) | |
self.add_contract(c) |
This file contains 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 result(self): | |
# Ensure all calculations are done and return the dataframe | |
# First, sum all licence columns to get the total earned in that month from all live contracts | |
self.df['forecast_licences'] = self.df[[c.contract_name for c in self.contracts]].sum(axis=1) | |
# Secondly, calculate a cumulative total licence sales | |
self.df['total_sales'] = self.df.forecast_licences.cumsum() | |
return self.df |
This file contains 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 add_contract(self, contract): | |
# Adds a new contract to the forecast | |
self.df[contract.contract_name] = np.zeros(self.number_of_months) | |
self.contracts.append(contract) | |
for m in range(contract.start_month, contract.start_month + contract.term, contract.payment_frequency): | |
try: | |
increase = (contract.increase_percentage * int(m / contract.increase_period) / 100) * contract.value | |
self.df.loc[self.months[m]][contract.contract_name] = contract.value + increase |
This file contains 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
class forecast: | |
def __init__(self, start_date, number_of_months): | |
self.start_date = start_date | |
self.number_of_months = number_of_months | |
self.months = pd.date_range('2020-01', periods=60, freq='M') | |
self.contracts = [] | |
self.df = pd.DataFrame(index=self.months) |
This file contains 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
class contract: | |
def __init__(self, start_month, payment_frequency, value, term, contract_name, increase_period=1, increase_percentage=0): | |
self.start_month = start_month # The month (zero based int) at which the contract starts | |
self.payment_frequency = payment_frequency # The frequency of payments (e.g. 1 for monthly, 3 for quarterly, 12 for annually) | |
self.value = value # The money recieved from the contract | |
self.term = term # The duration of the contract in months | |
self.contract_name = contract_name # An identifier for the contract | |
self.increase_period = increase_period # Optional frequency of price increases (e.g. 12 for an annual inflation) | |
self.increase_percentage = increase_percentage # Optional percentage increase (e.g. 2.5 for a 2.5% price increase) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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 os | |
import sys | |
import argparse | |
import fnmatch | |
import logging | |
import papermill as pm | |
from datetime import datetime | |
import time | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder