letianzj / quanttrader Goto Github PK
View Code? Open in Web Editor NEWBacktest and live trading in Python
License: Apache License 2.0
Backtest and live trading in Python
License: Apache License 2.0
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
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:
quanttrader
supports my idea/strategy?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?
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
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:
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
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.
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
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.*'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.