From 4b7a2ca365e9d37fd21584c927ea19a643ecbbe2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:16:20 -1100 Subject: [PATCH] First version correlator --- src/komodo_gateway.h | 44 +++++++++++++++++++++++++++++++----------- src/rpc/blockchain.cpp | 4 +++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1f1ce8dc6..b59a6fbf1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2232,17 +2232,39 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) return(correlated[0]); } -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i; int64_t price,sum = 0; - for (i=0; i= daywindow ) + i = 0; + if ( (price= rawprices[i]) == 0 ) + return(-1); + if ( price >= lowprice && price <= highprice ) + { + sum += price; + correlation++; + if ( correlation > (daywindow>>1) ) + { + fprintf(stderr,"iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + return(sum / correlation) + } + } + } } - //fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); - return(sum / numprices); + return(0); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 668081934..c68d4b14b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1238,7 +1238,8 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i