-
-
Save hughkelsey/1597950 to your computer and use it in GitHub Desktop.
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 Deal < AR | |
attr_reader :minimum_order, :board_lot_size, :unit_value, :allocation_value | |
end | |
# last level allocation rate | |
# planned allocations | |
# deal | |
class DealAllocation < AR | |
belongs_to :deal | |
has_many :expressions_of_interest, :through => :deal | |
has_many :allocation_plan_items | |
attr_accessor :remaining_units | |
def by_rank(rank) | |
expressions_of_interest.select {|e| e.rank == rank} | |
end | |
def rank_total(rank) | |
by_rank(rank).sum(&:units_calculated) | |
end | |
def partial_rank | |
expressions_of_interest.select {|eoi| [:partial, :no].include? eoi.within_deal_allocation? }.first.eoi_member_rank | |
end | |
end | |
class Allocation::ExpressionOfInterest | |
attr_reader :expression_of_interest, :deal_allocation | |
def initialize(expression_of_interest, deal_allocation) | |
# allocation_plan_item = Allocation::AllocationPlanItem.plan_for_rank(self.rank) | |
@deal_allocation = deal_allocation | |
@expression_of_interest = expression_of_interest | |
end | |
def self.from_deal_allocation(deal_allocation) | |
deal_allocation.expressions_of_interest.map {|eoi| new(eoi, deal_allocation)}.sort_by {} | |
end | |
def in_partial_rank? | |
deal_allocation.partial_rank == self.eoi_member_rank | |
end | |
# expression_of_interest | |
def date_of_interest | |
expression_of_interest.created_at | |
end | |
# expression_of_interest | |
def eoi_member_rank | |
expression_of_interest.member | |
end | |
# expression_of_interest | |
def eoi_amount_requested | |
expression_of_interest.eoi_amount_requested | |
end | |
# expression_of_interest | |
def eoi_units_requested | |
expression_of_interest.eoi_units_requested | |
end | |
# deal_allocation | |
def amount_calculated | |
units_calculated * deal.unit_price | |
end | |
# allocation_plan, #deal <-- could use expression of interest insead of deal | |
def units_calculated | |
if in_partial_rank? | |
units_calculated_by_percent | |
else | |
units_calculated_by_strategy | |
end | |
end | |
def units_calculated_by_percent(allocation_percentage = 1.0, remaining_percentage = 0.37) | |
requested_units * remaining_percentage * allocation_percentage | |
# result = alloction_plan.percentage_strategy(requested_units, allocation_percentage) | |
return 0 if result == 0 | |
[result.rounded_down(board_lot_size), minimum].max | |
end | |
def units_calculated_by_strategy | |
result = allocation_plan.calculate(requested_units) | |
return 0 if result == 0 | |
[result.rounded_down(board_lot_size), minimum].max | |
end | |
# deal_allocation | |
def percentage_of_deal_unit_allocation | |
(units_calculated / deal.total_unit_allocation).as_percent | |
end | |
# deal_allocation | |
def cumulative_percentage_of_deal_unit_allocation | |
if deal_allocation.previous_expression_of_interest(self) | |
deal_allocation.previous_expression_of_interest(self).cumulative_percentage_of_deal_unit_allocation + percentage_of_deal_unit_allocation | |
else | |
percentage_of_deal_unit_allocation | |
end | |
end | |
def within_deal_allocation? | |
if cumulative_percentage_of_deal_unit_allocation < 100 | |
:yes | |
elsif cumulative_percentage_of_deal_unit_allocation - percentage_of_deal_unit_allocation < 100 | |
:partial | |
else | |
:no | |
end | |
end | |
end | |
class Allocation::AllocationPlanItem < AR | |
attr_reader :rank | |
attr_reader :rank_plan, :rank_demand | |
def self.plan_for_rank(rank) | |
# looks up the plan for a rank | |
end | |
end | |
class Allocation::InvestorRankPlan | |
attr_accessor :units | |
attr_reader :percentage | |
def calculate(units) | |
# result will be rounded to the board lot size | |
(units * percentage).rounded(board_lot_size) | |
end | |
end | |
class Allocation::InvestorRankEOIDemand | |
attr_reader :value | |
def units | |
value * something | |
end | |
end | |
put, :update, :id => deal_allocation_id, :deal_allocation => {:remainder_allocation_percentage => 25, :allocation_plan_item_attributes => [{:id => 1, :units_allocated => 10000}]} | |
def update | |
@deal_allocation = find(params[:id]) | |
@deal_allocation.update_attributes(params[:deal_allocation]) | |
end | |
def show | |
@deal_allocation = find(params[:id]) | |
Allocation::ExpressionOfInterest.from_deal_allocation(@deal_allocation) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment