How to calculate average

Use this forum to post Vensim related questions.
Post Reply
nahsan
Junior Member
Posts: 7
Joined: Mon Mar 27, 2023 2:47 pm
Vensim version: PLE+

How to calculate average

Post by nahsan »

Hey all,
I would be rather asking something really basic, as I am new to Vensim. I could not figure out that how can I take the average of only certain time period (lets say first ten years) of from the data in stock?
tomfid
Administrator
Posts: 3992
Joined: Wed May 24, 2006 4:54 am

Re: How to calculate average

Post by tomfid »

If an exponentially-weighted moving average is OK, you can use the SMOOTH function to compute an average. For example,

avg value = SMOOTH( value, horizon ) ~ stuff
horizon = 10 ~ years

If you want to freeze the average at some point, you can replace the SMOOTH with the underlying stock/flow equivalent:

avg value = INTEG( avg adjusting, initial value ) ~ stuff
avg adjusting = avg active * (value-avg value) / horizon ~ stuff/time
horizon = 10 ~ years
avg active = 1-STEP(1,freeze time) ~ dmnl ~ switch that controls whether updating is active
freeze time = 20 ~ year

If you need a simple average, it's a little more complicated, but you can do something like the following:

inflow = value ~ stuff
cum value = INTEG( inflow-outflow, 0 ) ~ stuff*time
outflow = DELAY FIXED(inflow, horizon, 0) ~ stuff
avg value = cum value/horizon ~ stuff
Post Reply