def weighted_moving_average(data, period):
catch_errors.check_for_period_error(data, period)<EOL>k = (period * (period + <NUM_LIT:1>)) / <NUM_LIT><EOL>wmas = []<EOL>for idx in range(<NUM_LIT:0>, len(data)-period+<NUM_LIT:1>):<EOL><INDENT>product = [data[idx + period_idx] * (period_idx + <NUM_LIT:1>) for period_idx in range(<NUM_LIT:0>, period)]<EOL>wma = sum(product) / k<EOL>wmas.append(wma)<EOL><DEDENT>wmas = fill_for_noncomputable_vals(data, wmas)<EOL>return wmas<EOL>
Weighted Moving Average.

Formula:
(P1 + 2 P2 + 3 P3 + ... + n Pn) / K
where K = (1+2+...+n) = n(n+1)/2 and Pn is the most recent price