From 05bd8d8af63d51ea3ba11f4c7816f48b97f7bd7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:16:03 -1100 Subject: [PATCH] Smooth coifs --- src/komodo_gateway.h | 36 +++++++++++++++++++++++++++--------- src/rpc/blockchain.cpp | 11 ++++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 78d320c91..afa3b40c1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -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 %.4f\n",(double)(smoothedsum/smoothedden)/10000); + return(smoothedsum/smoothedden); } - return(smoothed); + return(0); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0080c9b2c..520307c4b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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; i2*daywindow+2; i++,ht--) + for (ht=nextheight-1,i=0; i2*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