Anylogic: adjust number of visitors over time (with trend?) - simulation

I am trying to create a trend in which visitors to an event slowly decline every year.
This is the setup: https://imgur.com/6mx3xy2
I want to ensure that for instance in year 1 there are 100,000 visitors but the next year this declines with 1%, so that next year only 99,000 visitors are present and the year after that 99.000*0.99 so in the total of those years 297.010 people have visited. (So, the Stock value of visitors being 297.010 after a simulation of 3 years)
What values/formulas should I give my NewInfoRealVisitors variable and flow equation for example? Or all the other variables for that matter

Ok, a lot of things to do here, first your structure is wrong and should be like this:
visitorsPerYear = annualVisitors it's the same variable, but defined as a flow and as a stock at the same time
annualVisitorsDecline = annualVisitors*declineRate
Now, to obtain the exact values you want (total visitors = 297010)
you need to use years as the model time units and you need to use 1 as the fixed time step:
And finally, you need to run the model in virtual time (as fast as possible) because otherwise anylogic changes your fixed time step without your control
If you don't do all this, you will just get an approximation of 297.010 based on Euler equations... close enough, but not exactly it.

Related

Timeplot to show the sum of model units

I am working on a system dynamics model, whose units are days, in AnyLogic. The model tracks daily demand of water for 10,950 days (30 years). One of the model’s outputs is a timeplot that keeps track of this demand, but I don’t want it to plot the daily demand. Instead, I want the timeplot to show demand in years (i.e. the sum of 365 days across the 30 years). I am having a bit of trouble finding a way to do this and would appreciate any help. Thank you!
I assume your problem is twofold.
How to get the time plot to display 30 years of data
How to sum the annual demand for 30 years
Here is a simple example that I believe answers your question.
In this simple model, there is a daily event that simulates the daily demand, and adds it to a variable called annualDemand
There is another event that runs yearly and tasks the annualDemand and saves it to a data set, and rests the annual demand accumulator to 0.
In your time plot, you simply display the dataset which will at the end of the model only contain 30 entries, one for each year.
By following the same principles
Save annual demand
yearly event to add annual demand to data set and reset the annual demand
time plot to plot the dataset
You should be able to get what you need.

Anylogic: System dynamics and randomness (triangular or normal) in flows gives wrong results

I am trying to create a dynamic environment in anylogic with portfolio performance over the time.
The return each year should be dynamic (random) using triangular or normal
Example triangular (-0.5,0.1,0.5) or normal(0.05,0.08)
That means sometimes it is positive and sometimes it's negative
Dynamic variable/parameter is 'Return1'
Flow is 'earn'
Stock is 'portfolio'
I use a variable Return1 = normal(0.05,0.08)
A Flow earn = portfolio*Return1
The stock is called Portfolio and initial value of 100. It accumulates the profit/loss each year
Unfortunately the results in the accumulated portfolio are not correct.
If I use Return1=0.1 or for example -0.05 (fixed prices) it works perfectly.
It seems there are issues in anylogic system dynamics with randomness.
I would appreciate if you can help how I could simulate the portfolio performance in this way
To do what you want, you need to recalculate the random variable in your variable every year. Maybe create an event that runs once per year that changes the value of the variable.
In the event you would have every year:
Return1 = normal(0.05,0.08)
The variable Return1 is not magically updated automatically based on your own desires and wishes, unless you tell Anylogic explicitely.
If return1 is a dynamic variable, then the value will be recalculated every time step, which will lead to unexpected results that will be maybe equivalent to using the average of your random value.
If your time step is 1 year... well in AnyLogic you can't really trust that time step unfortunately.

AnyLogic "triggered by rate" implementation

Anybody has a reference for how AnyLogic implements it's rate per day? Specifically, my agent is at different locations (based on time of day) throughout the day. If there are 10 triggers a day, do they happen randomly for each agent throughout the day, or only at the beginning of a day (when agent is at home), etc.?
Thank you, Amy! Your explanation was very helpful.
The rate follows the Poisson distribution. If you divide 1/rate, you will get an inter-arrival time that follows the exponential.
As this is random, you may not actually get 10 a day - you may get 9 one day and 11 the next. If you want to get exactly 10 in a day, you need to think about writing your own code to make that happen. That might be something like generating 10 dynamic events randomly sampled times that all trigger a transition in their action code (that would not be exponential between events).

prediction and time series

how to decide how in advance my prediction is?
i am following the featuretools churn tutorial https://github.com/Featuretools/predict-customer-churn
what i don't quite understand how did it decide that the prediction is for one month in advance.. in previous churn examples i tried, i just get aggregated data ( it could be historical for a years or months) then i build churn model and predict but i don't know if my prediction is for a month a year or even how many days in advance how is that decided!.
does it depend on the period of aggregation or the data i didn't use. i know cut off time is the time i want to make prediction but how do i tell the system i want to make prediction for 2 month in advance do i just disregard the data for the last two months by setting the cut_off time but provide the label after the two months and say my model based on the features i get is for a 2 month advanced prediction.
for ex. cut_off date is 1/8/2010 label is the customer state on 1/10/2010
so two months period is the advance prediction? and i used all historical data previous to cut_off time?
this might be a time series problem that is turned into a simple classification but i am not sure!
You pick the amount of time in advanced (called "lead time") using your domain expertise. Depending on the real world application the lead time might be more or less. Sometimes you might even build multiple models with different lead times to apply in different situations.
You control the lead time by moving the cutoff earlier with respect to the time the label became known. So, the example you give looks correct.

Calculate interest on postgresql with trigger/function

I'm currently working on a simple banking application.
I have built a postgresql database, with the right tables and functions.
My problem is, that I am not sure how to calculate the interest rate on the accounts. I have a function that will tell me the balance, on a time.
If we say that we have a 1 month period, where I want to calculate the interest on the account. The balance looks like this:
February Balance
1. $1000
3. $300
10. $700
27. $500
Balance on end of month: $500
My initial thoughts are to make a for loop, looping from the 1st in the month, to the last day in month, and adding the interest earned for that particular day in a row.
The function I want to use at end of month should be something like addInterest(startDate,endDate,accountNumber), which should insert one row into the table, adding the earned rate.
Could someone bring me on the right track, or show me some good learning resources on PL/PGSQL?
Edit
I have been reading a bit on cursors. Should I use a cursor to walk through the table?
I find it a bit confusing to use cursors, anyone here with some well explained examples?
There are various ways of interest calculation in banking system.
Interest = Balance x Rate x Days / Year
Types of Balances
Periodical Aggregate Balance
Daily Aggregate Balance
Types of Rates
Fixed Rate Dynamic Rate (according to balance)
Dynamic Rate (according to term)
Dynamic Rate (according to schedule)
Types of Days/Schedules
End of Day Processing (One day)
End of Month Processing (One month)
End of Quarter Processing (Three months)
End of Half Processing (Six months)
End of Year Processing (One year)
Year Formula
A year could consist of 365 or 366 days.
Your user might want to override number of days in a year, maintain a separate year variable property in your application.
Conclusion
Interest should be calculated as a routine task. Best approach would be that would run on a schedule depending upon the frequency setup of individual accounts.
The manual has a section about loops and looping through query results. There are also examples of trigger functions written in pl/pgsql. The manual is very complete, it's the best source I know of.