Exercises and Information

Version 2002-02-14

by

Peter Lohmander

www.Lohmander.com

 

 

A very quick course on VBScript and numerical optimization

 

When we study problems in economics and optimisation, we should not only consider the analytical results in general form. It is very good to have a simple, fast and complete numerical programming environment. There we can test the analytical results and check the magnitude of optimal results for typical parameter values. If this numerical environment is free of charge, it is even better. If it can be used on the web in a simple fashion, it is superb! VBScript is such a tool! The only drawback is that we are restricted to Microsoft Explorer. On the other hand, this web browser is free of charge, so it does not really matter!

 

1. Make sure that Microsoft Explorer is installed on your computer and that it has standard settings with respect to scripts.

 

2. We consider this problem: Maximize, by selecting the optimal harvest year, the present value of the harvest plus the released land after harvest. We assume that this simple function is OK when the forest stand soon will be harvested:

 

W(t) = (1/(1+i))^t * (P(t)V(t) + L) 

 

The definitions are the following: W(t) is the present value per hectare, P(t) is the net price per volume unit, V(t) is the volume per hectare, t is the harvest year (years from now) and i is the rate of interest in the capital market.

 

In order to make a long story shorter: Just click on this link:

 

www.Lohmander.com/Kurser/NLH02/harvopt2.htm

 

The following HTML file with included VBScript code solves the optimisation problem:

 

 

 

<html>

<body>

<H3>

www.Lohmander.com 2002-12-14 <br>

<script LANGUAGE = "VBScript">

 

st = 1

Do While st > 0

'------------------------------------------------------------------------------------------------------------------

Document.Write "<br>" & "**** Present value maximization ****" & "<br>"

topt = 0

nuvopt = 0

i = InputBox("Rate of interest = ", "User data")

v0 = InputBox("Volume per hectare right now = ", "User data")

v1 = InputBox("Volume growth per hectare and year = ", "User data")

p0 = InputBox("Net price per volume unit right now = ", "User data")

p1 = InputBox("Net price growth per year = ", "User data")

L = InputBox("Land value per hectare = ", "User data")

 

For t = 0 to 300

disc = (1/(1+i/100))^t

P = p0+p1*t

V = v0+v1*t

nuvev = disc*(P*V+L)

if nuvev > nuvopt then topt = t

if nuvev > nuvopt then nuvopt = nuvev

Next

 

Document.Write "Rate of interest= " & i & "<br>"

Document.Write "v0 = " & v0 & "<br>"

Document.Write "v1 = " & v1 & "<br>"

Document.Write "p0 = " & p0 & "<br>"

Document.Write "p1 = " & p1 & "<br>"

Document.Write "L  = " & L  & "<br>"

Document.Write "The optimal harvest year = " & topt & "<br>"

Document.Write "The optimal present value = " & INT(nuvopt) & "<br>"

st = InputBox("If you want to continue, write 1. Otherwise, write 0.", "Continue or stop")

'----------------------------------------------------------------------------------------------------------------------------

Loop

 

</script>

</H3>

</body>

</html>

 

 

 

 

You just write the code using a simple text editor and save it as a text file. You should give it the name harvopt2.htm.

Then, you just click on the file and you should be able to see the results.

 

The results should be the same as the results you find here: Just click on this link:

 

www.Lohmander.com/Kurser/NLH02/harvopt2.htm

 

I am convinced that you understand how to modify the script code above if you want to solve some similar type of problem. Please define some other optimisation problems, create the HTML and VBScript codes and check that the results make sense!