Skip to content

This package offers both traditional benchmark and newly developed Online Portfolio Selection (OPS) algorithms implementation.

License

Notifications You must be signed in to change notification settings

shayandavoodii/OnlinePortfolioSelection.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation (Latest)
Continuous Integration
Coverage

  1. About
  2. Disclaimer
  3. Quick Start
  4. TODO LIST
  5. Contribution
  6. Motivation
  7. License
  8. Contact

About

This package presents a selection of proposed Online Portfolio Selection (OPS) algorithms found in the literature. The algorithms are implemented in Julia, ensuring complete type stability and suitability for research applications. It's an actively evolving package, with ongoing development work to introduce additional published methods. The aim is to introduce novel methods following the implementation of fundamental benchmark approaches. Presently, the package includes the following algorithms:

Note

In the following table, the abbreviations FL, FW, PM, and ML stand for Follow the Loser, Follow the Winner, Pattern-Matching, and Meta-Learning, respectively.

Algorithm Strategy Algorithm Strategy Algorithm Strategy
1 CORN PM 12 PAMR FL 23 TPPT Combination of Strategies
2 DRICORN-K PM 13 PPT FW 24 GWR FL
3 BCRP Benchmark (Market) 14 CWMR FL 25 ONS Benchmark (Market)
4 UP Benchmark (Market) 15 CAEG ML 26 DMR FL
5 EG FW 16 OLDEM PM 27 RMR FL
6 BS Benchmark (Market) 17 AICTR FW 28 SSPO FW
7 RPRT FL 18 EGM FW 29 WAEG ML
8 Anticor FL 19 OLMAR FL 30 MAEG ML
9 1/N Benchmark (Market) 20 Bᴷ PM 31 SPOLC FL
10 CW-OGD ML 21 LOAD Combination of Strategies 32 TCO FL
11 ClusLog PM 22 MRvol Combination of Strategies 33 KTPT PM
OPS algorithms have been evaluated using a set of promimnent metrics through the literature, such as the Annualized Sharpe Ratio, the Annualized Percentage Yield, and etc. The package also includes a set of utility functions to calculate these metrics to facilitate the evaluation process. The available metrics are as follows:
Row № Metric Abbreviation
1 Cumulative Wealth CW (Also known as $S_n$)
2 Mean Excess Return MER
3 Information Ratio IR
4 Annualized Percentage Yield APY
5 Annualized Standard Deviation $\sigma_p$
6 Annualized Sharpe Ratio SR
7 Maximum Drawdown MDD
8 Calmar Ratio CR
9 Average Turnover AT

Further information about the metrics can be found in the documentation.

🆙Table of contents

Disclaimer

This package is designed exclusively for research purposes and explicitly not for investment use. The author(s) hold no responsibility for any financial losses or damages incurred from using this package for investment or financial purposes.

🆙Table of contents


Quick Start

Installation

The most recent stable version of the package can be installed by entering the following command in the Julia REPL after typing ]:

pkg> add OnlinePortfolioSelection

or

julia> using Pkg; Pkg.add("OnlinePortfolioSelection")
Additionally, the development version of the package can be installed by executing the following command in the Julia REPL after entering ]:
pkg> dev OnlinePortfolioSelection

🆙Table of contents

Example

The full list of available strategies can be obtained by executing the following command after importing the package:
julia> using OnlinePortfolioSelection

julia> opsmethods()
In summary, all the implemented algorithms' names appear with lowercase letters. All of the strategies return an object of type OPSAlgorithm, which encompasses the following fields:
julia> fieldnames(OPSAlgorithm)
(:n_assets, :b, :alg)
  • n_assets: conveying the number of assets.
  • b: containing the corresponding weights of each asset in each investment period.
  • alg: representing the name of the algorithm that resulted in the output.

To obtain more information about a specific strategy, you can type ? in the REPL and then call the name of the strategy. For example, to access more details about the 'CORN-K' strategy, run the following command:

help?> cornk
Finally, to execute the 'CORN-K' strategy, use the following commands:
juila> using OnlinePortfolioSelection

# Generate a random price matrix. The rows are the assets, and the columns represent the time.
julia> adj_close_random = rand(10, 100);

