For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Python Notebook Research



  • I'd like to abstract my technical indicator processing, trade decision logic, tradebar data streams, and final algorithm performance metrics inside some sort of notebook. Conceptually, I'd like to have a collection of rolling windows with a historical data warmup to fill queues, ready the indicators & smoothing functions, and train models.

    With this sort of modular design, it seems like there would be a nice balance between fast research prototyping, debugging, and easy tradebar-accurate porting to other vendor configurations.

    As a sketch, I set this up in Python with Jupyter Notebook, which more or less performs the task. It's surprisingly slow, however. https://github.com/iRyanBell/chart_exploration_notebook/blob/master/Chart Exploration.ipynb

    Are there any better examples for performing this sort of exploratory research work in Python?


  • administrators

    You may excuse me, but may it be that you are posting in the wrong forum?

    There are no traces of backtrader in your Python Notebook. It actually contains traces of a bad clone/copy of backtrader



  • @backtrader My apologies. What I'm looking for is a general strategy which lives outside of Backtrader for easy debugging, tweaking, and visualization. Eg., perhaps I'd like something that works like an RSI, but works differently, and I'd like to use threshold values with this strategy after seeing what the general shape of the output wave looks like.

    From here, a small Backtrader wrapper, or Backtesting.py wrapper, or QuantConnect wrapper might be able to interact with the script. I imported Backtesting, but I also have the other two libraries installed.


  • administrators

    I personally fail to see what's simple about an environment in which one has to even define what the RSI does, account for the warm-up period and many other things which are in that notebook.

    Furthermore if one has a time.sleep(TIME) the speed is for sure going to be controlled by the time spent sleeping and not by any other less limiting factor like CPU capacity.

    @Ryan-Bell said in Python Notebook Research:

    perhaps I'd like something that works like an RSI, but works differently

    Isn't that what backtrader makes very easy by allowing the definition of custom indicators (with easy parameters and custom defined output lines), subclassing and extension of existing indicators?

    @Ryan-Bell said in Python Notebook Research:

    I'd like to use threshold values with this strategy

    Isn't that what parameters in a backtrader strategy are for? (You CANNOT define parameters in that bad clone)

    @Ryan-Bell said in Python Notebook Research:

    seeing what the general shape of the output wave looks like

    Isn't plotting a single line in backtrader? (Because I see several lines to do plotting there)

    @Ryan-Bell said in Python Notebook Research:

    From here, a small Backtrader wrapper, or Backtesting.py wrapper, or QuantConnect wrapper might be able to interact with the script. I imported Backtesting, but I also have the other two libraries installed.

    Sorry, but you have a very custom script. There is no possibility for other things to interact with the script, because the script is tightly integrated with one.

    The same script with backtrader

    import backtrader as bt
    
    goog = bt.PandasData(dataname=df)
    
    class Strategy(bt.Strategy):
        def __init__(self):
            bt.ind.RSI()
    
    cerebro = bt.Cerebro()
    cerebro.broker.setcash(1e6)
    cerebro.broker.setcommission(commission=0.05)
    
    bt.run()
    bt.plot()
    


  • @backtrader My sketch might have been a poor illustration for what I'm trying to achieve.

    In backtrader, let's say I want to take that standard RSI function and run an exponential moving average over the values to create a sort of RSIEMA (or, perhaps a fit it against a polynomial approximation with ARIMA forecast weighting.) It would be convenient if the code for the indicator was there in my notebook, ready for experimentation. Then, rather than run the algorithm with the display turned off for months / years at a time, I'd like to watch the algorithm's behavior and indicator signals.

    In this sense, it would be really cool to decouple the algorithm from the portfolio performance testing environment, and see more in the way of strategy / indicator debugging. I'd like to be able to test a strategy with multiple backtesting frameworks and ultimately see the same results for confirmation.

    I was just curious if there was an example for working in this fashion.


  • administrators

    @Ryan-Bell said in Python Notebook Research:

    to create a sort of RSIEMA

    https://www.backtrader.com/docu/indautoref/#rsi_ema

    @Ryan-Bell said in Python Notebook Research:

    (or, perhaps a fit it against a polynomial approximation with ARIMA forecast weighting.)

    The RSI (and subclasses) have a movav parameter which allows customization of the moving average which is applied to the underlying values produced before they are smoothed. If you want to use a polynomial fit approximation, simply create it and pass it as movav.

    @Ryan-Bell said in Python Notebook Research:

    In this sense, it would be really cool to decouple the algorithm from the portfolio performance testing environment,

    Well, you had a tight integration with a backtester, which shows that the goal is not attainable. Either you do research, which gives you an approximation and a notion if you want to further pursue things, or you backtest for accurate results (by the way, your selected backtester supports virtually no order types, so much for accuracy)

    @Ryan-Bell said in Python Notebook Research:

    I'd like to be able to test a strategy with multiple backtesting frameworks and ultimately see the same results for confirmation.

    I guess you have plenty of free time.


Log in to reply
 

});