0
Rとcppで非常に新しいです。これらはRcppを使った私のcppコードです。'['トークンの前にテンプレート引数がありません
#include <cmath>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector getPerformance(NumericVector accProfitSeries, NumericVector dateSeries, double capital, double riskFreeRate)
{
NumericVector retult(8);
int Length = accProfitSeries.length();
double strategyProfit = accProfitSeries[Length - 1];
double returnRate = log(strategyProfit/capital);
double tradingPeriod = (dateSeries[dateSeries.length() - 1] - dateSeries[0])/365;
double returnRateYear = returnRate/tradingPeriod;
double sharpeRatio;
for (int i = 0; i < 8; i++) {
result[i] = 0;
}
NumericVector capitalLevel(Length), capitalReturn(Length);
double meanReturn, sumReturn, stdReturn;
double tmp;
for (int i = 0; i < Length; i++)
{
capitalLevel[i] = accProfitSeries[i] + capital;
capitalReturn[i] = log(capitalReturn[i]/capitalReturn[0]);
sumReturn = sumReturn + capitalReturn[i];
}
meanReturn = sumReturn/Length;
for (int i = 0; i < Length; i++)
tmp += pow(capitalReturn[i] - meanReturn, 2);
stdReturn = sqrt(tmp/Length);
sharpeRatio = (meanReturn - riskFreeRate)/stdReturn;
double maxCapital = 0, drawback = 0, maxDrawback = 0, maxDrawbackPercent = 0;
int drawbackPeriod = 0, maxDrawbackPeriod = 0;
for (int i = 0; i < Length; i++)
{
maxCapital = max(NumericVector::create(maxCapital, capitalLevel[i]));
drawback = capitalLevel[i] - maxCapital;
maxDrawback = min(NumericVector::create(maxDrawback, drawback));
maxDrawbackPercent = maxDrawback/(maxCapital - capital);
if (drawback >= 0)
{
drawbackPeriod = 0;
}
else
{
drawbackPeriod++;
maxDrawbackPeriod = max(NumericVector::create(maxDrawbackPeriod, drawbackPeriod));
}
}
result[0] = returnRate;
result[1] = tradingPeriod;
result[2] = returnRateYear;
result[3] = sharpeRatio;
result[4] = maxDrawback;
result[5] = maxDrawbackPeriod;
result[6] = strategyProfit;
result[7] = maxDrawbackPercent;
return(result);
}
私は、エラーメッセージの1つを得た、他の人が似ています
getPerformance.cpp:9:17エラー:不足しているテンプレート引数 '[' トークン 結果の前に[I] = 0;
どうすれば解決できますか?
スタート: 'NumericVectorのretultは(8);'あなたは ''結果(8)をしたいです。 –