WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
stats.h File Reference
#include <time.h>
#include "indicators.h"

Go to the source code of this file.

Data Structures

struct  WU_SharpeRatio
 Sharpe ratio is the relation between the risk-free rate discounted retuns and the volatility of an investment. More...
struct  WU_SortinoRatio
struct  WU_CalmarRatio
struct  WU_PortfolioStats
 WU_PortfolioStats tracks portfolio state, positions, and trading statistics. More...

Macros

#define wu_portfolio_stats_update(stats, cash, value, timestamp)
 Updates portfolio state in stats.
#define wu_portfolio_stats_record_trade(stats, pnl, reason)
 Records a trade in the stats.
#define wu_portfolio_stats_update_position(stats, idx, sym, qty, val, price)
 Updates position info for a specific asset.
#define wu_portfolio_stats_to_keyvalue(stats)
 Converts stats to key=value format string.
#define wu_portfolio_stats_to_json(stats, pretty)
 Converts stats to JSON format string.
#define wu_portfolio_stats_reset(stats)
#define wu_portfolio_stats_delete(stats)

Functions

WU_SharpeRatio wu_sharpe_ratio_new (double initial_value, double risk_free_rate)
 Creates a new Sharpe Ratio calculator.
WU_SortinoRatio wu_sortino_ratio_new (double initial_value, double risk_free_rate)
 Creates a new Sortino Ratio calculator.
WU_CalmarRatio wu_calmar_ratio_new (double initial_value)
WU_PortfolioStats wu_portfolio_stats_new (double initial_cash, double risk_free_rate)
 Creates a new WU_PortfolioStats instance.

Macro Definition Documentation

◆ wu_portfolio_stats_delete

#define wu_portfolio_stats_delete ( stats)
Value:
do { \
if ((stats) && (stats)->delete) \
(stats)->delete((stats)); \
} while(0)

Definition at line 170 of file stats.h.

◆ wu_portfolio_stats_record_trade

#define wu_portfolio_stats_record_trade ( stats,
pnl,
reason )
Value:
do { \
if ((stats)->record_trade) \
(stats)->record_trade((stats), (pnl), (reason)); \
} while(0)

Records a trade in the stats.

Definition at line 138 of file stats.h.

◆ wu_portfolio_stats_reset

#define wu_portfolio_stats_reset ( stats)
Value:
do { \
if ((stats)->reset) \
(stats)->reset((stats)); \
} while(0)

Definition at line 165 of file stats.h.

◆ wu_portfolio_stats_to_json

#define wu_portfolio_stats_to_json ( stats,
pretty )
Value:
((stats)->to_json ? (stats)->to_json((stats), (pretty)) : NULL)

Converts stats to JSON format string.

Caller must free the returned string.

Definition at line 162 of file stats.h.

◆ wu_portfolio_stats_to_keyvalue

#define wu_portfolio_stats_to_keyvalue ( stats)
Value:
((stats)->to_keyvalue ? (stats)->to_keyvalue((stats)) : NULL)

Converts stats to key=value format string.

Caller must free the returned string.

Definition at line 155 of file stats.h.

◆ wu_portfolio_stats_update

#define wu_portfolio_stats_update ( stats,
cash,
value,
timestamp )
Value:
do { \
if ((stats)->update) \
(stats)->update((stats), (cash), (value), (timestamp)); \
} while(0)
static double update(WU_EMA ema, double value)
Definition ema.c:4

Updates portfolio state in stats.

Definition at line 130 of file stats.h.

◆ wu_portfolio_stats_update_position

#define wu_portfolio_stats_update_position ( stats,
idx,
sym,
qty,
val,
price )
Value:
do { \
if ((stats)->update_position) \
(stats)->update_position((stats), (idx), (sym), (qty), (val), (price)); \
} while(0)

Updates position info for a specific asset.

Definition at line 146 of file stats.h.

Function Documentation

◆ wu_calmar_ratio_new()

WU_CalmarRatio wu_calmar_ratio_new ( double initial_value)

Definition at line 112 of file calmar.c.

◆ wu_portfolio_stats_new()

WU_PortfolioStats wu_portfolio_stats_new ( double initial_cash,
double risk_free_rate )

Creates a new WU_PortfolioStats instance.

Parameters
initial_cashInitial cash amount
risk_free_rateAnnual risk-free rate for Sharpe/Sortino calculations (e.g., 0.03 for 3%)

Definition at line 295 of file stats.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_sortino_ratio_new()

WU_SortinoRatio wu_sortino_ratio_new ( double initial_value,
double risk_free_rate )

Creates a new Sortino Ratio calculator.

Definition at line 105 of file sortino.c.