freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
28.01k stars 6k forks source link

Portfolio maintenance / portfolio balancing #4149

Closed Payback80 closed 3 years ago

Payback80 commented 3 years ago

Hello! Great project! It's two days that i'm digging the codebase and the docs and I'm still not sure if i can do what i want. i want to implement a portfolio theory like the Markowitz portfolio, i've already read issue #2183 , #3118

I'll try to be clear, suppose i have a portfolio of 3 pairs btc-eur, eth-eur, ltc-eur and suppose i have an algo that will rebalance the portfolio at a fixed time t={t0,t1,t2....tn}. the algo weights sequence will be

t0 [0 , 0.5, 0.5] means get balance & tradable_balance_ratio open 2 market buy operation 50% of the balance on eth-eur and 50% on ltc-eur t1 [0 , 0, 1] sell eth-eur, calculate the profit/loss, get balance & tradable_balance_ratio and of the WHOLE tradable_balance put 100% on ltc-eur

t2 [0.5 , 0, 0.5] sell 50% of the position on ltc-eur, calculate profit/loss, get balance & tradable_balance_ratio , with 50% of the tradable balance buy btc-eur

So the questione are:

- def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: and in interface.py

@abstractmethod def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Based on TA indicators, populates the buy signal for the given dataframe :param dataframe: DataFrame :param metadata: Additional information, like the currently traded pair :return: DataFrame with buy column

will create a SINGLE dataframe with buy/sell signals for each pair whitelisted in the config, am i right? For clarification purpouses as in the above example it could be nice having a single df with a pair of columns buy/sell for each tradable pair in % so 6 columns. If not any suggestion for a workaround that will sync the 3 pairs on the same candle?

but the second question is more important: Is it possible to manage the portfolio's weights? as in #2183 the intent is to buy and sell in percentages, this will not only useful for my situation but also in trading system where given certain conditions you want to buy more.

I think your project will have a great benefit of allowing an easy wasy to implement portfolio theories and any suggestion to solve my problem is well appreciated, thank you

xmatthias commented 3 years ago

First, i'm going to move this from the strategy to the main repository - as it's not related to strategies at all.


That said / done - Freqtrade is not really a tool for portfolio balancing, but for (day) trading - so the concept is to enter a position (ideally at a low price) - and then exit that position ASAP (once it reaches a certain profit, or hits a stoploss, or your strategy signals to "sell" - based on whatever indications).

What you're talking about is portfolio optimization / portfolio balancing. I'm sure you'll find tools that are designed to do this - but freqtrade is not built for hat, and it's whole structure and concept will not play well with it.

If you think it can be supported with minimal changes, feel free to submit a pull-request which will introduce this. However, i will not change half the bot to support this, while risking to break other usecases, and increasing the maintenance burden as it'll be another part of the code that has to be maintained (and checked it's not breaking, and eventually adjusted if bugs are found ...). Keep in mind that it's an open source project, so it's people working on it in their free time - so we must keep maintenance burden as low as possible (it's already high due to some rarely used features ...).

If not any suggestion for a workaround that will sync the 3 pairs on the same candle?

Read the documentation - it's possible with the dataprovider within the strategy.

Is it possible to manage the portfolio's weights?

no, trade sizes are fixed at the moment (or it's a % of your account). You can't define the value per trade. Allowing the strategy to control stake amount is a longstanding issue (and there is an unfinished / incomplete PR available in #3886 ) - so this might be changed.

I think your project will have a great benefit of allowing an easy wasy to implement portfolio theories and any suggestion to solve my problem is well appreciated, thank you

All possibilities are in the documentation (best read from cover to cover to know what is supported). As said above, feel free to submit a Pull request if minimal changes are necessary to support your usecase - but in general, i don't see freqtrade as a portfolio maintenance tool.

xmatthias commented 3 years ago

I'll assume this as answered by the above.

Feel free to comment below / reopen if that's not the case.

sdfsdsdsd commented 3 years ago

@Payback80 Did you work on this?

I am not using freqtrader yet in production, but the general topic of portfolio optimization aside, I want to write a strategy that can decide for or against buying one coin based on information about other coins, which is what I am doing in daytrading.

So any state of this work appreciated.

CarloNicolini commented 3 days ago

no, trade sizes are fixed at the moment (or it's a % of your account). You can't define the value per trade. Allowing the strategy to control stake amount is a longstanding issue (and there is an unfinished / incomplete PR available in #3886 ) - so this might be changed.

I think your project will have a great benefit of allowing an easy wasy to implement portfolio theories and any suggestion to solve my problem is well appreciated, thank you

All possibilities are in the documentation (best read from cover to cover to know what is supported). As said above, feel free to submit a Pull request if minimal changes are necessary to support your usecase - but in general, i don't see freqtrade as a portfolio maintenance tool.

Is this related to the informative_pairs method?

xmatthias commented 3 days ago

This is a 3 year old issue. It's safe to say - information here may be incorrect in 2024.

Plaese read the documentatin to get uptodate information.