【PercentRank】
[code]inputs:PriceValueToRank( numericsimple ),
PriceValue( numericseries ),
Len( numericsimple ) ;
variables:
var0( 0 ),
var1( 0 ),
var2( 0 ),
var3( 0 ) ;
arrays:
arr0[1000]( 0 ) ;
condition1 = Len > 1
and PriceValueToRank >= Lowest( PriceValue, Len )
and PriceValueToRank <= Highest( PriceValue, Len ) ;
if condition1
then
begin
for Value1 = 1 to Len
begin
arr0[Value1] = PriceValue[ Value1 - 1 ] ;
end ;
Value1 = SortArray( arr0, Len, -1 ) ;
var0 = 1 / ( Len - 1 ) ;
var1 = 0 ;
for Value2 = 1 to Len
begin
if arr0[Value2] = PriceValueToRank then
begin
PercentRank = var0 * ( Value2 - 1 ) ;
var1 = 1 ;
Value2 = Len ;
end ;
end ;
if var1 = 0 then
begin
for Value3 = 1 to Len - 1
begin
var2 = arr0[Value3] ;
var3 = arr0[ Value3 + 1 ] ;
condition1 = PriceValueToRank > var2 and PriceValueToRank < var3 ;
if condition1 then
begin
PercentRank = var0 * ( ( Value3 - 1 ) + ( PriceValueToRank -
var2 ) / ( var3 - var2 ) ) ;
Value3 = Len - 1 ;
end ;
end ;
end ;
end
else
PercentRank = -1 ;
[/code]
页:
[1]