src/assetallocation.cpp
// calculate annual interest on an asset allocation
calculate annual interest on an asset allocation
calculate annual interest on an asset allocation
CAmount GetAssetAllocationInterest(CAssetAllocation & assetAllocation, const int& nHeight, string& errorMessage) {
	if (!AccumulateInterestSinceLastClaim(assetAllocation, nHeight)) {
		errorMessage = _("Not enough blocks in-between interest claims");
		return 0;
	}
	const int &nInterestClaimBlockThreshold = fUnitTest ? 1 : ONE_MONTH_IN_BLOCKS;
	if ((nHeight - assetAllocation.nLastInterestClaimHeight) < nInterestClaimBlockThreshold || assetAllocation.nLastInterestClaimHeight == 0) {
		errorMessage = _("Not enough blocks have passed since the last claim, please wait some more time...");
		return 0;
	}
	const cpp_dec_float_50 &nInterestBlockTerm = fUnitTest ? cpp_dec_float_50(ONE_HOUR_IN_BLOCKS) : cpp_dec_float_50(ONE_YEAR_IN_BLOCKS);
	const cpp_dec_float_50 &nBlockDifference = cpp_dec_float_50(nHeight - assetAllocation.nLastInterestClaimHeight);
	const cpp_dec_float_50& nBalanceOverTimeDifference = cpp_dec_float_50(assetAllocation.nAccumulatedBalanceSinceLastInterestClaim / nBlockDifference);
	const cpp_dec_float_50& fInterestOverTimeDifference = cpp_dec_float_50(assetAllocation.fAccumulatedInterestSinceLastInterestClaim / nBlockDifference);
	const cpp_dec_float_50& nInterestPerBlock = fInterestOverTimeDifference / nInterestBlockTerm;
	const cpp_dec_float_50& powcalc = (boost::multiprecision::pow(cpp_dec_float_50(1.0) + nInterestPerBlock, nBlockDifference)*nBalanceOverTimeDifference) - nBalanceOverTimeDifference;
	return powcalc.convert_to<CAmount>();
}
CAmount GetAssetAllocationInterest ( CAssetAllocation & assetAllocation , const int & nHeight , string & errorMessage ) { if ( ! AccumulateInterestSinceLastClaim ( assetAllocation , nHeight ) ) { errorMessage = _ ( " " ) ; return 0 ; } const int & nInterestClaimBlockThreshold = fUnitTest ? 1 : ONE_MONTH_IN_BLOCKS ; if ( ( nHeight - assetAllocation . nLastInterestClaimHeight ) < nInterestClaimBlockThreshold || assetAllocation . nLastInterestClaimHeight == 0 ) { errorMessage = _ ( " " ) ; return 0 ; } const cpp_dec_float_50 & nInterestBlockTerm = fUnitTest ? cpp_dec_float_50 ( ONE_HOUR_IN_BLOCKS ) : cpp_dec_float_50 ( ONE_YEAR_IN_BLOCKS ) ; const cpp_dec_float_50 & nBlockDifference = cpp_dec_float_50 ( nHeight - assetAllocation . nLastInterestClaimHeight ) ; const cpp_dec_float_50 & nBalanceOverTimeDifference = cpp_dec_float_50 ( assetAllocation . nAccumulatedBalanceSinceLastInterestClaim / nBlockDifference ) ; const cpp_dec_float_50 & fInterestOverTimeDifference = cpp_dec_float_50 ( assetAllocation . fAccumulatedInterestSinceLastInterestClaim / nBlockDifference ) ; const cpp_dec_float_50 & nInterestPerBlock = fInterestOverTimeDifference / nInterestBlockTerm ; const cpp_dec_float_50 & powcalc = ( boost :: multiprecision :: pow ( cpp_dec_float_50 ( 1.0 ) + nInterestPerBlock , nBlockDifference ) * nBalanceOverTimeDifference ) - nBalanceOverTimeDifference ; return powcalc . convert_to < CAmount > ( ) ; }
calculate annual interest on an asset allocation
calculate annual interest on an asset allocation
// need to do one more average balance calculation since the last update to this asset allocation // apply compound annual interest to get total interest since last time interest was collected