Coder Social home page Coder Social logo

backtrader-finstrat's Introduction

backtrader-finstrat

Active Stratefy - Residual (idiosyncratic) momentum based, with tactical asset allocation, pyramid positioning (Bollinger Bands)

Source code - strategy_idiosync_m_gtaa_py_bb_atr_stoploss.py

Risk Management

  1. Quarterly (rebalance) checks

    • If the global market is in a downtrend, don't rebalance and continue holding safe assets.
    • Individual stocks - exclude from consideration stocks in downtrend (SMA < 200 or 150)
  2. Monthly checks (beginning of each month)

    • if the global market is in a downtrend (< 200SMA), exist equities and buy safe assets.
    • If the global market switched to an uptrend (> 200SMA), rebalance back into risky assets, even before the official rebalance.

Reasoning - don't catch a falling knife, however, monthly intervals allow room for the market to recover if briefly touching SMA200.

  1. Daily checks
    • Checks trailing high against deviation of scaled average true range ATR(90) of the stock.
      • ATR is more robust than using constant trailing % loss, since it takes into account historical volatility of specific stock.
      • The larger is number of days from trailing high, the more likely price to break the ATR
        • To count that, ATR is scaled by number of days (up-to 6) from the high
      • ATR approach is more sound theoretically and is robust under different universes, as opposed to constant 20%, which was more tuned to the extended universe
      • It is mechanism that backs up the global (monthly) risk management in a robust manner.

Positioning

  • If stock is in a downtrend at the purchase decision, wait till it reaches the lower limit of its Bollinger Band before allowing the purchase.
  • If the purchase is enabled, perform pyramid positioning - if the asset's price moved X% above the current target price, buy an asset's proportion and set a new target price.

Profit taking

Profit-taking is happening in 2 cases:

  1. Sell at the rebalance, due to the current asset wasn't picked by the momentum algorithm.
  2. Profit-taking if an asset appreciated 30% compared to its buy price (for any continuous period, not just a quarter)

Past strategy - Absolute momentum based, with tactical asset allocation, pyramid positioning (Bollinger Bands)

Source code - strategy_momentum_gtaa_py_bb_atr_stoploss.py

  • Shares the same features as the main strategy, just the momentum calculation is different.

Past strategy 2 - momentum based, with tactical asset allocation, pyramid positioning

Source code - strategy_momentum_gtaa_pyramiding.py

Risk Management

  1. Monthly checks (beginning of each month)
    • if the global market is in a downtrend (< 200SMA), exist equities and buy safe assets.
    • If the global market switched to an uptrend (> 200SMA), rebalance back into risky assets.

Reasoning - don't catch a falling knife, however, monthly intervals allow some room for the market to recover if briefly touching SMA200.

  1. Daily checks

    • If individual asset's trailing decline > 25%, close position.
  2. Quarterly - if the global market is in a downtrend, don't rebalance, continue holding safe assets.

Positioning

  • Pyramid positioning - if the price of the asset moved X% above starting price, buy a portion of the asset and set a new target price. While absolute returns are a bit lower, the strategy has improved risk-adjusted returns and significantly lower maximum drawdown. Backtested on multiple universes.

Profit taking

Profit-taking is happening in 2 cases:

  1. Sell at the rebalance, because the current asset wasn't picked by the momentum algorithm.
  2. Profit-taking if an asset appreciated 30% compared to its buy price (for any continuous period, not just 3 months)

backtrader-finstrat's People

Contributors

snexus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.