IDEAS home Printed from
   My bibliography  Save this paper a GAMS-like Modeling System based on Python and SAGE


  • Roberto Roson


This paper presents an external module for the Python programming language and for the SAGE open source mathematical software, which allows the realization of models based on constrained optimization or non-linear systems. The module, which is freely available for download, allows describing the structure of a model using a syntax similar to that of popular modeling systems like GAMS, AIMMS or GEMPACK; in particular by allowing the automatic replication of equations, variable and parameter definitions on the basis of some specified sets. Many applied models, especially in economics, are based on non-linear constrained optimization and system solving. Years ago, the standard way to realize simulations for this kind of models involved writing your own code, using a programming language like FORTRAN, possibly making calls to external math library subroutines. Subsequently, the introduction of packages like Matlab, GAUSS, Octave and many others have made this process somewhat simpler, because vectors and matrices could be treated as single variables, and complex numerical tasks could be performed with a single instruction. However, one fundamental problem remained: the model code still looked much different from the more familiar mathematical notation one would have used in a paper. Therefore, checking and modifying the model code written by another researcher was a rather daunting task. To address this issue, GAMS (General Algebraic Modeling System) was developed by Alexander Meeraus and many of his collaborators at the World Bank in Washington D.C., since the late '70s (Meeraus, 1983). The main purpose of GAMS was (and still is) “providing a high-level language for the compact representation of large and complex models” and “permitting model descriptions that are independent of solution algorithms”. This paper presents an external module for the Python programming language and for the SAGE open source mathematical software, based on the same principles underlying GAMS and other similar packages. The purpose is providing a tool that takes the best of both worlds: the simplicity and clarity of GAMS-like systems combined with the flexibility and power of Python and SAGE. The paper is structured as follows. In the next section, some key characteristics of GAMS and other popular Modeling Systems are reviewed in some detail. Section 3 introduces the Python programming language and the closely related SAGE system for symbolic and numerical computation. Section 4 illustrates the basics of the syntax, and in Section 5 a practical example is provided. A discussion follows in Section 6 and a final section concludes. The paper presents an external module for programs written with the Python language and for the SAGE mathematical software. This module allows the definition and solution of non-linear systems and optimization problems, described in a way very similar to GAMS and programs alike. The key common characteristic of and GAMS is the automatic indexing of parameters, equations and variables. Since many elements of this kind can be defined with only one instruction (as one would normally do, for instance when the model is illustrated in a scientific paper), understanding how the model works directly by reading the program code is normally quite straightforward. The latter feature turns out to be particularly critical when the model code needs to be understood and manipulated by others, which may occur either in a team work or when replication and validation of some results is called for.

Suggested Citation

  • Roberto Roson, 2016. " a GAMS-like Modeling System based on Python and SAGE," EcoMod2016 9165, EcoMod.
  • Handle: RePEc:ekd:009007:9165

    Download full text from publisher

    File URL:
    Download Restriction: no

    Other versions of this item:

    References listed on IDEAS

    1. Pearson, K. R., 1988. "Automating the computation of solutions of large economic models," Economic Modelling, Elsevier, vol. 5(4), pages 385-395, October.
    2. Mark Horridge & Ken Pearson, 2011. "Solution Software for CGE Modeling," Centre of Policy Studies/IMPACT Centre Working Papers g-214, Victoria University, Centre of Policy Studies/IMPACT Centre.
    3. Meeraus, Alexander, 1983. "An algebraic approach to modeling," Journal of Economic Dynamics and Control, Elsevier, vol. 5(1), pages 81-108, February.
    Full references (including those not matched with items on IDEAS)

    More about this item


    None; Modeling: new developments; Miscellaneous;

    JEL classification:

    • C63 - Mathematical and Quantitative Methods - - Mathematical Methods; Programming Models; Mathematical and Simulation Modeling - - - Computational Techniques
    • C65 - Mathematical and Quantitative Methods - - Mathematical Methods; Programming Models; Mathematical and Simulation Modeling - - - Miscellaneous Mathematical Tools
    • C68 - Mathematical and Quantitative Methods - - Mathematical Methods; Programming Models; Mathematical and Simulation Modeling - - - Computable General Equilibrium Models
    • C8 - Mathematical and Quantitative Methods - - Data Collection and Data Estimation Methodology; Computer Programs

    NEP fields

    This paper has been announced in the following NEP Reports:


    Access and download statistics


    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:ekd:009007:9165. See general information about how to correct material in RePEc.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: (Theresa Leary). General contact details of provider: .

    If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

    If CitEc recognized a reference but did not link an item in RePEc to it, you can help with this form .

    If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your RePEc Author Service profile, as there may be some citations waiting for confirmation.

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service hosted by the Research Division of the Federal Reserve Bank of St. Louis . RePEc uses bibliographic data supplied by the respective publishers.