Skip to Content
Mastering Python for Finance - Second Edition
book

Mastering Python for Finance - Second Edition

by James Ma Weiming
April 2019
Intermediate to advanced
426 pages
11h 13m
English
Packt Publishing
Content preview from Mastering Python for Finance - Second Edition

Writing the trend-following trader class

Let's write a class for our trend-following trading system with a new class named TrendFollowingTreader, which simply extends the MeanReversionTrader class using the following Python code:

class TrendFollowingTrader(MeanReversionTrader):    def __init__(        self, *args, long_mean_periods=10,        buy_threshold=1.0, sell_threshold=1.0, **kwargs    ):        super(TrendFollowingTrader, self).__init__(*args, **kwargs)        self.long_mean_periods = long_mean_periods        self.buy_threshold = buy_threshold        self.sell_threshold = sell_threshold

In our constructor, we define three additional keyword arguments, long_mean_periods, buy_threshold, and sell_threshold, saved as class variables. The long_mean_periods variable defines the number ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Finance - Second Edition

Python for Finance - Second Edition

Yuxing Yan
Python for Finance

Python for Finance

Yves Hilpisch

Publisher Resources

ISBN: 9781789346466Supplemental Content