GithubHelp home page GithubHelp logo

letianzj / quanttrader Goto Github PK

View Code? Open in Web Editor NEW
500.0 18.0 107.0 6.55 MB

Backtest and live trading in Python

License: Apache License 2.0

Python 41.26% Makefile 0.10% CSS 4.59% JavaScript 11.32% HTML 42.62% Batchfile 0.12%
quantitative-trading backtesting-trading-strategies trading-strategies trading-platform trading-algorithms trading-systems quant-trading quant-trader stock backtests

quanttrader's People

Contributors

drchandrakant avatar jxstanford avatar letianzj avatar meltingscales avatar wenq1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quanttrader's Issues

Ability to use ASK and BID candles

IB provide bothe OHLC for ASDK and BID price, this is useful to include the spread as part of the trading cost and avoid specific time or stock where spread can be prohibitive. Hence more realistic simulation and backtesting. How would the source code needs to be modified to that end? Happy to help if I am provided some pointers

Is it supports to add/remove options DataFrame dynamic during engine running?

Hello, I have looked for many python backtesting frameworks, none of them support option backtesting well.

All the df (DataFrame) mentioned below are with 1 minute precision (1 minute bars), since I'm backtesting for day trading.

Because for example like SPY there will be 3 expiring options every week (Monday, Wednesday, Friday). I will follow the steps below:

  1. Add SPY 1 year 1 minute bar df to engine. (2021-06-30 ~ 2022-06-30 minutes bar).
  2. Add a few SPY options expires at 2021-06-30 (For the sake of explanation, let's assume that 2021-06-30 is a Monday).
  3. Start engine to start backtesting.
  4. Until the 2021-06-30 last bar reach (2021-06-03 15:59, suppose my df is from 09:30 ~ 15:59 instead of 09:31 ~ 16:00), remove the Monday expiration options from engine.
  5. Add SPY 2021-07-02 (Wednesday) expiration options df to engine. The engine is going on and reach 2021-07-01 09:30. So I can access the new options for backtesting.
  6. Repeat 4~5 until reach 2022-06-30 15:59, all SPY minute bars depleted.

Is quanttrader supports my idea/strategy?

Delay order execution

Hi there,

Is there any way to delay order execution so as to match the design of backtrader? I know the immediate execution mode is by design, just want to have some flexibility.

I noted line below in strategy_base.py

        def adjust_position(self, sym, size_from, size_to, timestamp=None):
                """
                use market order to adjust position
                :param sym:
                :param size_from:
                :param size_to:
                :param timestamp: used by backtest broker to get price on timestamp
                :return:
                """
                if size_from == size_to:
                        return
                o = OrderEvent()
                o.full_symbol = sym
                o.order_type = OrderType.MARKET
                o.order_size = size_to - size_from
                o.source = self.id  # identify source
                if timestamp is None:
                        o.create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
                else:
                        o.create_time = timestamp

Is the timestamp arg intended for this?

Collaboration

Hi, I just found your repository and liked it a lot. It remembers me of my event trading system working in python and controlling MT5 in the background.

Just wanted to reach out and see if you would be interested in further investigating the trading quest. My focus is currently building trading processed where the pattern analysis is only the beginning (position sizing, hedging during high DD, pairs integration and integration of manual trading in case the software is lost).

Feel free to reach out if you are interested

"No security definition has been found for the request" - onTick never gets called

I am following this tutorial:

https://www.youtube.com/watch?v=CrsrTxqiXNY

Using these samples:

https://github.com/letianzj/quanttrader/tree/master/examples

Here is my code:

https://github.com/HenryFBP/algorithmic-trading/tree/master/algotradingtest/algotradingtest/quanttradertest

And I cannot seem to get a strategy to run.

The quanttrader package downloads all my stocks and orders properly, but onTick never seems to get called when I click on Start_Strat button. Perhaps my config_live.yaml is incorrect? It was copied directly from the "examples" folder of this repo.

account: [redacted]
client_id: 0
host: 127.0.0.1
port: 7497
theme: dark
strategy:
  #---------- Strategy and params control -----------#
  # DoubleMovingAverageCrossStrategy:
  #   active: false
  #   capital: 10000
  #   params:
  #     n_fast_ma: 20
  #     n_slow_ma: 200
  #   symbols:
  #   - NGZ0 FUT NYMEX
  #---------- Strategy and params control -----------#
  DualTimeFrameStrategy:
    active: false
    capital: 10000
    params:
      start_time: '09:30:00'
      end_time: '16:14:58'
      bar_start_time: '09:00:00'
      bar_end_time: '16:15:00'
      lookback_5sec: 50
      lookback_15sec: 20
    symbols:
    - ESM1 FUT GLOBEX
  #---------- Strategy and params control -----------#
  # DualThrustStrategy:
  #   active: false
  #   capital: 10000
  #   params:
  #     G: 20
  #   symbols:
  #   - MESZ0 FUT GLOBEX
  #---------- Strategy and params control -----------#
  # MovingAverageCrossStrategy:
  #   active: false
  #   capital: 10000
  #   params:
  #     G: 20
  #   symbols:
  #   - CLZ0 FUT NYMEX
  #---------- Strategy and params control -----------#
  # ActiveBuySellStrengthStrategy:
  #   active: false
  #   capital: 10000
  #   params:
  #     strength_abs_threshold: 200
  #   symbols:
  #     - NQZ0 FUT GLOBEX
  #---------- Strategy, params control, and local risk control -----------#
  OrderPerIntervalStrategy:
    active: false
    capital: 50000
    order_start_time: '10:00:00'
    order_end_time: '16:15:00'
    params:
      tick_trigger_threshold: 6000
    single_trade_limit: 3
    symbols:
    - ESM1 FUT GLOBEX
    total_active_limit: 2
    total_cancel_limit: 5
    total_loss_limit: 5000
    total_trade_limit: 15
#---------- global risk control -----------#
total_active_limit: 3
total_cancel_limit: 10
total_loss_limit: 10000
total_trade_limit: 20

Tick data is not getting downloaded

I ran the live_engine.py and started the strategy but tick data is not getting downloaded.

2021-04-09 23:03:53,245 - quanttrader.gui.ui_main_window - INFO - control: start_strategy 1

Log doesnot have any info after that.

Any help on this would be great.

Need help with modify order_per_interval.py

In my config_live.yaml file with these specification

params:
  tick_trigger_threshold: 100
  single_trade_limit: 3
symbols:
  - QQQ STK SMART 360.50 360.00 380.00
  - AAPL STK SMART 175.10 174.75 173.23
  # desciption of each stock for OrderPerIntervalStrategy and their trigger levels
  # [sym] [STK] [Exc] [level1-long] [level2-long] [level3-short]
  # How do pass these individual stock parameter into OrderPerIntervalStrategy
  # if QQQ, current tick.lastPrice ==  360.50, make bracket order (with Mkt order, stopLost = currentPrice - 0.50, takeProfit = currentPrice + 0.75)  )
  # if AAPL, current tick.lastPrice ==  175.10, make bracket order (with Mkt order, stopLost = currentPrice - 0.50, takeProfit = currentPrice + 0.75)  )

What is modify order_per_interval.py to execute yaml specifications ?

Are there more strategies ? so to better understand the process

Thanks in advance

Invalid specifier: '>=3.7.*'

When trying to setup for local development:

cd quanttrader
pip install -e .
error in quanttrader setup command: 'python_requires' must be a string containing valid version specifiers; Invalid specifier: '>=3.7.*'

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.