Smooth coifs
This commit is contained in:
@@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int
|
||||
if ( (price= nonzprices[i]) != 0 )
|
||||
{
|
||||
den += (daywindow - i);
|
||||
sum += ((daywindow - i) * (price + firstprice*9)) / 10;
|
||||
sum += ((daywindow - i) * (price + firstprice*2)) / 3;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@@ -2334,11 +2334,17 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int
|
||||
}
|
||||
|
||||
|
||||
int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices)
|
||||
int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth)
|
||||
{
|
||||
int32_t i; int64_t sum,den,smoothed=0,firstprice = correlated[0];
|
||||
const int64_t coeffs[7] = { 7, 13, 5, 4, 6, 7, 3 };
|
||||
int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0];
|
||||
if ( daywindow < 2 )
|
||||
return(0);
|
||||
if ( sizeof(smoothed)/sizeof(*smoothed) )
|
||||
{
|
||||
fprintf(stderr,"smoothwidth %d != %d\n",smoothwidth,(int32_t)(sizeof(smoothed)/sizeof(*smoothed)));
|
||||
return(0);
|
||||
}
|
||||
memset(nonzprices,0,sizeof(*nonzprices)*daywindow);
|
||||
for (i=1; i<daywindow; i++)
|
||||
{
|
||||
@@ -2358,14 +2364,26 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz
|
||||
correlated[i] = firstprice;
|
||||
else break;
|
||||
}
|
||||
sum = den = 0;
|
||||
for (i=0; i<daywindow; i++)
|
||||
for (iter=0; iter<smoothwidth; iter++)
|
||||
{
|
||||
sum += ((daywindow - i) * (correlated[i] + firstprice*9))/10;
|
||||
den += (daywindow - i);
|
||||
sum = den = 0;
|
||||
for (i=0; i<daywindow; i++)
|
||||
{
|
||||
sum += ((daywindow - i) * (correlated[i+iter] + firstprice*9))/10;
|
||||
den += (daywindow - i);
|
||||
}
|
||||
smoothed[iter] = (sum / den);
|
||||
}
|
||||
smoothed = (sum / den);
|
||||
smoothedsum = smoothedden = 0;
|
||||
for (i=0; i<7; i++)
|
||||
{
|
||||
fprintf(stderr,"%.4f ",(double)smoothed[i]/10000);
|
||||
smoothedsum += coeffs[i] * smoothed[i];
|
||||
smoothedden += coeffs[i];
|
||||
}
|
||||
fprintf(stderr,"-> %.4f\n",(double)(smoothedsum/smoothedden)/10000);
|
||||
return(smoothedsum/smoothedden);
|
||||
}
|
||||
return(smoothed);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1183,6 +1183,7 @@ uint32_t komodo_heightstamp(int32_t height);
|
||||
|
||||
UniValue prices(const UniValue& params, bool fHelp)
|
||||
{
|
||||
int32_t smoothwidth = 7;
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("prices maxsamples\n");
|
||||
LOCK(cs_main);
|
||||
@@ -1197,7 +1198,7 @@ UniValue prices(const UniValue& params, bool fHelp)
|
||||
UniValue a(UniValue::VARR);
|
||||
if ( daywindow < 7 )
|
||||
daywindow = 7;
|
||||
width = maxsamples+2*daywindow;
|
||||
width = maxsamples+2*daywindow+smoothwidth;
|
||||
numpricefeeds = komodo_heightpricebits(&seed,rawprices,nextheight-1);
|
||||
if ( numpricefeeds <= 0 )
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds");
|
||||
@@ -1205,7 +1206,7 @@ UniValue prices(const UniValue& params, bool fHelp)
|
||||
correlated = (int64_t *)calloc(sizeof(*correlated),width);
|
||||
correlated2 = (int64_t *)calloc(sizeof(*correlated2),width);
|
||||
prices2 = (uint32_t *)calloc(sizeof(*prices2),width);
|
||||
for (ht=nextheight-1,i=0; i<width&&ht>2*daywindow+2; i++,ht--)
|
||||
for (ht=nextheight-1,i=0; i<width&&ht>2*daywindow+2+smoothwidth; i++,ht--)
|
||||
{
|
||||
if ( ht < 0 || ht > chainActive.Height() )
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
@@ -1238,17 +1239,17 @@ UniValue prices(const UniValue& params, bool fHelp)
|
||||
if ( (str= komodo_pricename(name,j)) != 0 )
|
||||
{
|
||||
item.push_back(Pair("name",str));
|
||||
for (i=0; i<maxsamples+daywindow; i++)
|
||||
for (i=0; i<maxsamples+daywindow+smoothwidth; i++)
|
||||
{
|
||||
offset = j*width + i;
|
||||
rngval = (rngval*11109 + 13849);
|
||||
if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow,prices2)) < 0 )
|
||||
if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow+smoothwidth,prices2)) < 0 )
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price");
|
||||
}
|
||||
for (i=0; i<maxsamples; i++)
|
||||
{
|
||||
offset = j*width + i;
|
||||
smoothed = komodo_pricesmoothed(&correlated[i],daywindow,correlated2);
|
||||
smoothed = komodo_pricesmoothed(&correlated[i],daywindow,correlated2,smoothwidth);
|
||||
UniValue parr(UniValue::VARR);
|
||||
parr.push_back(ValueFromAmount((int64_t)prices[offset] * (j<36?10000:1)));
|
||||
parr.push_back(ValueFromAmount(correlated[i]));
|
||||
|
||||
Reference in New Issue
Block a user