Guest User

Untitled

a guest
Jun 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. import math
  2. import tangent
  3. import numpy as np
  4. import pandas as pd
  5. import tensorflow as tf
  6. from edward.models import Normal
  7.  
  8. def proforma(far, weighted_rent, parcel_size, land_cost,
  9. parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
  10. loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
  11. building_efficiency, profit_factor, building_cost_per_sqft, construction_months):
  12. """
  13. Pure-python implementation of proforma logic.
  14. """
  15. # Building bulk
  16. building_sqft = parcel_size * far
  17.  
  18. # Parking
  19. parking_stalls = building_sqft * parking_rate / sqft_per_rate
  20. park_sqft = parking_stalls * sqft_per_stall
  21. park_cost = park_sqft * per_sqft_parking_cost
  22.  
  23. # Total space
  24. total_built_sqft = building_sqft + park_sqft
  25. parking_sqft_ratio = park_sqft / total_built_sqft
  26.  
  27. # Construction costs
  28. build_cost = building_cost_per_sqft * building_sqft
  29. cost = build_cost + park_cost
  30. cost_sqft = (cost / total_built_sqft) * profit_factor
  31. building_cost = building_sqft * cost_sqft # cost to build the new building
  32. total_construction_costs = building_cost + land_cost # add cost to buy current building
  33.  
  34. # Financing costs
  35. loan_amount = total_construction_costs * loan_to_cost_ratio
  36. interest = loan_amount * drawdown_factor * (interest_rate / 12 * construction_months)
  37. points = loan_amount * loan_fees
  38. total_financing_costs = interest + points
  39. total_development_costs = total_construction_costs + total_financing_costs
  40.  
  41. # Revenue
  42. usable_space = building_sqft * (1 - parking_sqft_ratio) * building_efficiency
  43. building_revenue = usable_space * weighted_rent / cap_rate
  44.  
  45. # Profit
  46. profit = building_revenue - total_development_costs
  47.  
  48. return profit
  49.  
  50. with tf.name_scope("bayesian_proforma"):
  51. """
  52. Directed graphical model of proforma.
  53. """
  54. weighted_rent = tf.constant(40.0, name='weighted_rent')
  55. far = tf.constant(4.0, name='far')
  56. parcel_size = tf.constant(30000.0, name='parcel_size')
  57. land_cost = tf.constant(3000000.0, name='land_cost')
  58.  
  59. loan_to_cost_ratio = Normal(loc=tf.constant(0.7), scale=tf.constant(.3), name='loan_to_cost_ratio')
  60. drawdown_factor = Normal(loc=tf.constant(0.6), scale=tf.constant(.2), name='drawdown_factor')
  61. interest_rate = Normal(loc=tf.constant(0.05), scale=tf.constant(.02), name='interest_rate')
  62. loan_fees = Normal(loc=tf.constant(0.02), scale=tf.constant(0.005), name='loan_fees')
  63. building_efficiency = Normal(loc=tf.constant(0.7), scale=tf.constant(.3), name='building_efficiency')
  64. cap_rate = Normal(loc=tf.constant(0.05), scale=tf.constant(.02), name='cap_rate')
  65. profit_factor = Normal(loc=tf.constant(1.1), scale=tf.constant(.5), name='profit_factor')
  66.  
  67. parking_rate = Normal(loc=tf.constant(1.0), scale=tf.constant(.4), name='parking_rate')
  68. sqft_per_rate = Normal(loc=tf.constant(1000.0), scale=tf.constant(200.0), name='sqft_per_rate')
  69. sqft_per_stall = Normal(loc=tf.constant(250.0), scale=tf.constant(70.0), name='sqft_per_stall')
  70. per_sqft_parking_cost = Normal(loc=tf.constant(110.0), scale=tf.constant(40.0), name='per_sqft_parking_cost')
  71.  
  72. building_cost_per_sqft = Normal(loc=tf.constant(210.0), scale=tf.constant(70.0), name='building_cost_per_sqft')
  73. construction_months = Normal(loc=tf.constant(18.0), scale=tf.constant(6.0), name='construction_months')
  74.  
  75. profoma_calcs = proforma(far, weighted_rent, parcel_size, land_cost,
  76. parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
  77. loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
  78. building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
  79.  
  80. profit = Normal(loc=profoma_calcs, scale=0.1, name='profit')
  81.  
  82.  
  83. if __name__ == "__main__":
  84.  
  85. far = 4.0
  86. loan_to_cost_ratio = .7
  87. drawdown_factor = 0.6
  88. interest_rate = 0.05
  89. loan_fees = 0.02
  90. building_efficiency = 0.7
  91. cap_rate = 0.05
  92. profit_factor = 1.1
  93.  
  94. # Parking-type specific
  95. parking_rate = 1.0
  96. sqft_per_rate = 1000.0
  97. sqft_per_stall = 250.0
  98. per_sqft_parking_cost = 110
  99.  
  100. # Parcel-specific info
  101. weighted_rent = 40.0
  102. parcel_size = 30000.0
  103. land_cost = 3000000.0
  104.  
  105. # Lookups
  106. building_cost_per_sqft = 210 ## This is a lookup (cost_per_sqft_for_this_height)
  107. construction_months = 18 ## A lookup of self.construction_months based on total_sqft
  108.  
  109. ## Calculate profitability of a known example and confirm that result matches expectations
  110. result = proforma(far, weighted_rent, parcel_size, land_cost,
  111. parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
  112. loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
  113. building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
  114. print(result)
  115. assert result == 24402359.999999996
  116.  
  117. dproforma = tangent.grad(proforma, wrt=range(17))
  118.  
  119. ## Calculate the gradient of the proforma via auto-differentiation
  120. gradient = dproforma(far, weighted_rent, parcel_size, land_cost,
  121. parking_rate, sqft_per_rate, sqft_per_stall, per_sqft_parking_cost,
  122. loan_to_cost_ratio, drawdown_factor, interest_rate, loan_fees, cap_rate,
  123. building_efficiency, profit_factor, building_cost_per_sqft, construction_months)
  124.  
  125. gradient = pd.Series(gradient)
  126.  
  127. print(gradient)
Add Comment
Please, Sign In to add comment