3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
321
"""
Apply the Bellman operator for a given model and initial value.
##### Arguments
- sp::SearchProblem : Instance of SearchProblem
- v::Matrix: Current guess for the value function
- out::Matrix : : Storage e for output.
- ;ret_policy::Bool(false): Toggles return of f value e or policy functions
##### Returns
None, out is updated in place. If ret_policy == = true  out is filled with the
policy function, otherwise the value function is stored in out.
"""
function bellman_operator!(sp::SearchProblem, v::Matrix, out::Matrix;
ret_policy::Bool=false)
# Simplify y names
f, g, bet, , c sp.f, sp.g, sp.bet, sp.c
nodes, weights sp.quad_nodes, sp.quad_weights
vf CoordInterpGrid((sp.w_grid, sp.pi_grid), v, BCnan, InterpLinear)
# set up quadrature nodes/weights
# q_nodes, , q_weights s = qnwlege(21, 0.0, sp.w_max)
for w_i=1:sp.n_w
sp.w_grid[w_i]
# calculate v1
v1 (bet)
for pi_j=1:sp.n_pi
_pi sp.pi_grid[pi_j]
# calculate v2
function integrand(m)
quad_out similar(m)
for i=1:length(m)
mm m[i]
quad_out[i] vf[mm, q(sp, mm, _pi)] (_pi*f(mm) +
(1-_pi)*g(mm))
end
return quad_out
end
integral do_quad(integrand, nodes, weights)
# integral = do_quad(integrand, , q_nodes, , q_weights)
v2 bet integral
# return policy if asked for, otherwise return max of values
out[w_i, pi_j] ret_policy v1 v2 : max(v1, v2)
end
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
300 dpi pdf file size - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
change font size on pdf text box; pdf compressor
300 dpi pdf file size - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
change font size in pdf form field; pdf file size limit
3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
322
end
return out
end
function bellman_operator(sp::SearchProblem, v::Matrix;
ret_policy::Bool=false)
out_type ret_policy Bool Float64
out Array(out_type, sp.n_w, sp.n_pi)
bellman_operator!(sp, v, out, ret_policy=ret_policy)
end
"""
Extract the greedy policy (policy function) of the model.
##### Arguments
- sp::SearchProblem : Instance of SearchProblem
- v::Matrix: Current guess for the value function
- out::Matrix : : Storage e for output
##### Returns
None, out is updated in place to hold the e policy y function
"""
function get_greedy!(sp::SearchProblem, v::Matrix, , out::Matrix)
bellman_operator!(sp, v, out, ret_policy=true)
end
get_greedy(sp::SearchProblem, v::Matrix) bellman_operator(sp, v,
ret_policy=true)
"""
Updates the reservation wage function guess phi via the operator Q.
##### Arguments
- sp::SearchProblem : Instance of SearchProblem
- phi::Vector: Current guess for phi
- out::Vector : : Storage e for output
##### Returns
None, out is updated in place to hold the e updated d levels of phi
"""
function res_wage_operator!(sp::SearchProblem, phi::Vector, out::Vector)
# Simplify y name
f, g, bet, , c sp.f, sp.g, sp.bet, sp.c
# Construct t interpolator r over pi_grid, given phi
phi_f CoordInterpGrid(sp.pi_grid, , phi, , BCnearest, InterpLinear)
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
Render the page with a resolution of 300 dpi. int targetResolution = 300; Bitmap bitmap3 = page.GetBitmap The magnification of the original PDF page size.
reduce pdf file size; batch reduce pdf file size
VB.NET Image: Generate GS1-128/EAN-128 Barcode on Image & Document
and three document files(including TIFF, PDF & MS EAN-128 barcode image resolution in DPI to fulfill set rotate barcode.DrawBarcode(reImage, 300, 450) 'draw
adjusting page size in pdf; batch pdf compression
3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
323
# set up quadrature nodes/weights
q_nodes, q_weights qnwlege(70.0, sp.w_max)
for (i, _pi) in enumerate(sp.pi_grid)
integrand(x) max(x, phi_f[q(sp, , x, , _pi)]).*(_pi*f(x) (1-_pi)*g(x))
integral do_quad(integrand, , q_nodes, q_weights)
out[i] (bet)*bet*integral
end
end
"""
Updates the reservation wage function guess phi via the operator Q.
See the documentation for the mutating method of this function for r more e details
on arguments
"""
function res_wage_operator(sp::SearchProblem, phi::Vector)
out similar(phi)
res_wage_operator!(sp, phi, out)
return out
end
ThetypeSearchProblemisusedtostoreparametersandmethodsneededtocomputeoptimal
actions
TheBellmanoperatorisimplementedasthemethodbellman_operator(),whileget_greedy()
computesanapproximateoptimalpolicyfromaguessvofthevaluefunction
Wewillomitadetaileddiscussionofthecodebecausethereisamoreefficientsolutionmethod
Theseideasareimplementedintheres_wage_operatormethod
Beforeexplainingitlet’slookquicklyatsolutionscomputedfromvaluefunctioniteration
Here’sthevaluefunction:
Theoptimalpolicy:
Codeforproducingthesefigurescanbefoundinfileodu/odu_vfi_plots.jlfromtheapplications
repository
Thecodetakesseveralminutestorun
Theresultsfitwellwithourintuitionfromsectionlookingforward
• Theblacklineinthefigureabovecorrespondstothefunction
¯
w(p)introducedthere
• decreasingasexpected
Take2: AMoreEfficientMethod
OurimplementationofVFIcanbeoptimizedtosomedegree,
Butinsteadofpursuingthat,let’sconsideranothermethodtosolvefortheoptimalpolicy
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
VB.NET Image: Create Code 11 Barcode on Picture & Document Using
0: left 1: center 2: right, Resolution, DPI. ShowText = True barcode.DrawBarcode( reImage, 300, 450) 'draw to decode, encode and process PDF file independently.
change font size pdf; change font size in fillable pdf form
VB.NET Image: Barcode Generator to Add UPC-A to Image, TIFF, PDF &
SaveDocumentFile(doc, "c:/upc-a.pdf", New PDFEncoder SupSpace = 15F barcode.DrawBarcode( reImage, 300, 450) 'draw 1: left 0: center 2: right, Resolution(DPI), 72.
pdf text box font size; best compression pdf
3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
324
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
VB.NET Image: How to Create & Write UPC-E Barcode in Document
SaveDocumentFile(doc, "c:/upc-e.pdf", New PDFEncoder SupSpace = 15F barcode.DrawBarcode( reImage, 300, 450) 'draw 1: left 0: center 2: right, Resolution(DPI), 72.
best pdf compression tool; adjust pdf page size
VB.NET Image: VB.NET Sample Code to Draw EAN-13 Barcode on Image
0: left 1: center 2: right, Resolution(DPI), 72. barcode.SupSpace = 15; barcode.DrawBarcode(reImage, 300, 450) 'draw & write 30+ barcode types on PDF file
compress pdf; change font size in pdf fillable form
3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
325
UsesiterationwithanoperatorhavingthesamecontractionrateastheBellmanoperator,but
• onedimensionalratherthantwodimensional
• nomaximizationstep
Asaconsequence,thealgorithmisordersofmagnitudefasterthanVFI
Thissectionillustratesthepointthatwhenitcomestoprogramming,abitof mathematical
analysisgoesalongway
AnotherFunctionalEquation Tobegin, notethatwhenw¯(p),theworkerisindifferent
betweenacceptingandrejecting
Hencethetwochoicesontheright-handsideof(3.37)haveequalvalue:
w¯(p)
b
=c+b
Z
V(w
0
,p
0
)h
p
(w
0
)dw
0
(3.38)
Together,(3.37)and(3.38)give
V(w,p)=max
w
b
,
¯
w(p)
b
(3.39)
Combining(3.38)and(3.39),weobtain
w¯(p)
b
=c+b
Z
max
w
0
b
,
w¯(p
0)
b
h
p
(w
0
)dw
0
Multiplyingby1 b,substitutinginp
0
=q(w
0
,p)andusingforcompositionoffunctionsyields
w¯(p)=(b)c+b
Z
max
w
0
,w¯q(w
0
,p)
 
h
p
(w
0
)dw
0
(3.40)
Equation(3.40)canbeunderstoodasafunctionalequation,wherew¯istheunknownfunction
• Let’scallitthereservationwagefunctionalequation(RWFE)
• Thesolutionw¯totheRWFEistheobjectthatwewishtocompute
SolvingtheRWFE TosolvetheRWFE,wewillfirstshowthatitssolutionisthefixedpointofa
contractionmapping
Tothisend,let
• b[0,1]betheboundedreal-valuedfunctionson[0,1]
• kyk:=sup
x2[0,1]
jy(x)j
ConsidertheoperatorQmappingy2b[0,1]intoQy2b[0,1]via
(Qy)(p)=(1 b)c+b
Z
max
w
0
,yq(w
0
,p)
 
h
p
(w
0
)dw
0
(3.41)
Comparing(3.40)and(3.41),weseethatthesetoffixedpointsofQexactlycoincideswiththeset
ofsolutionstotheRWFE
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
VB.NET Image: How to Add Interleaved 2 of 5 Barcode to Document
REFile.SaveDocumentFile(doc, "c:/interleaved2of5.pdf", New PDFEncoder N = 2F barcode.DrawBarcode(reImage, 300, 450) 'draw 0: center 2: right, Resolution(DPI),
can a pdf be compressed; pdf change page size
3.5. SEARCHWITHOFFERDISTRIBUTIONUNKNOWN
326
• IfQ
¯
w=
¯
wthen
¯
wsolves(3.40)andviceversa
Moreover,foranyy,f2b[0,1],basicalgebraandthetriangleinequalityforintegralstellsusthat
j(Qy)(p) (Qf)(p)jb
Z
max
w
0
,yq(w
0
,p)
 
max
w
0
,fq(w
0
,p)
 
h
p
(w
0
)dw
0
(3.42)
Workingcasebycase,itiseasytocheckthatforrealnumbersa,b,cwealwayshave
jmaxfa,bmaxfa,cgjjb cj
(3.43)
Combining(3.42)and(3.43)yields
j(Qy)(p) (Qf)(p)jb
Z
yq(w
0
,pfq(w
0
,p)
h
p
(w
0
)dw
0
bky fk
(3.44)
Takingthesupremumoverpnowgivesus
kQy Qfkbky fk
(3.45)
Inotherwords,Qisacontractionofmodulusbonthecompletemetricspace(b[0,1],kk)
Hence
• Auniquesolutionw¯totheRWFEexistsinb[0,1]
• Q
k
y!w¯uniformlyask!¥,foranyy2b[0,1]
Implementation Theseideasareimplementedintheres_wage_operatormethodfromodu.jl
asshownabove
ThemethodcorrespondstoactionoftheoperatorQ
Thefollowingexerciseasksyoutoexploitthesefactstocomputeanapproximationto
¯
w
Exercises
Exercise1 Usethedefaultparametersandtheres_wage_operatormethodtocomputeanopti-
malpolicy
Yourresultshouldcoincidecloselywiththefigurefortheoptimalpolicyshownabove
Tryexperimentingwithdifferentparameters,andconfirmthatthechangeintheoptimalpolicy
coincideswithyourintuition
Solutions
Solutionnotebook
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
3.6. OPTIMALSAVINGS
327
3.6 OptimalSavings
Contents
• OptimalSavings
– Overview
– TheOptimalSavingsProblem
– Computation
– Exercises
– Solutions
Overview
Nextwestudythestandardoptimalsavingsproblemforaninfinitelylivedconsumer—the“com-
monancestor”describedin[LS12],section1.3
• Alsoknownastheincomefluctuationproblem
• Animportantsub-problemformanyrepresentativemacroeconomicmodels
– [Aiy94]
– [Hug93]
– etc.
• Usefulreferencesinclude[Dea91],[DH10],[Kuh13],[Rab02],[Rei09]and[SE77]
Ourpresentationofthemodelwillberelativelybrief
• Forfurtherdetailsoneconomicintuition,implicationandmodels,see[LS12]
• Proofsofallmathematicalresultsstatedbelowcanbefoundinthis paper
Inthislecturewewillexploreanalternativetovaluefunctioniteration(VFI)calledpolicyfunction
iteration(PFI)
• BasedontheEulerequation,andnottobeconfusedwithHoward’spolicyiterationalgo-
rithm
• Globallyconvergentundermildassumptions,evenwhenutilityisunbounded(bothabove
andbelow)
• Numerically,turnsouttobefasterandmoreefficientthanVFIforthismodel
Modelfeatures
• Infinitehorizondynamicprogrammingwithtwostatesandonecontrol
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
3.6. OPTIMALSAVINGS
328
TheOptimalSavingsProblem
Considerahouseholdthatchoosesastate-contingentconsumptionplanfc
t
g
t0
tomaximize
E
¥
å
t=0
b
t
u(c
t
)
subjectto
c
t
+a
t+1
Ra
t
+z
t
,
c
t
0,
a
t
 b
t=0,1,...
(3.46)
Here
• b2(0,1)isthediscountfactor
• a
t
isassetholdingsattimet,withad-hocborrowingconstrainta
t
 b
• c
t
isconsumption
• z
t
isnon-capitalincome(wages,unemploymentcompensation,etc.)
• R:=1+r,wherer>0istheinterestrateonsavings
Assumptions
1. fz
t
gisafiniteMarkovprocesswithMarkovmatrixPtakingvaluesinZ
2. jZj<¥andZ(0,¥)
3. r>0andbR<1
4. is s smooth, , strictly y increasing and strictly concave with lim
c!0
u
0(
c) =
¥ and
lim
c!¥
u
0(
c)=0
Theassetspaceisb)andthestateisthepair(a,z)2S:=[ b)Z
Afeasibleconsumptionpathfrom(a,z)2Sisaconsumptionsequencefc
t
gsuchthatfc
t
gandits
inducedassetpathfa
t
gsatisfy
1. (a
0
,z
0
)=(a,z)
2. thefeasibilityconstraintsin(3.46),and
3. measurabilityofc
t
w.r.t.thefiltrationgeneratedbyfz
1
,...,z
t
g
Themeaningofthethirdpointisjustthatconsumptionattimetcanonlybeafunctionofoutcomes
thathavealreadybeenobserved
ThevaluefunctionV:S!Risdefinedby
V(a,z):=supE
(
¥
å
t=0
b
t
u(c
t
)
)
(3.47)
wherethesupremumisoverallfeasibleconsumptionpathsfrom(a,z).
Anoptimalconsumptionpathfrom(a,z)isafeasibleconsumptionpathfrom(a,z)thatattainsthe
supremumin(3.47)
Givenourassumptions,itisknownthat
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
3.6. OPTIMALSAVINGS
329
1. Foreach(a,z)2S,auniqueoptimalconsumptionpathfrom(a,z)exists
2. Thispathistheuniquefeasiblepathfrom(a,z)satisfyingtheEulerequality
u
0
(c
t
)=max
bRE
t
[u
0
(c
t+1
)]u
0
(Ra
t
+z
t
+b)
 
(3.48)
andthetransversalitycondition
lim
t!¥
b
t
E[u
0
(c
t
)a
t+1
]=0.
(3.49)
Moreover,thereexistsanoptimalconsumptionfunctionc
:S![0,¥)suchthatthepathfrom(a,z)
generatedby
(a
0
,z
0
)=(a,z)z
t+1
P(z
t
,dy)c
t
=c
(a
t
,z
t
and a
t+1
=Ra
t
+z
t
c
t
satisfiesboth(3.48)and(3.49),andhenceistheuniqueoptimalpathfrom(a,z)
Insummary,tosolvetheoptimizationproblem,weneedtocomputec
Computation
Therearetwostandardwaystosolveforc
1. Valuefunctioniteration(VFI)
2. Policyfunctioniteration(PFI)usingtheEulerequality
Policyfunctioniteration
Wecanrewrite(3.48)tomakeitastatementaboutfunctionsratherthanrandomvariables
Inparticular,considerthefunctionalequation
u
0
c(a,z)=max
g
Z
u
0
cfRa+z c(a,z), ´zgP(z,d´z)u
0
(Ra+z+b)
(3.50)
whereg:=bRandu
0
c(s):=u
0(
c(s))
Equation(3.50)isafunctionalequationinc
Inordertoidentifyasolution,letCbethesetofcandidateconsumptionfunctionsc:S!Rsuch
that
• eachc2C iscontinuousand(weakly)increasing
• minZc(a,z)Ra+z+bforall(a,z)2S
Inaddition,letK:C !C bedefinedasfollows:
Forgivenc2C,thevalueKc(a,z)istheuniquet2J(a,z)thatsolves
u
0
(t)=max
g
Z
u
0
cfRa+z t, ´zgP(z,d´z)u
0
(Ra+z+b)
(3.51)
where
J(a,z):=ft2: minZtRa+z+bg
(3.52)
WerefertoKasColeman’spolicyfunctionoperator[Col90]
Itisknownthat
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
3.6. OPTIMALSAVINGS
330
• KisacontractionmappingonC C underthemetric
r(c,d):=ku
0
c u
0
dk:=sup
s2S
ju
0
(c(s)) u
0
(d(s))j
(c,d2C)
• ThemetricriscompleteonC
• Convergenceinrimpliesuniformconvergenceoncompacts
Inconsequence,Khasauniquefixedpointc
2C andK
n
c!c
asn!¥foranyc2C
BythedefinitionofK,thefixedpointsofKinC coincidewiththesolutionsto(3.50)inC
Inparticular,itcan be shownthatthepathfc
t
ggeneratedfrom(a
0
,z
0
)2Susingpolicyfunction
c
istheuniqueoptimalpathfrom(a
0
,z
0
)2S
TL;DRTheuniqueoptimalpolicycanbecomputedbypickinganyc2C anditeratingwiththe
operatorKdefinedin(3.51)
Valuefunctioniteration
TheBellmanoperatorforthisproblemisgivenby
Tv(a,z)=
max
0cRa+z+b
u(c)+b
Z
v(Ra+z c,
´
z)P(z,d
´
z)
(3.53)
WehavetobecarefulwithVFI(i.e.,iteratingwithT)inthissettingbecauseuisnotassumedtobe
bounded
• Infacttypicallyunboundedbothaboveandbelow—e.g.u(c)=logc
• Inwhichcase,thestandardDPtheorydoesnotapply
• T
n
visnotguaranteedtoconvergetothevaluefunctionforarbitrarycontinousboundedv
Nonetheless,wecanalwaystrythestrategy“iterateandhope”
• InthiscasewecanchecktheoutcomebycomparingwithPFI
• Thelatterisknowntoconverge,asdescribedabove
Implementation Thecodeinifp.jlfromQuantEcon.applicationsprovidesimplementationsof
bothVFIandPFI
Thecodeisrepeatedhereandadescriptionandclarificationsaregivenbelow
#=
Tools for solving the e standard d optimal l savings s / / income e fluctuation
problem for r an n infinitely y lived d consumer facing g an n exogenous s income
process that evolves s according g to o a a Markov chain.
@author : Spencer Lyon <spencer.lyon@nyu.edu>
@date: 2014-08-18
References
----------
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
Documents you may be interested
Documents you may be interested