MrMarc

3163 Reputation

18 Badges

17 years, 131 days

MaplePrimes Activity


These are answers submitted by MrMarc

I am not sure a mixed distribution is the best way maybe a conditional distribution is better ?!

For example if we run alec's code with PDF instead of CDF we get something like this:

 

f:=piecewise(x<-10,0,Statistics:-PDF(Normal(0,20),x)):

plot(f,x=-20..80);

 

 

However this is not a valid representation of the stop-loss distribution because here we simply cut the

distribution at some point it does not aggregate all probabilities up to point -10.

Maybe an integral should be used instead of 0 in the piecewise function if x<-10 ....hummmm

 

all right thanx alec and we concluded that the PDF could not be plotted or ?!

If you plot the PDF it should look something like the picture below .

Alec what Maple code should I use to extract the equation and plot the CDF that you are talking about ?

ooohh ok, ha ha .... I will have to try something ells then to extract the PDF

what Maple code should I use to get such a Pdf  ? 

The Maple code could include a plot of the pdf so we can see that it is pdf is working as it should

 Yes I agree with you I also had problems with decimals, digits, float[8] etc....a bit annoying.

Hey alec how could I construct a random correlation matrix that still is positive definite but is tilted in one

direction for example more negative cross correlation than positive or more positive than negative cross correlation etc ?!

thanx Robert for sharing your wisdom with us. That worked great :-) . Very nice indeed. I spend all last night trying

to solve the problem when I came across this website :   http://comisef.wikidot.com/tutorial:repairingcorrelation

It has some very nice ( simple and straightforward ) Matlab code which I simply translated to Maple.

It seams to do the trick but dont ask me why because I have no idea :-)

 

restart :
with(LinearAlgebra) :
C := Matrix([[1, .9, -.7], [.9, 1, .3], [-.7, .3, 1]]);
IsDefinite(C);

unprotect(D) :
# computes eigenvector and eigenvalues
V := Re(Eigenvectors(C)[2]) :
D := DiagonalMatrix(Re(Eigenvalues(C))) :

# replaces negative eigenvalues with zero
D := map(proc (x) options operator, arrow; `if`(x < 0, 0, x) end proc, D) :

# reconstruct correlation matrix
BB := Multiply(Multiply(V, D),Transpose(V)) :

# rescale correlation matrix
T := Transpose(Matrix(1/Array(Diagonal(BB))^.5)) :
TT := Multiply(T, Transpose(T)) :

# new correlation matrix
CC := evalf(Matrix(Array(BB)*Array(TT)), 6);
IsDefinite(CC) ;

                                                               false
                                                                true

I did however find some MATLAB code:

 

Here's matlab code...
%Reference
%The most general methodology to create a valid correlation matrix for risk management and option pricing purposes
%Riccardo Rebonato, Peter J¨ackel, Quantitative Research Centre of the NatWest Group, 19 th October 1999
%http://www.quarchome.org/correlationmatrix.pdf


n=5; %Dimension of the correlation matrix
%Generating random correlation matrix
k=(rand(n)*2-1); k=(k+k')/2; %Random symmetric matrix
C=k.*not(eye(n))+eye(n) %Principal diagonal elements set to unity

%Spectral Decomposition
[CVec, CVal]=eig(C); %Original eigenvectors and eigenvalues stored
CVal_colvector=eig(C); %Eigenvales in a column vector
PosTest=CVal_colvector>=0 %Testing if all eigenvalues are non-negative
CVal_colvector_cor=CVal_colvector.*PosTest; %Setting -ve eigenvalues to zero
CVal_Cor=CVal_colvector_cor*ones(1, n).*eye(n); %Corrected eigenvalue matrix


BDash=CVec.*((ones(n)*CVal_Cor).^0.5); %Eigenvector scaled by "square root of" individual corrected eigenvalues.
B=BDash./repmat(sum((BDash.^2),2).^0.5, 1, n) %Normalized to have row vectors of unit length
CDash=B*B'


%Simpler alternate approach to above three lines
T=repmat(sum(CVec.*CVec.*repmat(CVal_colvector_cor', n, 1), 2).^(-1), 1, n).*eye(n); %Diagonal scaling matrix
B_alternate=(T.^0.5)*CVec*(CVal_Cor.^0.5)
CDash_alternate=B_alternate*B_alternate'

humm I must admit I have no idea what is going on :-) 

I tried to read the article you suggested at:   www.gloriamundi.org/picsresources/ahtw.pdf

But I did not realy understand anything...

oohh yes of course. sorry, I kind of overlooked that. Back to the drawing board....

heyy what did you do with C := C.Transpose(C) it seamed to do the trick ?!

I tried to run the below code but as I might have suspected the matrix still is not positive-definite...hummm


restart;
with(LinearAlgebra):

n := 10:
x := [evalf(seq((1/10)*(rand(-10 .. 10))(), i = 1 .. n), 1)] :

for i to n do
for j to n do

if i = j then xx[i, j] := 1
elif i = 1 then xx[1, j] := x[j]
else xx[i, j] := x[j] end if

end do
end do:

C := Matrix(n, n, xx);
Eigenvalues(C);
IsDefinite(C)

ok fair enough !  thanx for your input Darin

Hopefully this can be solved in time for Maple 14 or sooner because I would love to be able to integrate real time data into Maple.

I have seen applications in MATLAB where you can actually trade from inside MATLAB by connection MATLAB

to your online broker ie Interactive Brokers. This requires that charts etc are updated contineously with real time data.

At the moment I cant see how this would be possible in Maple 13...

I am using Maple 13.01 so it should work for me as well :-)

maybe I am doing something wrong ?!  The worksheet is ok it updates the mathcontainer

but the problem is that Maple is busy during the execution so this multithreading thing has

kind of lost is purpose because the same functionality in this case can be achived with a procedure.

The purpose was to update the mathcontainer while simultaniously being

able to do something ells ....hummm

I do appreciate your input and you taking the time to answer my question however

the worksheet does not solve my specified problem. I want the mathcontainer to be contineously

updated with one second interval from the moment I call:    thread_id := Threads:-Create(f())

Then I should be able to do whatever I want in Maple while the mathcontainer is updating it self

and then when I call :   thread_done := true    the updating should stop.

 

That is not taking place now. What is taking place now is this:

I make the call :    thread_id := Threads:-Create(f())

then nothing is happening in the mathcontainer and I can still work in Maple which is good

but then when I call:   thread_done := true    the mathcontainer suddenly starts to update itself

and Maple is locked because the procedure is busy.

 

I dont understand why all the output is printed all at once in the end when you call   thread_done := true

and not contineously with one second interval from the moment you call   thread_id := Threads:-Create(f())

to the moment when you exit :   thread_done := true

 

New comment:  I did however notice that when you call thread_id := Threads:-Create(f()) the MathContainer is

initially updated once but that is it. It does not matter how long you wait it is not updated anymore untill you call

thread_done := true   then all hell brakes loose ha ha

 

hummm I am not sure I am doing thing correctly.

 

"You can do whatever you like betwen the Threads:-Create() and Threads:-Wait(), and the thread will keep executing."

 

But how can I confirm that the loop is indeed running ?  I have no idea if the loop is working properly or not :-)

Cant I use a MathContainer to confirm that the loop indeed is running correctly?

for example like:   SetProperty( MathContainer13, value, L1, refresh=true );

so the mathcontainer is constantly updating when the loop is running in the background

 

The reason why I am asking is because I want to call a procedure every 10 seconds to get real time data

from yahoo finance displayed in a MathContainer.

 

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