Giter Club home page Giter Club logo

econpdes.jl's Introduction

Build Status

Install

Pkg.clone("https://github.com/matthieugomez/EconPDEs.jl")

This package proposes a new, fast, and robust algorithm to solve PDEs associated with economic models (i.e. HJBs or market pricing equations). I discuss in details this algorithm here.

Solving PDEs

The function pdesolve takes three arguments: (i) a function encoding the pde (ii) a state grid corresponding to a discretized version of the state space (iii) an initial guess for the array(s) to solve for.

For instance, to solve the PDE corresponding to the Campbell Cochrane model:

using EconPDEs

# define state grid
state = OrderedDict(:s => linspace(-100, -2.4, 1000))

# define initial guess
y0 = OrderedDict(:p => ones(state[:x]))

# define pde function
# The function encoding the pde takes two arguments:
# 1. state variable 
# 2. current solution y
function f(state, y)
	μ = 0.0189 ; σ = 0.015 ; γ = 2.0 ; ρ = 0.116 ; κs = 0.13
	s = state.s
	p, ps, pss = y.p, y.ps, y.pss
	# Note that "y" contains the derivatives as fields. 
	# The field names correspond to the names given in the initial guess and in the state grid
	
	# drift and volatility of state variable s
	Sbar = σ * sqrt/ κs)
	sbar = log(Sbar)
	λ = 1 / Sbar * sqrt(1 - 2 * (s - sbar)) - 1
	μs = - κs * (s - sbar)
	σs = λ * σ

	# market price of risk κ
	κ = γ *+ σs)

	# risk free rate  r
	r = ρ + γ * μ - γ * κs / 2

	# drift and volatility of p
	σp = ps / p * σs
	μp = ps / p * μs + 0.5 * pss / p * σs^2

	# The function must return a tuple of two terms.
	# 1. A tuple corresponding to the value of the system of PDEs at this grid point.
	# 2. A tuple corresponding to the drift of state variables at this grid point (used for upwinding).
	out = p * (1 / p + μ + μp + σp * σ - r - κ *+ σp))
	return out, μs
end

# solve PDE
pdesolve(f, state, y0)

pdesolve then automatically creates and solves the finite different scheme associated with the PDE, using upwinding etc

Solving Non Linear Systems

pdesolve internally calls finiteschemesolve that is written specifically to solve non linear systems associated with finite difference schemes. finiteschemesolve can also be called directly.

Denote F the finite difference scheme corresponding to a PDE. The goal is to find y such that F(y) = 0. The function finiteschemesolve has the following syntax:

  • The first argument is a function F!(y, out) which transforms out = F(y) in place.
  • The second argument is an array of arbitrary dimension for the initial guess for y
  • The option is_algebraic (defaults to an array of false) is an array indicating the eventual algebraic equations (typically market clearing conditions).

Some options control the algorithm:

  • The option Δ (default to 1.0) specifies the initial time step.
  • The option inner_iterations (default to 10) specifies the number of inner Newton-Raphson iterations.
  • The option autodiff (default to true) specifies that the Jacobian is evaluated using automatic differentiation.

econpdes.jl's People

Contributors

matthieugomez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.