Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import tangent
- import numpy as np
- import pandas as pd
- import tensorflow as tf
- from edward.models import Normal
- def proforma(far, weighted_rent, parcel_size, land_cost,
- parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
- loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
- building_efficiency, profit_factor, building_cost_per_sqft, construction_months):
- """
- Pure-python implementation of proforma logic.
- """
- # Building bulk
- building_sqft = parcel_size * far
- # Parking
- parking_stalls = building_sqft * parking_rate / sqft_per_rate
- park_sqft = parking_stalls * sqft_per_stall
- park_cost = park_sqft * per_sqft_parking_cost
- # Total space
- total_built_sqft = building_sqft + park_sqft
- parking_sqft_ratio = park_sqft / total_built_sqft
- # Construction costs
- build_cost = building_cost_per_sqft * building_sqft
- cost = build_cost + park_cost
- cost_sqft = (cost / total_built_sqft) * profit_factor
- building_cost = building_sqft * cost_sqft # cost to build the new building
- total_construction_costs = building_cost + land_cost # add cost to buy current building
- # Financing costs
- loan_amount = total_construction_costs * loan_to_cost_ratio
- interest = loan_amount * drawdown_factor * (interest_rate / 12 * construction_months)
- points = loan_amount * loan_fees
- total_financing_costs = interest + points
- total_development_costs = total_construction_costs + total_financing_costs
- # Revenue
- usable_space = building_sqft * (1 - parking_sqft_ratio) * building_efficiency
- building_revenue = usable_space * weighted_rent / cap_rate
- # Profit
- profit = building_revenue - total_development_costs
- return profit
- with tf.name_scope("bayesian_proforma"):
- """
- Directed graphical model of proforma.
- """
- weighted_rent = tf.constant(40.0, name='weighted_rent')
- far = tf.constant(4.0, name='far')
- parcel_size = tf.constant(30000.0, name='parcel_size')
- land_cost = tf.constant(3000000.0, name='land_cost')
- loan_to_cost_ratio = Normal(loc=tf.constant(0.7), scale=tf.constant(.3), name='loan_to_cost_ratio')
- drawdown_factor = Normal(loc=tf.constant(0.6), scale=tf.constant(.2), name='drawdown_factor')
- interest_rate = Normal(loc=tf.constant(0.05), scale=tf.constant(.02), name='interest_rate')
- loan_fees = Normal(loc=tf.constant(0.02), scale=tf.constant(0.005), name='loan_fees')
- building_efficiency = Normal(loc=tf.constant(0.7), scale=tf.constant(.3), name='building_efficiency')
- cap_rate = Normal(loc=tf.constant(0.05), scale=tf.constant(.02), name='cap_rate')
- profit_factor = Normal(loc=tf.constant(1.1), scale=tf.constant(.5), name='profit_factor')
- parking_rate = Normal(loc=tf.constant(1.0), scale=tf.constant(.4), name='parking_rate')
- sqft_per_rate = Normal(loc=tf.constant(1000.0), scale=tf.constant(200.0), name='sqft_per_rate')
- sqft_per_stall = Normal(loc=tf.constant(250.0), scale=tf.constant(70.0), name='sqft_per_stall')
- per_sqft_parking_cost = Normal(loc=tf.constant(110.0), scale=tf.constant(40.0), name='per_sqft_parking_cost')
- building_cost_per_sqft = Normal(loc=tf.constant(210.0), scale=tf.constant(70.0), name='building_cost_per_sqft')
- construction_months = Normal(loc=tf.constant(18.0), scale=tf.constant(6.0), name='construction_months')
- profoma_calcs = proforma(far, weighted_rent, parcel_size, land_cost,
- parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
- loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
- building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
- profit = Normal(loc=profoma_calcs, scale=0.1, name='profit')
- if __name__ == "__main__":
- far = 4.0
- loan_to_cost_ratio = .7
- drawdown_factor = 0.6
- interest_rate = 0.05
- loan_fees = 0.02
- building_efficiency = 0.7
- cap_rate = 0.05
- profit_factor = 1.1
- # Parking-type specific
- parking_rate = 1.0
- sqft_per_rate = 1000.0
- sqft_per_stall = 250.0
- per_sqft_parking_cost = 110
- # Parcel-specific info
- weighted_rent = 40.0
- parcel_size = 30000.0
- land_cost = 3000000.0
- # Lookups
- building_cost_per_sqft = 210 ## This is a lookup (cost_per_sqft_for_this_height)
- construction_months = 18 ## A lookup of self.construction_months based on total_sqft
- ## Calculate profitability of a known example and confirm that result matches expectations
- result = proforma(far, weighted_rent, parcel_size, land_cost,
- parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
- loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
- building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
- print(result)
- assert result == 24402359.999999996
- dproforma = tangent.grad(proforma, wrt=range(17))
- ## Calculate the gradient of the proforma via auto-differentiation
- gradient = dproforma(far, weighted_rent, parcel_size, land_cost,
- parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
- loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
- building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
- gradient = pd.Series(gradient)
- print(gradient)
Add Comment
Please, Sign In to add comment