finta icon indicating copy to clipboard operation
finta copied to clipboard

Set custom series name

Open damianoporta opened this issue 7 years ago • 8 comments

Hi, first of all THANK YOU FOR THIS AWESOME LIBRARY A question: how can we set custom series name? At the moment it seems not possible setting a custom series name, we must rename it after return. Do you think could be useful to pass an optional parameter to set a custom series name?

damianoporta avatar Sep 10 '18 12:09 damianoporta

Hi,

no I did not make it possible to have a custom series name. Perhaps that is usable indeed. I'll get it done when I catch some spare time.

peerchemist avatar Sep 10 '18 13:09 peerchemist

Hi, i can fork the repo and create a PR.

we can add the name parameter with None value and then change each indicator like this: name=name or '{0} period SMA'.format(period)

what do you think?

damianoporta avatar Sep 10 '18 13:09 damianoporta

It should have default value, so if user does not provide any it prints out what it prints out now.

def SMA(self, ohlc, periods, column='close', name='SMA')

then you can override with name='simple_moving_average' if you like.

So sure, I happy to merge in your PR. :)

peerchemist avatar Sep 10 '18 14:09 peerchemist

@peerchemist i think your series names are good, i do not think we need to change them, just let the user renames it if needed. For example at the moment the SMA name is: '{0} period SMA'.format(period) we can use it as default and override it if the optional parameter is used. No?

damianoporta avatar Sep 10 '18 14:09 damianoporta

How would you override it in the code? With if block? Is not what I've proposed cleaner solution with less lines of code?

peerchemist avatar Sep 10 '18 15:09 peerchemist

    def SMA(cls, ohlc, period=41, column='close', name=None):
        """
        Simple moving average - rolling mean in pandas lingo. Also known as 'MA'.
        The simple moving average (SMA) is the most basic of the moving averages used for trading.
        """

        return pd.Series(ohlc[column].rolling(center=False, window=period,
                         min_periods=period - 1).mean(),
name=name or '{0} period SMA'.format(period))

is this not good for you? WIth this code we did not add any new line.

damianoporta avatar Sep 10 '18 15:09 damianoporta

Ok that will work.

peerchemist avatar Sep 10 '18 15:09 peerchemist

Any updates on this?

peerchemist avatar Oct 02 '18 14:10 peerchemist