fmilthaler / FinQuant

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

Feature/stocks clustering #64

Closed shurajan closed 3 years ago

shurajan commented 3 years ago

Hello

I added a new feature to Portfolio class to cluster stocks by returns and volatility. This should help investors to make a decision to exclude poorly performing stocks or identify champions. The feature is quite useful when dealing with a great number of stocks in portfolio. I adjusted tests and successully passed them all. Looking forward to reading your feedback to make any required adjustments.

PS: I have long since last time contributing to project and so I hope I did everything right). I would not say that I am very experienced python developer too.

fmilthaler commented 3 years ago

Hi there and thank you very much for your suggestion and implementation. This looks like a good addition, and I appreciate the effort to add tests as well as an example.

If you don't mind, please change the target of the merge request from fmilthaler:master to fmilthaler:feature/stocks-clustering. It is then easier for me to test etc before it is merged into master.

shurajan commented 3 years ago

I also think the version of randomizers below for MC would work a bit better:

def random_weights_norm(num_assets: int):
    U = np.random.random_sample(num_assets - 1)
    U = np.insert(U, 0, 0.0, axis=0)
    U = np.insert(U, len(U), 1.0, axis=0)
    U.sort()
    V_list = []
    vi_1 = 0
    for i in range(len(U)):
        if i > 0:
            vi = U[i] - vi_1
            V_list.append(vi)
            vi_1 = U[i]

    return np.array(V_list)
fmilthaler commented 3 years ago

Once again, thanks @shurajan. My apologies for the slow progress on this. I got plenty of stuff happening these days. Will try and look at this soon in more detail and then merge to master. Much appreciated! :)