MrMarc

3163 Reputation

18 Badges

17 years, 133 days

MaplePrimes Activity


These are answers submitted by MrMarc

 

I have attached a pdf file outlining the problem (updated=working)

www.mapleprimes.com/files/8342_Chiang.pdf

and my maple file

www.mapleprimes.com/files/8342_new.mw

 

It is highly important to understand this derivation and why he use p(t) instead of diff(p(t),t)

since the euler equation given by

 

is the link between lagrange and optimal control.

Otherwise I cannot explain the structure of the present and current value hamiltonian

 

 

 Ok let see if I can explain it

Chiang wants to integrate the below equation by parts

 

By using the formula

 

He assumes that

 

 

and that

 

so we get

 

and

 

what I dont understand is why he defines p(t)=U and not diff(p(t),t)=U ??

 

when we have F( g(t) , f(t) )  then we get

 

and we define

 

but this is not the same way chiang does it .......... strange

ok, I will explain as soon as I figure our how to post 2-D equations...humm

 

 

I have given up trying to derivation of the euler equation in Maple.

Now I only use Maple as a word processor (typing equations manually) since it is just impossible to get Maple to do what I want.

 

One question though:

 

Does anyone know why Chiang in Elements of Dynamic Optimization

defines u as p(t) instead of diff(p(t),t) when he integrate the equation by part to get the Euler equation??

maybe this is a stupid question but

-V(F(a), G(a)) + V(F(b), G(b))

is that the expression we get when we evaluate V( F(x), G(x) at the end points a and b ?

Is there a simple way to show this?

 

ok, thank you for your input Robert....:-)

 

I have attached the Maple file

www.mapleprimes.com/files/8342_MM.mw

 

maybe this is even a more stupid question then but what rules are we

using when we are differentiating that expression?

Thanx Joe!  Saved me a couple of hours. I could not get my small head around it :-)

Thank you Joe!  

As always solid as a rock!  

I appreciate you taking the time to explain this to me :-)

Doug if you are interested check out my uploads at 

http://www.maplesoft.com/applications/app_center_advanced_search.aspx?ABA=87231

you might pick up something there. But it is not related to programming but rather economic and finance.

There are more to come...have loads of stuff...:-)

Again, just for the record

Based upon further disussion with Joe Riel  we can put the output from the do-loop in a list by using the below code

Again everything after "for cnt to to nq do" should be without execute symbol >  (Achived by pressing shift-enter)

 

restart;
with(Statistics):

# parameters
s[1]:=100:     # Starting price stock
d:=4:              # Trailing distance
n:=100:         # Number of periods
nq:=100:       # Number of simulations

# stock price
randomize():
T := table():      # Assign table used to temporarily store results for do-loop

for cnt to nq do   # The starting point for the do-loop
rand_:=Sample(RandomVariable(Normal(0,1)),n):
for i from 2 to n do s[i]:=s[i-1]+rand_[i] end do:
A:=[seq(s[i],i=1..n)]:

# Trailing stop-loss
B[1]:=(A[1]-d):  
for i from 2 to n do
B[i]:=`if`(A[i]>A[i-1] and A[i]>(A[i]-d) and (A[i]-d)>B[i-1],(A[i]-d),B[i-1])
od:
C:=[seq(B[i],i=1..n)]:
r[1]:=0: for i from 2 to n do r[i]:=`if`(A[i]>C[i],0,1) od:
w:=[seq(r[i],i=1..n)]:
wp[1]:=0: for i from 2 to n do wp[i]:=(w[i]+wp[i-1]) od:
w_w_:=[seq(wp[i],i=1..n)]:
ww[1]:=0: for i from 2 to n do ww[i]:=(w_w_[i]+w_w_[i-1]) od:
w_w:=[seq(ww[i],i=1..n)]:

# Final Corrections
C_[1]:=(A[1]-d): for i from 2 to n do C_[i]:=`if`(w_w[i]=0,C[i],C_[i-1]) od:
C_C:=[seq(C_[i],i=1..n)]:

########### Results #########

# Exit period due to stop loss
u[1]:=0: for i from 2 to n do u[i]:=`if`(w_w[i]=1,i,0) od:
Exit_period:=convert([seq(u[i],i=1..n)],'`+`' );

# Exit price stop loss
Exit_price:=`if`(Exit_period=0,0,C_C[n]);

# Last close stock price
Last_close:=`if`(A[n]<0,0,A[n]);

# profit loss with stop loss
prof_s:=`if`(Exit_price=0,Last_close-A[1],Exit_price-A[1]);

# profit loss without stop loss
prof_:=Last_close-A[1];
#############################
T[cnt]:=prof_s;
end do:

h:= convert(T,'list'):

wow!  I am just amazed that you managed to do all that work in such a short period and with such a precision and insight !

That work for me would have taken about 1 year, ha ha and then I am rounding down with about 10 years. Sweet !

 

thanx Doug!  As i have said previously I am quite overwhelmed with your guys willingness to help

and do some serious work! I am quite sure this is a unique trade to the helpful people posting at the maple forum and   

I am very greatful for it.  I will have a look at your work and post if I have any questions. Again thanx for your time and effort.

You saved the day !!

or should I say the week or even the month without exaggerating !

very grateful for your input and help !  :-)

First 18 19 20 21 22 23 24 Page 20 of 24