MrMarc

3163 Reputation

18 Badges

17 years, 131 days

MaplePrimes Activity


These are answers submitted by MrMarc

 

Doug yes that is exactly what I mean :-) 

I appreciate your creative input here on how to solve the problem but "simulate the menu bar" seems a bit ad hoc

but maybe it is as close we can get to the real thing :-)  The user should not only be able to create shortcuts to

Maplets but also shortcuts to Maple worksheets in the GUI for quick and easy access. 

 

"an embedded component (button or combo box) whose action is to launch a maplet."
 

yes that would also be useful. I had not thought of that one. Quite nice actually :-)

 

 

Doug I followed you roadmap and my conclusion is still that you can not bookmark (ie create shortcut) to Maplets

or even Maple worksheets inside Maple. As you point out Maple can view Maplets externally but in my opinion this

is not really the same. For example there are loads of empty space in the menu field inside Maple (ontop where

the zoom buttons are)   I want to be able to place shortcuts to some Maplets there. When I click on the shortcut

the Maplet or Maple worksheet should launch. This is possible in MATLAB and is a very valuable feature because

it means that you can customize the software to your personal preferences. At present I cant see how this would

be possible in Maple which is a significant weakness.

if the code is huge why dont you just run the code in sections and see where the

error message pops up ?!  ie 1..2, 1..3, 1..4 etc.  Then you can post such a code

oohhh I managed to solve it. I accidently used [seq(ap[i], i = 1 .. n-1)]  as the y variable when

it should have been [seq(ap[i], i = 2 .. n)]. Now it works as expected :-)

 


restart:
with(Statistics):
with(LinearAlgebra):

n := 500:

E := Sample(RandomVariable(Normal(0, 10)), n):
B :=0.7:

for t from 2 to n do

ap[1] := 100; ap[t] := B*ap[t-1]+E[t]

end do:

XX := [seq(ap[i], i = 1 .. n-1)] :
YY := [seq(ap[i], i = 2 .. n)]:

w1 := Fit(B2*x, XX, YY, x, output = parametervector):
w2 := Fit(B2*x, XX, YY, x, output = standarderrors):

`<|>`(`<,>`(B2 = evalf(w1[1], 3)), `<,>`(TstatB2 = evalf(w1[1]/w2[1], 5)), `<,>`(Significant = is(abs(evalf(w1[1]/w2[1], 5)) > 2)));


             [B2 = 0.692  TstatB2 = 14.561  Significant = true]
 

thank you alec :-)   stable as usual !

dont worry about the second question I realized that the question is impossible to solve the way I stated it.

I managed to solve it as follows:


restart:
with(Statistics);
with(plots);
randomize();

n := 10; mu := 0; sigma := .5; tt := 100; `&Delta;t` := evalf(1/tt, 3);

r := Sample(RandomVariable(Normal(mu*`&Delta;t`, sigma*sqrt(`&Delta;t`))), n*tt);

X := proc (ap) local t, s, ss, app;

for t to n*tt do

s[0] := 500; s[t] := s[t-1]+s[t-1]*r[t]

end do;

ss := [seq(s[i], i = 1 .. n*tt, ap)];

app := [seq(i, i = 1 .. nops(ss), nops(ss)/n)];

listplot(ss, color = black, thickness = 2, labels = ["Time", "Stock Price"], labelfont = [Times, Roman, 14], font = [times, roman, 14], tickmarks = [[seq(app[i] = i, i = 1 .. n)], default])

end proc;
 

where ap is the slider   Do(%Plot2=X(%Slider2));

 

which illustrates how the geometric brownian motion changes when dt changes 

MapleSim seems to mostly to be focused on enginering (ie mechanical, electrical).

I want to bulild a generic finance model (ie a market making model) but it sems to be rather difficult.....

Where different components represent speculators and market makers etc

all right let me expain. I have no idea how this MapleSim works so I want to start with an simple example.

I found this add component that seem simple enough. It has 2 input connections to it and 1 output.

I want to simply connect two random variables to the 2 input connections and then connect a plot to the

output connection. Then simply run the simulation and see what the add chart look like.

I have no idea if this is the way you do things as I said I have no clue how the software is designed to work :-)

 

I would assume that over time we would get something like the code below.

Again my question is how can this be generalized into a contineous Normal(0,1) process ?


with(plottools):
with(plots):
rotate(textplot([seq(seq([i-j, j, binomial(i, j)/2^i], j = 0 .. i), i = 0 .. 12)], axes = none, font = [times, roman, 16]), -(1/4)*Pi);
 

Note : 

I think the answer is that the volatility of the initial distribution N(0,1) grows over time with the sqrt (time period) .

