Example #1
0
    def call_ema(self, other_args: List[str]):
        """Process ema command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="ema",
            description="""
            The Exponential Moving Average is a staple of technical
            analysis and is used in countless technical indicators. In a Simple Moving
            Average, each value in the time period carries equal weight, and values outside
            of the time period are not included in the average. However, the Exponential
            Moving Average is a cumulative calculation, including all data. Past values have
            a diminishing contribution to the average, while more recent values have a greater
            contribution. This method allows the moving average to be more responsive to changes
            in the data.
        """,
        )

        parser.add_argument(
            "-l",
            "--length",
            action="store",
            dest="n_length",
            type=check_positive_list,
            default=[20, 50],
            help=
            "Window lengths.  Multiple values indicated as comma separated values.",
        )

        parser.add_argument(
            "-o",
            "--offset",
            action="store",
            dest="n_offset",
            type=int,
            default=0,
            help="offset",
        )

        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-l")

        ns_parser = parse_known_args_and_warn(
            parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES)
        if ns_parser:
            overlap_view.view_ma(
                ma_type="EMA",
                s_ticker=self.ticker,
                s_interval=self.interval,
                df_stock=self.stock,
                length=ns_parser.n_length,
                offset=ns_parser.n_offset,
                export=ns_parser.export,
            )
Example #2
0
    def call_zlma(self, other_args: List[str]):
        """Process zlma command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="zlma",
            description="""
                The zero lag exponential moving average (ZLEMA) indicator
                was created by John Ehlers and Ric Way. The idea is do a
                regular exponential moving average (EMA) calculation but
                on a de-lagged data instead of doing it on the regular data.
                Data is de-lagged by removing the data from "lag" days ago
                thus removing (or attempting to) the cumulative effect of
                the moving average.
            """,
        )

        parser.add_argument(
            "-l",
            "--length",
            action="store",
            dest="n_length",
            type=check_positive_list,
            default=[20],
            help=
            "Window lengths.  Multiple values indicated as comma separated values.",
        )

        parser.add_argument(
            "-o",
            "--offset",
            action="store",
            dest="n_offset",
            type=int,
            default=0,
            help="offset",
        )

        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-l")

        ns_parser = parse_known_args_and_warn(
            parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES)
        if ns_parser:
            overlap_view.view_ma(
                ma_type="ZLMA",
                s_ticker=self.ticker,
                s_interval=self.interval,
                df_stock=self.stock,
                length=ns_parser.n_length,
                offset=ns_parser.n_offset,
                export=ns_parser.export,
            )
Example #3
0
    def call_sma(self, other_args: List[str]):
        """Process sma command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="sma",
            description="""
                Moving Averages are used to smooth the data in an array to
                help eliminate noise and identify trends. The Simple Moving Average is literally
                the simplest form of a moving average. Each output value is the average of the
                previous n values. In a Simple Moving Average, each value in the time period carries
                equal weight, and values outside of the time period are not included in the average.
                This makes it less responsive to recent changes in the data, which can be useful for
                filtering out those changes.
            """,
        )

        parser.add_argument(
            "-l",
            "--length",
            action="store",
            dest="n_length",
            type=check_positive_list,
            default=[20, 50],
            help=
            "Window lengths.  Multiple values indicated as comma separated values. ",
        )

        parser.add_argument(
            "-o",
            "--offset",
            action="store",
            dest="n_offset",
            type=int,
            default=0,
            help="offset",
        )

        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-l")
        ns_parser = parse_known_args_and_warn(
            parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES)
        if ns_parser:
            overlap_view.view_ma(
                ma_type="SMA",
                s_ticker=self.ticker,
                s_interval=self.interval,
                df_stock=self.stock,
                length=ns_parser.n_length,
                offset=ns_parser.n_offset,
                export=ns_parser.export,
            )
    def call_hma(self, other_args: List[str]):
        """Process hma command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="hma",
            description="""
                The Hull Moving Average solves the age old dilemma of making a moving average
                more responsive to current price activity whilst maintaining curve smoothness.
                In fact the HMA almost eliminates lag altogether and manages to improve smoothing
                at the same time.
                        """,
        )
        parser.add_argument(
            "-l",
            "--length",
            action="store",
            dest="n_length",
            type=check_positive_list,
            default=overlap_model.WINDOW_LENGTHS2,
            help="Window lengths.  Multiple values indicated as comma separated values. ",
        )
        parser.add_argument(
            "-o",
            "--offset",
            action="store",
            dest="n_offset",
            type=int,
            default=0,
            help="offset",
        )

        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-l")

        ns_parser = parse_known_args_and_warn(
            parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
        )
        if ns_parser:
            overlap_view.view_ma(
                ma_type="HMA",
                s_ticker=self.ticker,
                s_interval="1440min",
                df_stock=self.data,
                length=ns_parser.n_length,
                offset=ns_parser.n_offset,
                export=ns_parser.export,
            )
    def call_wma(self, other_args: List[str]):
        """Process wma command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="wma",
            description="""
                A Weighted Moving Average puts more weight on recent data and less on past data.
                This is done by multiplying each bar’s price by a weighting factor. Because of its
                unique calculation, WMA will follow prices more closely than a corresponding Simple
                Moving Average.
                        """,
        )
        parser.add_argument(
            "-l",
            "--length",
            action="store",
            dest="n_length",
            type=check_positive_list,
            default=overlap_model.WINDOW_LENGTHS,
            help="Window lengths.  Multiple values indicated as comma separated values. ",
        )
        parser.add_argument(
            "-o",
            "--offset",
            action="store",
            dest="n_offset",
            type=int,
            default=0,
            help="offset",
        )

        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-l")

        ns_parser = parse_known_args_and_warn(
            parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
        )
        if ns_parser:
            overlap_view.view_ma(
                ma_type="WMA",
                s_ticker=self.ticker,
                s_interval="1440min",
                df_stock=self.data,
                length=ns_parser.n_length,
                offset=ns_parser.n_offset,
                export=ns_parser.export,
            )