WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
positions.h
Go to the documentation of this file.
1#ifndef _POSITIONS_H
2#define _POSITIONS_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include "types.h"
7
8#define WU_SYMBOL_MAX_LEN 32
9
10/**
11 * WU_Position represents an open position in the portfolio.
12 */
13typedef struct WU_Position_ {
15 double quantity;
16 double price;
17 bool active;
18}* WU_Position;
19
20/**
21 * WU_PositionVector is a data structure that holds multiple positions
22 * for a single asset. It includes the asset symbol and last price.
23 */
24typedef struct WU_PositionVector {
25 void (*add)(struct WU_PositionVector* vec, WU_Position pos);
26 void (*remove)(struct WU_PositionVector* vec, int index);
27 void (*clear)(struct WU_PositionVector* vec);
28 struct WU_Position_ (*get)(struct WU_PositionVector* vec, int index,
29 bool* found);
30 double (*total_quantity)(struct WU_PositionVector* vec);
31 void (*delete)(struct WU_PositionVector* vec);
32 char* symbol;
33 double last_price;
35 bool* active;
36 int count;
39
40#define wu_position_add(vec, pos) ((vec)->add((vec), (pos)))
41#define wu_position_remove(vec, index) ((vec)->remove((vec), (index)))
42#define wu_position_clear(vec) ((vec)->clear((vec)))
43#define wu_position_get(vec, index, found) ((vec)->get((vec), (index), (found)))
44#define wu_position_total_quantity(vec) ((vec)->total_quantity((vec)))
45#define wu_position_vector_delete(vec) do { \
46 if ((vec)->delete) \
47 (vec)->delete((WU_PositionVector*)(vec)); \
48} while(0)
49
50WU_PositionVector* wu_position_vector_new(const char* symbol);
51
52/**
53 * WU_PositionSizeType represents the type of position sizing used in the
54 * portfolio. It can be an absolute quantity, a percentage of the
55 * portfolio value, an equal percentage across all assets, or a
56 * strategy-guided position sizing where the strategy determines the
57 * size of the position based on its own logic.
58 */
65
66/**
67 * Position sizing policy. Defines how to determine the size of each
68 * trade based on the signal and the portfolio's current state.
69 */
74
75#endif // _POSITIONS_H
WU_PositionVector * wu_position_vector_new(const char *symbol)
WU_PositionSizeType
WU_PositionSizeType represents the type of position sizing used in the portfolio.
Definition positions.h:59
@ WU_POSITION_SIZE_PCT_EQUAL
Definition positions.h:62
@ WU_POSITION_SIZE_STRATEGY_GUIDED
Definition positions.h:63
@ WU_POSITION_SIZE_ABS
Definition positions.h:60
@ WU_POSITION_SIZE_PCT
Definition positions.h:61
Position sizing policy.
Definition positions.h:70
WU_PositionSizeType size_type
Definition positions.h:71
WU_PositionVector is a data structure that holds multiple positions for a single asset.
Definition positions.h:24
struct WU_Position_(* get)(struct WU_PositionVector *vec, int index, bool *found)
Definition positions.h:28
void(* remove)(struct WU_PositionVector *vec, int index)
Definition positions.h:26
struct WU_Position_ * positions
Definition positions.h:34
void(* clear)(struct WU_PositionVector *vec)
Definition positions.h:27
double(* total_quantity)(struct WU_PositionVector *vec)
Definition positions.h:30
void(* add)(struct WU_PositionVector *vec, WU_Position pos)
Definition positions.h:25
WU_Position represents an open position in the portfolio.
Definition positions.h:13
double quantity
Definition positions.h:15
WU_TimeStamp timestamp
Definition positions.h:14
double price
Definition positions.h:16
A timestamp represent a mark in time given relative to unix epoch.
Definition timeutils.h:21