|
|
calculating returns
Hi all
I want to calculate squared returns from data using a formular similar to
squaredreturn=(log(lastprice(k)-lastprice(k-1)))^2
but obviously there is a problem since there is no data for lastprice(0).
In addition i am already in a for k=1 loop, so i cannot simply start the loop from k>=2
Can any1 offer any suggestions
Many thanks
|
|
0
|
|
|
|
Reply
|
Peter
|
8/2/2010 11:28:04 PM |
|
On Aug 3, 11:28=A0am, "Peter Smith" <fe0...@mail.wbs.ac.uk> wrote:
> Hi all
>
> I want to calculate squared returns from data using a formular similar to
>
> squaredreturn=3D(log(lastprice(k)-lastprice(k-1)))^2
>
> but obviously there is a problem since there is no data for lastprice(0).
> In addition i am already in a for k=3D1 loop, so i cannot simply start th=
e loop from k>=3D2
>
> Can any1 offer any suggestions
> Many thanks
Well, your squaredreturn means nothing at k=3D1, so you're better to set
it to NaN.
But don't do it in the loop:
squaredreturn=3D(log(lastprice(2:end)-lastprice(1:end-1))).^2;
squaredreturn=3D[NaN;squaredreturn];
Note the dot before the ^. This is essential.
|
|
0
|
|
|
|
Reply
|
mulgor (2841)
|
8/2/2010 11:33:45 PM
|
|
Also please note i cannot use ln(lastprice(k+1)-lastprice(k)) as eventually it reaches a point where there is no k+1
|
|
0
|
|
|
|
Reply
|
Peter
|
8/2/2010 11:35:24 PM
|
|
TideMan <mulgor@gmail.com> wrote in message <c5309e34-e2ed-4e85-8d7a-2e418c8d0a1a@x20g2000pro.googlegroups.com>...
> On Aug 3, 11:28 am, "Peter Smith" <fe0...@mail.wbs.ac.uk> wrote:
> > Hi all
> >
> > I want to calculate squared returns from data using a formular similar to
> >
> > squaredreturn=(log(lastprice(k)-lastprice(k-1)))^2
> >
> > but obviously there is a problem since there is no data for lastprice(0).
> > In addition i am already in a for k=1 loop, so i cannot simply start the loop from k>=2
> >
> > Can any1 offer any suggestions
> > Many thanks
>
> Well, your squaredreturn means nothing at k=1, so you're better to set
> it to NaN.
>
> But don't do it in the loop:
> squaredreturn=(log(lastprice(2:end)-lastprice(1:end-1))).^2;
% You can also use the built-in MATLAB function DIFF
% which will do exactly the same thing:
squaredreturn=(log(diff(lastprice))).^2;
% Slightly slower perhaps, but somewhat simplier?
> squaredreturn=[NaN;squaredreturn];
>
> Note the dot before the ^. This is essential.
|
|
0
|
|
|
|
Reply
|
someone
|
8/3/2010 12:55:06 AM
|
|
Dear Peter,
> Also please note i cannot use ln(lastprice(k+1)-lastprice(k)) as eventually it reaches a point where there is no k+1
What about the trivial solution:
n = length(lastprice);
for k = 1:n
if k < n
x = ln(lastprice(k+1) - lastprice(k));
end
end
If a certain line should not be caclulated in the loop for a certain counter value, simply omit the calculation for this certain counter value.
Kind regards, Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
8/3/2010 11:01:04 AM
|
|
|
4 Replies
241 Views
(page loaded in 0.162 seconds)
Similiar Articles: return level plot - comp.soft-sys.matlabcalculating returns - comp.soft-sys.matlab Hi all I want to calculate squared returns from data using a formular similar to ... return level plot - comp.soft-sys.matlab ... Calculating member offset at runtime - comp.lang.c++.moderated ...calculating returns - comp.soft-sys.matlab Calculating member offset at runtime - comp.lang.c++.moderated ... How to calculate effective/average paged memory access time ... Calculate Settling Time of a Transfer Function - comp.dsp ...I want to be able to calculate the settling time that Matlab returns for a step response (assuming that is the correct settling time value). I have not been able to ... Calculation and verification of IBAN checksums - comp.lang.awk ...Here's some awk code to verify IBANs and calculate the IBAN checksums, in case ... calculating returns - comp.soft-sys.matlab Calculation and verification of IBAN checksums ... Calculating mean values from data with NaN`s - comp.soft-sys ...calculating returns - comp.soft-sys.matlab Calculating mean values from data with NaN`s - comp.soft-sys ... calculating returns - comp.soft-sys.matlab Calculating mean ... Age range calculation problem - comp.databases.filemaker ...calculating returns - comp.soft-sys.matlab Age range calculation problem - comp.databases.filemaker ... calculating returns - comp.soft-sys.matlab Age range calculation ... Calculating the 1st Wednesday of each month - comp.databases ...Date( Month(d_Date1) , 1 , Year(d_Date1) ) + Choose( DayofWeek( Date( Month(d_Date1) , 1 , Year(d_Date1) ) )-1, 3,2,1,0,6,5,4 ) ....should return the first Wednesday ... How to calculate effective demand-paged memory access tmie - comp ...calculating returns - comp.soft-sys.matlab How to calculate effective demand-paged memory access tmie - comp ... How to calculate effective demand-paged memory access tmie ... Calculating length of a wire product - comp.cad.pro-engineer ...Take a U-shaped wire, bent from 10 mm O.D. stainless steel. You model it as a swept extrusion or a pipe (solid) and when finished, you calculate the... Serialization in Matlab - comp.soft-sys.matlabcalculating returns - comp.soft-sys.matlab Serialization in Matlab - comp.soft-sys.matlab The problem: I want to mark certain members of a class/struct for network ... How to Calculate a Return on an Investment | eHow.comA Return on Investment (ROI) is calculated to measure the performance of one investment relative to another. ROI is expressed as a percentage and is based on returns ... Calculate Return - How To Information | eHow.comDon't just sit there scratching your head, find useful info on Calculate Return on eHow. Get essential tips and learn more about everything from How to Measure Output ... 7/30/2012 4:22:13 AM
|
|
|
|
|
|
|
|
|