PyPortfolioOpt icon indicating copy to clipboard operation
PyPortfolioOpt copied to clipboard

Suggestion on DiscreteAllocation class for regular rebalancing

Open HYANGKI-LEE opened this issue 3 years ago • 2 comments

Hello, Robert

I found your DiscreteAllocation.greedy_portfolio() in pypfopt while implementing a regular rebalancing task. However, my challenge was that my situation was not SIMPLY convert continuous weights to discrete allocation.

A new situation I had to consider was:

  • I already have some stocks.
    • In other words, we had to consider the situation of not only buying the stock, but also selling it.
  • ‘fee’ (a kind of contraction cost) must be considered (In addition, using ‘total_portfolio_value’, which is dependent on ‘latest_prices’, felt a little less intuitive to me.)

Thankfully, thanks to your project, I was able to implement the task without difficulty. I really appreciate this part.

I am using your code by modifying the structure as below.

[Inputs & Outputs in DiscreteAllocation class] “””

  • Inputs:

    • weights - dict
    • latest_prices - pd.Series or dict
    • total_portfolio_value - int/float
    • short_ratio- float
  • Output:

    • allocation - dict “””

[After modifying] “””

  • Inputs:

    • weights - dict
    • init_state - dict # number of existing shares
    • latest_prices - pd.Series or dict
    • cash - int/float # amount of cash currently has
    • fee_rate - float # fee rate as contraction cost
    • short_ratio- float
    • verbose- bool
  • Output:

    • allocation - dict
    • action - dict # action for desired weight (+ indicates buying, - indicates selling)
    • cash_left - dict “””

If this fixing fits the direction of your project PyPortfolioOpt, I'd be happy to share with you.

Please read the above and reply. Thank you for your time.

HYANGKI-LEE avatar Oct 21 '22 03:10 HYANGKI-LEE

If this can be implemented in a self-contained way with a couple of unit tests, I'm happy to accept a PR!

robertmartin8 avatar Nov 26 '22 14:11 robertmartin8

@HYANGKI-LEE Can you please create a PR, I would like to use that code.

Thanks

AnkitAggarwalAlphagrep avatar Dec 13 '22 17:12 AnkitAggarwalAlphagrep