I need a trading strategy written in Python for Quantconnect which can be backtested and optimized.
This is basically for me to get a template for changing in future.
- The trading algorithm must trade US equities only
- Must be written in Python
- Must use Coarse/Fine selection
- Will trade both sides
1. Universe Selection in timeframe 1:
The universe selection happens in one timeframe and the actual trading in another faster timeframe.
For example, we want to select a set of stocks every night for the next day.
- Must use Coarse/Fine selection
- Coarse equity selection must have
[login to view URL] > priceThreshold, where priceThreshold is a parameter with default value of 5 and
minimum avg volume of avgVolThreshold, where avgVolThreshold is a parameter with default value of 50000, and minimum average volume of the symbol is computed over a parameterized period say AvgVolPeriod e.g. symbolSMAv = SimpleMovingAverage([login to view URL])
- Fine equity selection
This needs to be clearly written such that another algorithm may be substituted by me later.
For this project we will use a parameterizable Bollinger Band squeeze as a threshold.
i.e. we will select only those where the bollinger bandwidth is below a certain threshold and has become smaller in the last m periods versus over the prior n periods
(see [login to view URL] for a reference)
The resulting list must be sorted by Float
2. Trading Algorithm in timeframe 2:
We want to trade in a shorter timeframe. E.g. if the universe selection happened on the day timeframe, then we are trading next day on the 1 min or 5 min timeframes.
- The trading algorithm for longs and shorts should be in seperate blocks so that one may comment the Long OR short versions for testing.
- The trading algorithm is breakout (or breakdown) over a certain % from its previous close in the universe and certain % over (or under) its bollinger band value.
- breakout is used for long positions, breakdown for short positions.
- e.g. we want to buy if the stock breakouts 2.5% over its previous close and is above its upper bollinger or vice-versa for shorting. This part needs to be clean and nicely modifiable.
- these two % values should be parameterizable.
- The algorithm must not enter into a trade for a symbol if it has earnings that day
- Similarly it must close out positions by close of trade which have earnings in the following day
- Must be able to set a buy and sell window times for all trades: e.g. enter new positions from 9:45 a.m. to 10:45 a.m. etc.
- The algorithm can trade up to 10 stocks in a single day but only 4 to prevent pattern day trading.
3. Position Sizing and Loss Control:
- The algorithm should allocate capital per position based on a fixed risk % of the currently available capital
- First: the stop loss price for Long positions = Minimum of AverageTrueRange(n periods, close), yesterday's close, Invert this for Short positions
- Capital Risk per position = 2% (parameter)
- e.g. if the parameter risk is 2% and 100K capital exists then 2k can be risked. hence the number of shares
- Number of shares = Risk-amount/(current_price - stop loss price)
- Based on the above conditions, The algorithm can allocate 100% of available capital or an equal dollar amount into each equity if there are more than one at that time.
4. Position Exit
- STOP LOSS: Upon entering the position a stop limit loss must be entered using the above value.
- PROFIT TARGET: A profit target based exit must also be entered e.g. 10% from entry
- TIME based EXIT: The position should be closed after N bars where N is a parameter.
[login to view URL] Criteria:
- Must show via backtesting that the algorithm works without errors before completion acceptance.
- Cleanly separated code and parameters for the major blocks as mentioned.
6. Skills required:
- Basic Trading Knowledge: ATR, Float, Stop Loss, Short/Long etc.
6 freelancers are bidding on average $177 for this job
Hi I'm very interested in your post. As a senior Python developer, I can help you perfectly. I have rich experience with Python/Django/Flask/ML/AI/Scraping. Let's discuss more detail via private chat. Thanks.