WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
sharpe.c File Reference
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "wu.h"

Go to the source code of this file.

Macros

#define SHARPE_MIN_OBSERVATIONS   30
 The Sharpe Ratio measures risk-adjusted return by comparing excess return (over risk-free rate) to total volatility (standard deviation).

Functions

static double wu_sharpe_ratio_update (WU_SharpeRatio self, WU_PerformanceUpdate perf)
 Updates the Sharpe Ratio calculation with a new portfolio value.
static void wu_sharpe_ratio_free (WU_SharpeRatio self)
 Frees resources allocated by the Sharpe Ratio object.
WU_SharpeRatio wu_sharpe_ratio_new (double initial_value, double risk_free_rate)
 Creates a new Sharpe Ratio calculator.

Macro Definition Documentation

◆ SHARPE_MIN_OBSERVATIONS

#define SHARPE_MIN_OBSERVATIONS   30

The Sharpe Ratio measures risk-adjusted return by comparing excess return (over risk-free rate) to total volatility (standard deviation).

Formula: Sharpe = (R_p - R_f) / σ_p where:

R_p = mean portfolio return (annualized) R_f = risk-free rate (annualized) σ_p = portfolio standard deviation (annualized) Minimum number of observations required for statistically meaningful Sharpe ratio calculation. Below this threshold, the ratio is unreliable.

Definition at line 22 of file sharpe.c.

Function Documentation

◆ wu_sharpe_ratio_free()

void wu_sharpe_ratio_free ( WU_SharpeRatio self)
static

Frees resources allocated by the Sharpe Ratio object.

Definition at line 96 of file sharpe.c.

◆ wu_sharpe_ratio_new()

WU_SharpeRatio wu_sharpe_ratio_new ( double initial_value,
double risk_free_rate )

Creates a new Sharpe Ratio calculator.

Definition at line 106 of file sharpe.c.

◆ wu_sharpe_ratio_update()

double wu_sharpe_ratio_update ( WU_SharpeRatio self,
WU_PerformanceUpdate perf )
static

Updates the Sharpe Ratio calculation with a new portfolio value.

Parameters
selfThe Sharpe Ratio object
perfPerformance update containing portfolio value and timestamp
Returns
The updated Sharpe Ratio value, or NAN if insufficient data

Definition at line 31 of file sharpe.c.