# Set the parameters of the strategy
julia> hor = 10; # The investment horizon
julia> nexp = 5; # The number of experts
julia> ml_tw = 3; # The maximum length of the time windows to be examined
julia> ml_cor = 5; # The maximum number of correlation coefficients to be examined

# Run the algorithm
julia> m_cornk = cornk(adj_close_random, hor, nexp, ml_tw, ml_cor)
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

# Get weights
julia> m_cornk.b
10×10 Matrix{Float64}:
 0.088856    0.147974       0.00084875  0.223069
 0.0         0.0             0.00347507  0.0
 0.101514    0.000792416     0.00100889  0.0553558
 0.00913491  0.0805729       0.00100889  0.10233
 0.683795    0.0             0.31303     0.0
 0.00913491  0.0            0.0         0.0407096
 0.0350864   0.0208009       0.251554    0.239765
 0.0         0.219552        0.395477    0.0
 0.0232303   0.349871        0.0131345   0.163805
 0.0492489   0.180437        0.0204634   0.174965
For further details regarding the implemented strategies and the API, please refer to the documentation.

🆙Table of contents

Run from Python

The package can be used from Python by using the PyJulia package as follows:
$ pip install julia

And then run the following commands in Python:

>>> import julia
>>> julia.install()
...
Precompiling PyCall...
Precompiling PyCall... DONE
PyCall is installed and built successfully.
>>> from julia import Pkg
>>> Pkg.add("OnlinePortfolioSelection")
>>> from julia import OnlinePortfolioSelection as OPS

# Generate a random relatvive price matrix. The rows are the assets, and the columns represent the time.
>>> import numpy as np
>>> rel_pr = np.random.rand(3, 100)
>>> rel_vol = np.random.rand(3, 100)
>>> horizon = 10; Wₘᵢₙ = 4; Wₘₐₓ = 10; λ = 0.05; η = 0.01;
>>> model = OPS.mrvol(rel_pr, rel_vol, horizon, Wₘᵢₙ, Wₘₐₓ, λ, η)
>>> model.b
array([[0.33333333, 0.36104291, 0.3814967 , 0.26303273, 0.16525094,
        0.23471654, 0.28741473, 0.34746891, 0.41769629, 0.34582386],
       [0.33333333, 0.35745995, 0.24895616, 0.30306051, 0.36527706,
        0.2817696 , 0.36959982, 0.43371551, 0.48357232, 0.51374896],
       [0.33333333, 0.28149714, 0.36954713, 0.43390676, 0.469472  ,
        0.48351386, 0.34298546, 0.21881558, 0.09873139, 0.14042718]])
>>> type(model.b)
<class 'numpy.ndarray'>
>>> model.b.sum(axis=0)
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
>>> model.alg
'MRvol'
>>> model.n_assets
3
As you can see, the package can be used from Python easily. For more information, check the documentation.

🆙Table of contents


To-do list

  • Implement $B^{NN}$
  • Adopt hierarchical clustering for ClusLog algorithm
  • Implement CRP
  • Implement $B^H$
  • etc.

🆙Table of contents

Contribution

Contributions are warmly welcome. Please feel free to open an issue and discuss the changes you want to make. Afterward, fork the repo and make the changes. Then, open a pull request, and I will review and hopefully merge it.

🆙Table of contents

Motivation

I aimed to implement benchmark methods for Online Portfolio Selection (OPS) as part of my M.Sc. thesis to conduct comprehensive benchmarking experiments. The goal was to compare the performance of these benchmark methods with my proposed method from my thesis. I decided to transform this into an open-source package so that other researchers could leverage these established methods for their own research, sparing them the effort of reimplementing existing strategies. My intention is to continue developing and expanding this package to include more algorithms as I find it an exciting area of study. Ultimately, I hope this contribution proves beneficial to the research community.

🆙Table of contents

License

This project is licensed under the MIT License - see the LICENSE file for details.

🆙Table of contents

Contact

If you have any inquiries or suggestions, please don't hesitate to contact me via email at [email protected]. Alternatively, feel free to open an issue in the repository.

🆙Table of contents