|
WU Trading Library 0.2.0
A backtesting and trading strategy library
|
Go to the source code of this file.
Data Structures | |
| struct | WU_Portfolio |
| Base for a portfolio, which defines the minimal interface for updating the portfolio with signals, calculating the current value of the portfolio, and calculating the profit and loss (PnL), as well as a method to free the portfolio's resources. More... | |
| struct | WU_ExecutionPolicy |
| struct | WU_BorrowParams |
| struct | WU_PortfolioParams |
| The parameters to define a portfolio. More... | |
| struct | WU_BasicPortfolio |
| A basic portfolio implementation that supports multiple assets. More... | |
Macros | |
| #define | wu_portfolio_update(portfolio, signals) |
| The update macro allows you to update the portfolio with new signals. | |
| #define | wu_portfolio_value(portfolio) |
| Calculates the current value of the portfolio. | |
| #define | wu_portfolio_pnl(portfolio) |
| Calculates the profit and loss (PnL) of the portfolio. | |
| #define | wu_portfolio_delete(portfolio) |
| Frees the resources associated with the portfolio. | |
| #define | WU_PORTFOLIO(portfolio) |
| Casting macro for the base portfolio type. | |
Functions | |
| WU_PortfolioParams | wu_portfolio_params_default (void) |
| Returns default portfolio parameters with reasonable values. | |
| WU_BasicPortfolio | wu_basic_portfolio_new (WU_PortfolioParams params, const char *symbols[]) |
| Creates a new basic portfolio instance with the specified parameters and asset symbols. | |
| double | wu_basic_portfolio_asset_value (WU_BasicPortfolio portfolio, int asset_index) |
| Get current value of a specific asset's positions. | |
| double | wu_basic_portfolio_asset_quantity (WU_BasicPortfolio portfolio, int asset_index) |
| Get total quantity held for a specific asset. | |
| #define WU_PORTFOLIO | ( | portfolio | ) |
Casting macro for the base portfolio type.
Definition at line 157 of file portfolios.h.
| #define wu_portfolio_delete | ( | portfolio | ) |
Frees the resources associated with the portfolio.
Usually this macro is called by the runner when it takes ownership of the portfolio.
Definition at line 52 of file portfolios.h.
| #define wu_portfolio_pnl | ( | portfolio | ) |
Calculates the profit and loss (PnL) of the portfolio.
This is typically calculated as the difference between the current value of the portfolio and the initial cash invested, minus any transaction costs or fees.
Definition at line 45 of file portfolios.h.
| #define wu_portfolio_update | ( | portfolio, | |
| signals ) |
The update macro allows you to update the portfolio with new signals.
Definition at line 28 of file portfolios.h.
| #define wu_portfolio_value | ( | portfolio | ) |
Calculates the current value of the portfolio.
This includes the value of all positions plus any remaining cash.
Definition at line 37 of file portfolios.h.
| enum WU_Direction |
| Enumerator | |
|---|---|
| WU_DIRECTION_LONG | |
| WU_DIRECTION_SHORT | |
| WU_DIRECTION_BOTH | |
Definition at line 57 of file portfolios.h.
| Enumerator | |
|---|---|
| WU_EXECUTION_POLICY_IMMEDIATE | |
| WU_EXECUTION_POLICY_NEXT_CLOSE | |
| WU_EXECUTION_POLICY_FIXED_SLIPPAGE | |
| WU_EXECUTION_POLICY_RANDOM_SLIPPAGE | |
Definition at line 63 of file portfolios.h.
| Enumerator | |
|---|---|
| WU_TRANSACTION_COST_FIXED | |
| WU_TRANSACTION_COST_PROPORTIONAL | |
Definition at line 70 of file portfolios.h.
| double wu_basic_portfolio_asset_quantity | ( | WU_BasicPortfolio | portfolio, |
| int | asset_index ) |
| double wu_basic_portfolio_asset_value | ( | WU_BasicPortfolio | portfolio, |
| int | asset_index ) |
| WU_BasicPortfolio wu_basic_portfolio_new | ( | WU_PortfolioParams | params, |
| const char * | symbols[] ) |
Creates a new basic portfolio instance with the specified parameters and asset symbols.
The array symbols should be created using the wu_symbol_list macro, which ensures it is null-terminated.
Creates a new basic portfolio instance with the specified parameters and asset symbols.
It takes in the portfolio parameters and an array of asset symbols, and initializes the portfolio's internal state accordingly. Memory is dynamically allocated for the portfolio structure and the position vectors for each asset. The function also sets up the function pointers for the portfolio operations (update, value, pnl, delete) and initializes the cash balance and trading statistics. If any memory allocation fails, it ensures that all previously allocated resources are freed to prevent memory leaks.
| WU_PortfolioParams wu_portfolio_params_default | ( | void | ) |
Returns default portfolio parameters with reasonable values.
Returns default portfolio parameters with reasonable values.
The portfolio can process buy and sell signals, manage positions for each asset, and calculate the total value and profit/loss (PnL) of the portfolio. It also includes features such as transaction costs, slippage, stop-loss, and take-profit mechanisms. Returns default portfolio parameters with reasonable values.