3123 Reputation

16 Badges

12 years, 314 days

MaplePrimes Activity

These are answers submitted by MrMarc

Thanx Joe exellent stuff :-)
I think I need to do more research into Markov chains because I have a hard time keeping
up with the terminology ie  transition matrix, stationary probability vector, Eigenvectors etc
If you have any free time feal free to try to explain such things. I am not expecting anything though :-)

Sample(RandomVariable(Normal(0, 1)), 10);

   [-0.479341933636560024, 0.784173699733298979, -0.500486574831822351,

     -0.491050898933502511, 0.237828352925436416, -0.148240640484583186,

     -0.0707527186858661478, 1.06583429443452870, -1.44945211081540992,



That is perfect Robert :-)  Sweet ! 
I think I now know why my code did not work because I did not specify Game C correctly

"Game C: play game A when turn number is divisible by 3, otherwise game B."

The thing is that I have not found one single reference that have explain that (not even the original flow chart that I posted)
so I am very greatful that you pointed that out :-).  I have created a revised flowchart to illustrate the dynamics:

I was just wondering if there are any particular reason why you have p=0.495 for Game A.
Can you put it to p=0.5 or will that change the dynamics ?!  Another thing if it is not to much to ask could you please
try to explain why the green curve has a positive slope both in words and in equations.
I mean it is very easy to see that it is the case but why ?

They are taking about Brownian ratchet but it is very difficult to see how such mechanics results in an
upward sloping green line .... humm

Is it possible to view a 3D Matrix (Array) in Maple as seen below ?



All right thanx :-)  I just find these 3D matricies to be fascinating

First insert a slider called Slider0 in the worksheet. You can set the value of the slider as follows:

x := 60:
SetProperty('Slider0', 'value', x);

I also have a problem with this SQL Server Agent (SQLEXPRESS). It wount start :-(

In excel it works perfectly. I just fill in some information about SQL server database name and password
and I get the data instantly. In Maple it does not work at all. I all the above examples I have used

url := "jdbc:sqlserver://localhost";

Now if I use

url := "jdbc:sqlserver://MARCUS-PC\SQLEXPRESS";

then I get :

Error, (in OpenConnection) The TCP/IP connection to the host MARCUS-PC/SQLEXPRESS, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
Error, `connection` does not evaluate to a module


When I execute the command without 'output' = Array; I get all blue text

connection:-ExecuteQuery("select * from Data WHERE dTicker='A'");


  module () local handle; export Next, Previous, Last, First, GetRowIndex,

     GotoRow, GetRowCount, InsertRow, DeleteRow, UpdateRow, GetData,

     UpdateData, GetType, GetName, GetColumnCount, SetOptions, GetOptions,

     Close, ToMaple; option unload = Close; end module


The thing is that when I call the SQL command:  select * from Data WHERE dTicker='A'

Inside Microsoft SQL Server Management Studio it works perfectly fine but the same command

connection:-ExecuteQuery("select * from Data WHERE dTicker='A'", 'output' = Array);

does not work in Maple..........strange


When I call :  connection:-GetColumns('output' = ['table', 'name']);

I get  Error, (in GetColumns) could not get data for 'table', this option may not be supported with the current database system.

When I call :  connection:-ExecuteQuery("select * from Data WHERE dTicker='A'", 'output' = Array);

I get  Error, (in ExecuteQuery) unknown API type


I agree :-)

Let me clarify with regard to the matrix. It possible to have a matrix that that have three columns:
the first column contain integer[2], the second column contail float[8] and the third column contain float[8]
Like this :

zz:=proc( X:: Matrix(datatype = [integer[2], float[8], float[8] ] ))

If we put   cc::(Matrix(datatype = float[8]))  as a parameter in SortX and then we can call it like

cc := Matrix(10, 3, datatype = float[8], storage = rectangular);
SortX(Ans, data1, cc, nstock);

It works (it is compiled correcly) and the code does 2000 stocks in 30 seconds. If we simply call

X := proc (SR::(Matrix(datatype = float[8])))
local n, nstock, Ans, ap, mm, i, j, cc, data1, nM;
n, nstock := op(1, SR);
Ans := Matrix(nstock, nstock, datatype = float[8], storage = rectangular):
Sharpe(Ans, nstock, n, SR):
data1 := sort(Alias(Ans, [nstock^2]), `>`)[1 .. 10] ;
end proc;

then it does 2000 stocks in 22 seconds however we dont have the index numbers.
My goal is to find an algorithm that sorts and gives me the index numbers for 2000
stocks in approx 25 seconds. I wonder if it is doable...?!

This is what I have got so far (see below). I a run Acer's code above without the
sort procedure it takes 0.5 seconds for 200 stocks. If I run the below code
with the sort procedure it takes 5.2 seconds, ok but still not good enough.
I want to get it down to around 1-2 seconds. I think there is a problem 
with compile in SortX. When I run Comipler:-Compile(SortX) it gives 
me an error message 

Error, (in printtab[CodeGeneration:-Names:-Declaration]) local variables cannot have Array types


Sharpe := proc (Ans::(Matrix(datatype = float[8])), nstock::(integer[4]), N::(integer[4]), 
SR::(Matrix(datatype = float[8]))) 
local ap1::float, ap2::float, i::(integer[4]), j::(integer[4]), r::(integer[4]), 
Xmean::float, Xstdev::float; 
option autocompile; 

for i to nstock do 
for j to i-1 do 

ap1 := 0.; 
for r to N do 
ap1 := ap1+SR[r, i]-SR[r, j] 
end do; 
Xmean := ap1/N; 

ap2 := 0.; 
for r to N do 
ap2 := ap2+(SR[r, i]-SR[r, j]-Xmean)^2 
end do; 
Xstdev := sqrt(ap2/(N-1)); 

Ans[i, j] := Xmean/Xstdev; 
Ans[j, i] := -Ans[i, j] 

end do 
end do 
end proc:

SortX := proc (Ans::(Matrix(datatype = float[8])), cc::(Matrix(datatype = float[8])), 
local ap, mm, i, j; 
option autocompile; 

for ap to 10 do 

mm[ap] := 0; 

for i to nstock do 
for j to nstock do 

if mm[ap] < Ans[i, j] then mm[ap] := Ans[i, j] 

end if end do end do; 

for i to nstock do 
for j to nstock do 

if Ans[i, j] = mm[ap] then 
cc[ap, 1] := i; cc[ap, 2] := -j; cc[ap, 3] := Ans[i, j]; Ans[i, j] := 0 else  end if: 

end do: 
end do: 
end do: 

end proc:

nstock := 200: 
n := 100: 

SR := Transpose(Matrix(`<,>`(seq(Sample(RandomVariable(Normal(0, 1)), n), i = 1 .. nstock)))):
st := time():
Ans := Matrix(nstock, nstock, datatype = float[8], storage = rectangular):
Sharpe(Ans, nstock, n, SR):
cc := Matrix(10, 3, datatype = float[8], storage = rectangular):
SortX(Ans, cc, nstock):

3 4 5 6 7 8 9 Last Page 5 of 25