lib/finance/asset_returns.rb
def portfolio_return(assets)
			#calculate the initial value of the asset
			portfolio_value_start = (assets.map {|a| a[:purchase_price] * a[:qty]}.reduce(:+)).to_d
			returns = []
			assets.each do |a|
				a[:portfolio_share] =  a[:purchase_price].to_d * a[:qty] / portfolio_value_start
				a_return = simple_return(a[:purchase_price], a[:sale_price]) * a[:portfolio_share]
				returns << a_return
			end
			portfolio_return = returns.reduce(:+)
			value = portfolio_value_start * (1 + portfolio_return)
			{:return => portfolio_return, :value => value}
		end
##
# Determine return on protfolio
# assets - array of hashes containing:
# purchase and sale price of a given asset
# quantity of givent asset purchased
# returns a hash in format {:return => "the percentage of return", :value => "the value of the portfolio"}
Determine return on protfolio
assets - array of hashes containing:
purchase and sale price of a given asset
quantity of givent asset purchased
returns a hash in format {:return => "the percentage of return", :value => "the value of the portfolio"}
Determine return on protfolio assets - array of hashes containing : purchase and sale price of a given asset quantity of givent asset purchased returns a hash in format { : return = > " the percentage of return " : value = > " the value of the portfolio " }
def portfolio_return(assets)
			portfolio_value_start = (assets.map {|a| a[:purchase_price] * a[:qty]}.reduce(:+)).to_d
			returns = []
			assets.each do |a|
				a[:portfolio_share] =  a[:purchase_price].to_d * a[:qty] / portfolio_value_start
				a_return = simple_return(a[:purchase_price], a[:sale_price]) * a[:portfolio_share]
				returns << a_return
			end
			portfolio_return = returns.reduce(:+)
			value = portfolio_value_start * (1 + portfolio_return)
			{:return => portfolio_return, :value => value}
		end
def portfolio_return ( assets ) portfolio_value_start = ( assets . map { | a | a [ :purchase_price ] * a [ :qty ] } . reduce ( :+ ) ) . to_d returns = [ ] assets . each do | a | a [ :portfolio_share ] = a [ :purchase_price ] . to_d * a [ :qty ] / portfolio_value_start a_return = simple_return ( a [ :purchase_price ] , a [ :sale_price ] ) * a [ :portfolio_share ] returns << a_return end portfolio_return = returns . reduce ( :+ ) value = portfolio_value_start * ( 1 + portfolio_return ) { :return => portfolio_return , :value => value } end
Determine return on protfolio
assets - array of hashes containing:
purchase and sale price of a given asset
quantity of givent asset purchased
returns a hash in format {:return => "the percentage of return", :value => "the value of the portfolio"}
Determine return on protfolio assets - array of hashes containing : purchase and sale price of a given asset quantity of givent asset purchased returns a hash in format { : return = > " the percentage of return " : value = > " the value of the portfolio " }
#calculate the initial value of the asset
assets