This also makes sense by looking at the above picture the distribution seems get wider and wider over time :-)

I tried to simulate multiple units roots where the green line is given by u[i] and redline is given by d[i]


m := 0:   stdev := 1:    where time = 1,2,3,4,...

u[time] := 100+( m+3*stdev*sqrt(time) ) :      d[time] := 100+( m-3*stdev*sqrt(time) );

 

 

It seems to work which is good :-)  This means that the probability of observing a value of x at time t

where x is the sum of the random variables from 1 to t and assuming a starting value of 30 should be given by:
 

restart:
with(Statistics):
with(plots):
f := proc (v, x) options operator, arrow; PDF(Normal(0, v+1), x-31) end proc :
matrixplot(Matrix(f, 10, 60), axes = boxed, color = green, labels = ["Time", "x", "P(x)"], labelfont = [times, roman, 14], font = [times, roman, 12]);
 

 

What do you think about that Robert ? Is that correct ?!

another way of looking at it would be to say that we have a 0.997 probability that the return is going to be between:

mean+3*stdev

mean - 3*stdev

but then the problems becomes how we are going to generalize that over for example 5 time periods ?!
 

Another way would be to use the following code :

restart;
f := piecewise(S > MS*(1-Trail), S-(1-Trail)*S, 0);
MS := 200:   # Highest previous stock price
Trail := .2:
S := 161:
f;
 

but the problem there is that you have to loop the code to get access to MS....hummm          

Based upon the previous discussion www.mapleprimes.com/forum/equationn010pdfstop10

which assumes a one period stop model the conclussion was that the probability

that the stop was going to be hit is equal to:

restart:
with(plots):
with(Statistics):
Stop := -10 :
v := 20 :
f := piecewise(x < Stop, 0, CDF(Normal(0, v), x)) :
'Probability*Stop*Hit' = evalf(eval(f, x = Stop), 4);

                  Probability Stop Hit = 0.3086
 

However I would assume that the way a trailing stop (dynamically changing over time) would

work mathematicaly is very differently from a one period stop ?!

I would assume that the below code can be used to calculate the probability that we will observe a

return at time 5 which is less than or equal to zero given that the all the previous periods have had returns that have

been less than or equal to zero.

restart: 
with(Statistics):
nperiod := 5 :
f := eval(CDF(Normal(0, 5), x), x = 0) :
ff := evalf(f^nperiod, 4);
  
                                ff := 0.03125


and by the same reasoning I assume that the below code can be used to calculate the probability that we will observe a

return at time 5 which is less than or equal to -5 given that the all the previous periods have had returns that have

been less than or equal to -5 .

restart: 
with(Statistics):
nperiod := 5 :
f := eval(CDF(Normal(0, 5), x), x = -5) :
ff := evalf(f^nperiod, 4);

                               ff := 0.0001007

 

I am not sure such reasoning is important thought ?!

all right that is nice alec !  Thanx for your input, help and support :-)

Yes, this was certainly an interesting thread with a lot of nice inputs.

I have read the thread multiple times and I must admit I learned a lot : -)

I now understand why alec said that the "CDF is more simple". The below code

gives me an equation for the CDF,  a probability estimate of that the stop is going

to be triggered and a plot that is acceptable  That ticks all my boxes so I am happy with that :-)


restart :
with(Statistics) :
Stop := -10 :
f := piecewise(x < Stop, 0, CDF(Normal(0, 20), x));
evalf(eval(f, x = Stop), 4);
plot(f, x = -20 .. 40);
 


It would also be interesting to see a generalization of this argument in the form of a

a conditional stop. Maybe I have to start a new post for this one.  What is the probability

that a conitional stop of let say -20 for the last 5 periods is going to be triggered ?!

I think this would be a more accurate description of what is going on for a N(0,20) with Stop=-10 or ?!

restart:
with(Statistics):
Stop := -10:
A := evalf(int(PDF(Normal(0, 20), X), X = -infinity .. Stop)):
f := piecewise(x < Stop, 0, x > -9.1, PDF(Normal(0, 20), x), A);
eval(f, x = -10);
plot(f, x = -20 .. 40);
 

However even if we have an integral in the piecewise function like the code below it still wont work because

the probability at -10 is wrong, strange ...


restart;
with(Statistics): 
Stop := -10 :
A := evalf(int(PDF(Normal(0, 20), X), X = -infinity .. Stop)): 
f := piecewise(x < Stop, 0, x = Stop, A, x > Stop, PDF(Normal(0, 20), x)); 
plot(f, x = -20 .. 80);

The reason might be that piecewise can not handle equalities

First 8 9 10 11 12 13 14 Last Page 10 of 24