fmilthaler / FinQuant

A program for financial portfolio management, analysis and optimisation.
MIT License
1.34k stars 190 forks source link

Benchmarking Performance #133

Closed wasimnoordin closed 11 months ago

wasimnoordin commented 11 months ago

Hi @fmilthaler and @PietropaoloFrisoni

Is there a way to compare the effectiveness of this program to a benchmarked or baseline run?

What I mean to say is, how can we see or quantify how well FinQuant is performing against no optimisation / a random-search optimisation? Currently, I'm not sure if there's such a way to evaluate how "well" the program is working, if you understand me correctly.

Thanks and I've been having a blast learning from FinQuant!

wasimnoordin commented 11 months ago

Any ideas on how finquant can be evaluated?

PietropaoloFrisoni commented 11 months ago

Hi @wasimnoordin , Thank you for your question, and sorry for not getting back to you sooner (although it is August, it is quite a busy period : )).

Currently, FinQuant implements some standard Quantitative Finance recipes for a financial portfolio, such as calculating the Sharpe Ratio, expected return, etc. These are based on simple mathematical models such as the Markowitz portfolio theory. While I'm not an economist, these are now part of the standard training of any financial student and quantitative analyst (It goes without saying that these are only models and, therefore, should be considered as such).

What do you mean by "evaluate how "well" the program is working"?

Are you referring to comparing the computation's efficiency (memory usage, run time, etc.) against alternative libraries that implement identical calculations based on the same models? Or would you like to test the effectiveness of the models on which the calculations are based?

Thank you, All the best.

wasimnoordin commented 11 months ago

Hi @PietropaoloFrisoni,

No worries at all!

What I mean is more like the latter point - testing the models themselves.

For example, this project uses a minimisation to optimise the volatility and Sharpe ratio to be used in determining the efficient frontier. Or the project also does a similar thing in Monte Carlo simulations. Is it possible to create a portfolio without any of these optimisations by using a method like random search, and then comparing the effect of these models to that non-optimised random portfolio? I.e. a "dry" run vs an "optimal" run.

Hope this makes sense :)

PietropaoloFrisoni commented 11 months ago

If I understand correctly what you mean, the first approach you could try is to create random weights for your stocks/funds and evaluate the portfolio parameters with those, compared to the efficient frontier. This is precisely what the Monte Carlo approach does internally: it "just" creates random weights for your portfolio's stocks/funds (sampling from uniform discrete multidimensional distribution) and then evaluates the parameter(s) you choose for each sample, picking up the optimal one.

For example, after choosing the funds/stocks you want to invest your money on, suppose you want to balance your portfolio to maximize the Sharpe ratio. Suppose also that you decide to use the Monte Carlo approach. In that case, FinQuant generates a certain number (corresponding to num_trials, which by default is 1000) of random weights and picks up the configuration for which the Sharpe ratio of your portfolio has a maximum. You can visualize the Sharpe ratio of the other configurations in the plots, which FinQuant generates automatically. In this sense, this allows you to "measure" how well your portfolio performs compared to different random weights.

Although I implemented something similar in a private old repository, the one who originally wrote this part of the code in FinQuant is @fmilthaler. Therefore @fmilthaler, please correct me if I'm saying something imprecise.

By the way, I always use the scipy.optimize.minimize module rather than Monte Carlo since it is usually faster and more efficient : ). I hope that helps!

All the best

wasimnoordin commented 11 months ago

Great response, thank you for taking the time!

So, to clarify, if I generate a number of random weights in Monte Carlo (which maximise the Sharpe ratio), would I be able to see the Sharpe ratios of configs that have not been optimised by Monte Carlo (i.e. not maximised Sharpe ratios) in the plots?

Is there a similar approach for Efficient Frontier? I.e. we see a plot which contains the Efficient Frontier optimised config (min vol, max sharpe) and this is displayed against all non-optimised configs?

Sorry if I'm fumbling my words - still more or less a beginner :)

PietropaoloFrisoni commented 11 months ago

No worries : )

if I generate a number of random weights in Monte Carlo (which maximise the Sharpe ratio), would I be able to see the Sharpe ratios of configs that have not been optimised by Monte Carlo (i.e. not maximised Sharpe ratios) in the plots?

Yes

Is there a similar approach for Efficient Frontier? I.e. we see a plot containing the Efficient Frontier optimised config (min vol, max sharpe) displayed against all non-optimised configs?

Yes

For example, in this pic, you can see the efficient frontier and the portfolios with random weights that do not maximize the Sharpe ratio. Each scatter point corresponds to a different portfolio with random weights, and the corresponding Sharpe ratio is on the right (sorry for the bad quality of the image):

EF

wasimnoordin commented 11 months ago

Great thanks! Did you generate this graph using one of the scripts in "Examples"? I assume you can do tye same for monte carlo?

PietropaoloFrisoni commented 11 months ago

Yes, I used something totally similar to the script in Example-Optimisation.py. The portfolios with random weights have been generated with Monte Carlo. You can try to reproduce the code by changing the parameter num_trials and verifying that the scatter points change accordingly.