I have the following scenario in mind:
Pass the system the following inputs:
in period duration (5Y)
out period duration (1Y)
parameters and ranges
Let's say we have 10 years worth of data, then the ideal processing would be as follows:
Break the data in multiple chunks according to the periods defined above
In Period 1: 2000-2005
Out Period 1: 2005-2006
In Period 2: 2001:2006
Out Period 2: 2006-2007
In Period 3: 2002-2007
Out Period 3: 2007-2008
Than start executiing the execution.
Optimize parameters for first In Period (2000-2005) - cerebro.optstrategy()
Get best parameters from previous run and test on Out Period 1 - cerebro.addstrategy()
Optimize again on the next In Period
Test with the parameters from previous step on the next out period
Optimize again ......
Test again on the next Out Period .....
At the end plot the combined strategy during all out periods from 2005 to 2010 by taking into consideration that parameters are being changed every year with the optimized values from last 5 years worth of data.
I am open for any ideas for implementation.
So far I am thinking to read the data in pandas, break it and loop through it in chunks and feed it to cerebro consecuently.
I have no idea how to combine the outputs from each cerebro run and how to plot all individual strategy executions into a single figure.
The idea is always to have a generic model, like it is the case with the timezones, in which you may pass pytz instances or something that, more or less, complies to the interface of pytz.
A similar approach will be taken.
My example was with daily bars, as I think is more close to the reality. At the end, forgetting about the -coc option for a moment, if you have a live order feed sending only daily bars, you could have that planned task at, for example, midday, that send the MOC order and gets executed with the close price of the daily bar.
There is difference between backtesting with daily bars and having a live feed which delivers daily bars. The latter probably constantly updates the current daily bar and that's why you think that already at noon time it may be possible to send a MOC order.
To achieve the same effect during backtesting you need one of this:
intraday data and replay daily bars
Set cheat-on-close and allow using the close price
Use filters and break the feed into OHL + C steps (see the Pinkfish Challenge - and the sample in the sources)
For the MOO I can send it to IB with kwargs as you´re proposing, but I cannot get the same effect with backtesting, basically because 1) Backtrader doesn´t support natively MOO orders (what about more order types support for the future? :slight_smile: ) or 2) as I don´t have "planning tasks capability" I should know which one is the last bar - 1 on the day, to send a Market Order, before it close, and simulate MOO behaviour...
Yes you can. If you use daily bars, whenever you get a bar during backtesting, you are at the end of the session. Send for both cases (backtesting and live) a Market order and the extra kwargs. The standard backtesting broker will ignore it and the IB broker will overwrite the order type.
if I do it with a background thread as proposed, I understand this is a real time capability, but no way to reproduce it on backtesting mode, isn´t?
Not at the moment
if implemented as points in lines (kind of time feed), wouldn´t be this more accurate to have same behaviour like in realtime with just 1 code?
At least it would have the same behavior right now for both scenarios.
Note: with CFD products you should consider taking the interest into account for both long and short positions.
Note2: that's the problem with snippet typing (as opposed to testing it), they usually contain typos. And the same applied partially to the documentation. Both posts have been corrected to avoid future confusion and the docs updated.
checksubmit controls if a submitted order can be accepted by the broker by simulating execution and with it checking if the current cash reserves are enough. It actually pseudo-executes all pending orders, because an order could actually be 1st opening a short and increasing the pseudo-cash reserves.
But this is only pseudo-execution. When the actual execution takes place, the actual cash level is checked again and execution will be rejected if not possible.
@backtrader if you don't mind I would correct your summary slightly:
@ab_trader is looking to use the signals and position sizes provided by bt, and mirror them to broker account by hands. bt will keep position sizes, cash, value and commissions.
In that scenario there is no need to load the positions, cause they are mirrored by trader and are the same in bt and at broker account. In case of the discrepancies bt strategy can be easily adjusted.
The broker is being used for signal and position sizes providing as well as for tracking of the cash and value (no need to support the real broker).
I believe this summary reflects my proposals better. :)
A full exception trace would be a lot more useful than the selected final line, which only says that something hasn't got a length.
The full trace will give hints as to where the error was triggered and not where the error finally happened.
Choosing GPLv3 is a fully conscious decision. What other libraries may or may not do is not of much interest. Each author or organization willing to release open source code weights the pros and cons of different approaches and in this case the GPLv3 was chosen.
Having a license doesn't preclude being able to have a 2nd license for the platform. In most cases this pattern is filled with a direct negotiation between the parties (one interested in an acquisition with a different license, the other willing to re-license) Whether such a pattern fits your case is something which cannot be simply assumed.