mapleFU commented on issue #38370:
URL: https://github.com/apache/arrow/issues/38370#issuecomment-1774061493
Would code like below helps?
```c++
arrow::Datum avg_return;
arrow::Datum avg_std;
double daily_sharpe_ratio;
// 创建 Arrow Double 标量
double days_of_year_double = 252.0;
double sqrt_year = std::sqrt(days_of_year_double);
ARROW_ASSIGN_OR_RAISE(avg_return, arrow::compute::CallFunction(
"mean", {fund_returns}));
arrow::compute::VarianceOptions variance_options;
variance_options.ddof = 1;
ARROW_ASSIGN_OR_RAISE(avg_std, arrow::compute::CallFunction(
"stddev",
{fund_returns},&variance_options));
daily_sharpe_ratio = avg_return.scalar_as<::arrow::DoubleScalar>().value /
avg_std.scalar_as<::arrow::DoubleScalar>().value;
std::cout << "计算得到的夏普率为 : " << daily_sharpe_ratio / sqrt_year << std::endl;
auto end_time = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
std::cout << "c++读取数据,然后计算夏普率一共耗费时间为: " << duration.count()/1000.0 << "
ms" << std::endl;
return arrow::Status::OK();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]