Page 1 of 1

How to calculate average

Posted: Mon Mar 27, 2023 7:04 pm
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?

Re: How to calculate average

Posted: Mon Mar 27, 2023 7:39 pm
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