25#define CALMAR_MIN_OBSERVATIONS 30
36 if (!self)
return NAN;
41 if (self->count == 0) {
42 self->prev_value = portfolio_value;
50 self->prev_value = portfolio_value;
54 if (self->max_drawdown) {
63 if (self->initial_value == 0.0) {
70 if (isnan(mdd) || mdd >= 0.0) {
77 double periods_elapsed = self->end_time - self->start_time;
79 if (periods_elapsed <= 0) {
84 double periods_per_year = (annualization_factor * self->count)
86 if (periods_per_year <= 0) {
92 double total_return = (portfolio_value - self->initial_value)
93 / self->initial_value;
95 double annualized_return = total_return * periods_per_year;
97 self->value = annualized_return / fabs(mdd);
106 if (self->max_drawdown) {
114 if (!cr)
return NULL;
116 if (!cr->max_drawdown) {
117 fprintf(stderr,
"Calmar Ratio Error: max_drawdown object creation failed\n");
121 cr->initial_value = initial_value;
123 cr->prev_value = initial_value;
WU_CalmarRatio wu_calmar_ratio_new(double initial_value)
static void wu_calmar_ratio_free(WU_CalmarRatio self)
Frees resources allocated by the Calmar Ratio object.
static double wu_calmar_ratio_update(WU_CalmarRatio self, WU_PerformanceUpdate perf)
Updates the Calmar Ratio calculation with a new portfolio value.
#define CALMAR_MIN_OBSERVATIONS
The Calmar Ratio measures risk-adjusted return by comparing annualized returns to the maximum drawdow...
#define wu_indicator_get(indicator)
Get the current value of the indicator.
#define wu_indicator_delete(indicator)
Delete the indicator and free any resources allocated by it.
#define wu_indicator_update(indicator, value)
Header file for technical indicators.
WU_MaxDrawdown wu_max_drawdown_new(void)
Creates a new WU_MaxDrawdown indicator.
double wu_annualization_factor(WU_TimeUnit unit)
Returns the number of units (seconds, millis, micros, or nanos) contained in a year.