I have a scenario where i have to calculate beta = cov/var. However, its the cov of the last 12 negative values. So examples if below is the data set i coulumn, i want my beta to be of the past 12 positive values so starting from bottom, if i am in a-(april) it would take all the 12 number above it and skip the zeros. I need that for positive and negatives. I can figure that out. Any help would be really appreciated.

j -10
f- 11
m- 0
a-10
m- 5
j- 0
j- 5
a-5
s- 0
o- 6
n- 5
d-6
j-5
f-5
m-5
a-3