I think I am right in saying that a custom fill model can only be set where you know upfront what stocvks you will be trading and can set the custom models in "Initialise"?
self.security.SetFeeModel(CustomFeeModel(self))
self.security.SetFillModel(CustomFillModel(self))
self.security.SetSlippageModel(CustomSlippageModel(self))
That being the case, if I want to trade a set of stocks which will vary from day to day based on the Course and Fine Filter modules, would I be right in thinking that I would have to start from scratch and (by way of example) design a series of buy or sell orders which stretch over my given time frame (resolution second or minute) and assume an order will be filled in say 10 different mini orders spread 1 minute or 1 second apart?
I guess many people must have done something like that here?
Anthony FJ Garner
Incidentally, for your amusement (and my own) I am trying to model the vague and wishy washy "system" being punted by a well known penny stock trader.
Needless to say, although the fellow claims he operates a system or systems, when you come to try and code it you find a rather different story. He may consider that he is systematic, but the reality is that he relies on a very large element of discretion on a day to day basis.
Liquidity is NOT such a big problem if you are trading small and you only trade when a "pump" is operational. Or at least a sharp upward momentum accompanied by a vastly increased $ volume.
The Quantopian forum had some amusing penny stock systems but none of them were sophisticated enough to account for a realistic order process in very fast moving environments,
One such system has been ported here but the reality is that it probably profits by erroneously bouncing off very wide b/o spreads at times when $ volume is low.
Needless to say this is day trading. I don't think anyone in their right might would want to hold this junk overnight. So you would be buying over a period of seconds or minutes after the open, taking incremental profits during the day (or losses) and cancelling open orders and exiting after say 4pm.
Rahul Chowdhury
Hey Anthony,
It is possible to set custom slippage, fill and fee models for an indefinite universe. We can use SetSecurityInitializer to set our custom fill models for all securities which enter our universe.
We can define our security initializer as
def CustomSecurityInitializer(self, security): security.SetFeeModel(CustomFeeModel(self)) security.SetFillModel(CustomFillModel(self)) security.SetSlippageModel(CustomSlippageModel(self))
This will set our models for each security when it is initializedThen in our Initialize method, we can set our CustomSecurityInitializer
self.SetSecurityInitializer(self.CustomSecurityInitializer)
Best
Rahul
Anthony FJ Garner
Wow, so its that simple. Many thanks. Mind you as I pointed out in another thread, in my view a custom fill module is of limited use if you can not spread it over several bars.
Custom Fill Model Example
As you will see, although that example separates an order into a number of different fills, they are all executed at the same price at the close of the same bar. I guess it should be possible to have the custom fills at the OHL or C or an average of some sort but I think it would be more realistic to spread it over a number of different bars.
I am going to have to try an adapt the following code to Python:
Partial Fill Model Tests
In any event thank you for your most helpful response and I will post an example of what I am proposing once I have worked out how to do it.
A
Anthony FJ Garner
Hmm....I am beginning to understand what a powerful and well designed tool Quantconnect is. A steep learninng curve and a fairly tiresome journey but quite a tool if you persevere. And a second data is quite and advantage over Quantopian's Minute data.
Jared Broad
Thanks Anthony. We'll add an example of Python Partial Fills later today.
L1 data shipped last night so you should see some spread appearing on your fills.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Anthony FJ Garner
Jared
That sounds excellent all round. Where would I find the new code which bases the fills on the B/O spreads? And I assume one can now access the B/O spreads direct oneself?
Ideally, a partial fill model would be based on volume for my purposes. And presumably everybody else's. One needs to assume that one does not absorb more than x% of a bar's volume for your own orders and that any unfilled portion of the order spills over to the next bar and so on. And I guess we will need to chose whether we are taking or making liquidity: whether we are accessing the offer and the volume at the offer for a purchase or whether we are offering a certain volume...which presumably gets taken (or not) at the next bar.
Anyway, I will be most interested to see what you are proposing.
Anthony FJ Garner
A few conclusions so far: published on my blog.
I am working my way towards testing out the “systems” promoted by Tim Sykes and others of his ilk regarding Penny Stocks.
The task is made no simpler by the failure to clearly specify entry and exit rules by those who promote penny stock trading. We hear about chart patters,”super nova”, support and resistance. We hear about buying dips. We hear about the fabulous profits to be made. Unfortunately, these profits seem largely to have been made by discretionary trading, since Mr Sykes and his students never actually manage to quantify their systems in such terms as could be communicated to a computer by code. And back tested.
These people say that their skills represent an art rather than a science, and I have a certain sympathy with that view. Clearly none of these people have the right skills to think about their trading in a quantitative way and that is perfectly understandable and acceptable.
Reading their posts on the many social media websites they inhabit makes it clear that they do not follow strictly quantifiable rules. And indeed, why should they? Nonetheless, their decisions as to when to buy and sell must be made on some basis and it would be interesting to find out whether, if they thought very hard and recorded their motivations for entering and exiting a trade, they could actually come up with concrete reasons for their decisions.
Most often, Sykes and his proteges will be celebrating trades they profited on and ruing trades they missed. The constant refrain on losing trades is “if”….”. If I had held overnight, if I had sold before the close. On winning trades by intuition, they chose the right course of action.
These guys claim (and I have no reason to doubt them) that they have more winning trades than losers, and that the average win exceeds the average loss. An enviable and unusual achievement.
One “system” is to buy into strength, to buy into a stock the day after it has had a substantial gain on substantial volume.
Another system is to short such trades which have been pumped and therefore will eventually be dumped.
That pumps and dumps exist is self evident. The trick is how to benefit from both the pump and the dump. Or at least from one or the other.
I have been working with the Quantconnect online back tester, since after a painful period of familiarization, I believe it to be excellent software. It also has the advantage of offering OHLC bars for seconds as well as tick data. It is about to roll out bid and offer data and volume at the b/o thus, back testing can become even more realistic.
So far, my back testing has been very simple and limited. If the stock rose x% yesterday on high dollar volume, buy at the open the next day and sell at the close. And the reverse: sell at the open the next day and cover at the close. My universe is many thousands of US stocks (including stocks which are no longer trading) whose stock price at the time of the trade (or rather the day before) was below $5 and dollar volume greater than $100,000.
I intend to move on and code profit taking measures intraday but for the time being, I believe my work has provided me with some valuable insight.
By way of example let us assume the price movement triggering an entry is 50%. The stock must have moved up 50% the previous day on high volume.
Bet size used was a maximum of 1% and the test period was from the beginning of 2014 to date.
Here is the breakdown:
Taking long trades only:
Av. Win 0.49%
Av. Loss -0.44%
Number of winning trades (%) 21%
Number of losing (%) 79%
CAGR -23.4%
Max DD 80.4%
Taking short trades only:
Av. Win 0.29%
Av. Loss -0.41%
Number of winning trades (%) 63%
Number of losing (%) 37%
CAGR 2.72%
Max DD 27%
Now clearly, Sykes and his friends do not buy at the open and sell at the close – or not usually. They are discretionary day traders and something prompts them to take trades at various times during the day. What causes such intra day entries and exits is not quantified – and these traders may claim that the reasons for such decisions are un-quantifiable.
Nonetheless, in these days of high frequency trading, it is possible to ape the antics of these people, if they can explain what it is they are doing. Or if you can guess or assume what they are doing.
As you can see from the above, statistically, shorting looks the smarter move. After all penny stocks achieve that sobriquet because they lose value over time and become worthless. But such stocks are hard to borrow. Prima facie, the long side of the trade looks a disaster.
But it is early days. Let’s see how this progresses. There will be errors in my code and my thought process and I am far from reaching and conclusions at this stage.
Jared Broad
Awesome =D Thank you for posting the research back. If you're open to it please post a new thread focusing on penny stock debunking. I think the new data+partial fills would be very helpful to those seeking to exploit misleading backtests.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Anthony FJ Garner
Thank you. I will do that. I become more impressed by the possibilities of Lean day by day.
Anthony FJ Garner
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!