FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Economics and finance

Description
Problem name and type, featuresDifficultyRelated examples
H‑1 Choice of loans *
calculation of net present value
H‑2 Publicity campaign *
forall-do
H‑3 Portfolio selection ** h7qportf.mos
sets of integers, second formulation with semi-continuous, parameters
H‑4 Financing an early retirement scheme **
inline if, selection with `|'
H‑5 Family budget **
formulation of monthly balance constraints including different payment frequencies; as, mod, inline if, selection with `|'
H‑6 Choice of expansion projects ** capbgt_graph.mos
experiment with solutions: solve LP problem explicitly, ``round'' some almost integer variable and re-solve
H‑7 Mean variance portfolio selection: Quadratic Programming problem *** folioqp_graph.mos
parameters, forall-do, min, max, loop over problem solving


Further explanation of this example: 'Applications of optimization with Xpress-MP', Chapter 13: Economics and finance problems

mosel_app_8.zip[download all files]

Source Files

Data Files





h5budget.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file h5budget.mos
   `````````````````
   Planning the family budget

   A mother wants to plan her family's annual budget.  A
   list of monthly expenses is provided as well as the
   family salary and allowances. Each month, the mother
   pays at least a given amount for leisure, but she would
   like to spend more in such activities. How should she
   balance the budget through the year to maximize the money
   available for leisure?

   This is a LP model similar to a production planning
   model where money can be transferred from one time
   period to the next one. To deal with the different
   periodicities of the expenses, the Mosel operator 'mod'
   is introduced. For the savings at the beginning of the
   first period, the conditional 'if' is used in the constraint
   formulation.

   (c) 2008-2022 Fair Isaac Corporation
       author: S. Heipcke, Mar. 2002, rev. Mar. 2022
*******************************************************!)

model "H-5 Family budget"
 uses "mmxprs"

 declarations
  MONTHS = 1..12                      ! Time period
  ITEMS: set of string                ! Set of shops
  
  INCOME, ALLOW: integer              ! Monthly income and allowance
  HMIN: integer                       ! Min. amount required for hobbies
  EXPENSE: array(ITEMS) of integer    ! Expenses
  FREQ: array(ITEMS) of integer       ! Frequency (periodicity) of expenses

  hobby: array(MONTHS) of mpvar       ! Money to spend for leisure/hobbies
  saving: array(MONTHS) of mpvar      ! Savings
 end-declarations

 initializations from 'h5budget.dat'
  INCOME ALLOW HMIN
  [EXPENSE, FREQ] as 'PAYMENT'
 end-initializations

! Objective: money for hobby
 Leisure:= sum(m in MONTHS) hobby(m)
 
! Monthly balances
 forall(m in MONTHS)
  sum(i in ITEMS | m mod FREQ(i) = 0) EXPENSE(i) + hobby(m) +
                  saving(m) <= INCOME + ALLOW + if(m>1, saving(m-1), 0) 

 forall(m in MONTHS) hobby(m) >= HMIN

! Solve the problem
 maximize(Leisure)
 
! Solution printing
 writeln("Money for hobby: ", getobjval)
 write("Month   ")
 forall(m in MONTHS) write(" ", strfmt(m,4))
 setparam("realfmt", "%4g")     ! Reserve 4 char.s for display of real numbers
 write("\nHobby:  ")
 forall(m in MONTHS) write(" ", getsol(hobby(m)))
 write("\nSavings:")
 forall(m in MONTHS) write(" ", getsol(saving(m)))
 writeln
 
end-model

Back to examples browserPrevious exampleNext example