# Organizing Code for a Complex Model¶

## Setting Parameters¶

The problem: one typically solves several versions of a model. How to ensure that all the right fixed / calibrated parameters are set for each version?

Example: A model is solved with different production functions, say Cobb-Douglas or CES.

Here is a possible workflow:

- Assign each model version a number.
- Write a file that sets “named” choices for each model version.
- E.g.:
`cS.prodFct = 'CES'`

- E.g.:
- For each named choice, define an
`object`

with the properties / methods:- provide a list of all potentially calibrated parameters (in my code, these would be
`pstructLH`

objects) - provide methods that are needed to solve the model (e.g.: return marginal products etc)

- provide a list of all potentially calibrated parameters (in my code, these would be
- Collect all potentially calibrated parameters into a
`pvectorLH`

object- This can make a vector of guesses that can be passed into optimization functions (such as
`fmincon`

) - It can take the
`guess`

vector and transform it into the parameters to be calibrated - For model objects that can be swapped out, simply question the object to get a list of all parameters it needs.

- This can make a vector of guesses that can be passed into optimization functions (such as
- In the model solution code, you don’t need to know what kind of production function is used. Key is that all of them have the same methods.

Now, to solve the model with a different production function, simply call the constructor for the appropriate object. The rest is automatic.