How to setup the point step and point value for data?
-
Hi:
I am new to backtrader. I read through the documents but I didn't find where to setup the point step and point value for a series of data.
Without the point value, how can backtrader get the accurate profit result?
Anyone helps me please?
Thanks
-
That seems very specific Forex jargon and it seems that people argue heavily about the definitions of pip, pipette.
What is your expectation with regards to point value and *point step?
Things you can control with backtrader without development:
-
leverage
-
multiplier
The
multiplier
can be used directly with the broker and the asset will simulated as a kind offutures-like
instrument. Probably what you are looking for.For specific use cases one can create a specific
CommissionInfo
subclass which control all aspects of how an asset is priced and what commissions apply to the operation. -
-
The reason is that different instrument may have different minimum ticksize and ambiguous tickvalue.
For example, as a stock index, the minimum price tick is 0.2 and the 1 tick money value is 20( just for example), but the minimum tick price for a commodity future may be 1 and the money equals to that is 10.Without that specification, it would be unrealistic to measure the strategy performance and hence the portofio performance will not be able to judge.
I haven't gone through the multiplier and leverage yet. I will see if this can meet the requirement.
Thanks
-
You seem them much more concerned with future-like instruments. Let's examine some different well-known possibilities with futures for stock indices:
-
ES Mini Future
Minimum movement: 0.25
Minimum movement value: $12.50
Which means that a 1 point multiplier is: $50.00 -
EuroStoxx 50 Future
Minimum movement: 1.00
Minimum movement value: €10.00
Which means that a 1 point multiplier is: €10.00
In all those well known futures, there is a minimum movement defined, but the multiplier (or point value) is always defined in terms of a full point
Quickly looking at another type of future:
Corn Future
Minimum movement value: €12.50
Which means that a 1 point multiplier is: €50.00
In backtrader you configure the
1 point
multiplier. You add the expected margin.See for example here how to set the commission to have future likes type: Docs - Commissions: Stocks vs Futures
In the two posts above you are concerned about the accuracy of backtrader. It tries to be accurate to the point that when backtesting with a future-like instrument, cash is added/deducted from the account with each bar, just as it happens with a real broker.
-
-
I read through the Docs about the commisions stocks vs futures.
But I am still confusing about two things.
-
as BackTrader doesn't define the minimum movement. It would be impossible to execute trade accurately. For example, a Corn trade may be opened as $3011 and close at $3113.3. In this case, no matter how multiplier is set, it would be a wrong profit.
-
I don't quite get the meaning of the margin in the parameter. Say an instrument price is 4000, and the magin is set to 2000, it should be equivalent to a leverage of 50%, is that right? But in reality leverage is defined as a percentage but not a fixed value, the margin should vary as the price movement.
Is there any suggestions about the accuracy please?
Thanks
-
-
@asuralm said in How to setup the point step and point value for data?:
- as BackTrader doesn't define the minimum movement. It would be impossible to execute trade accurately. For example, a Corn trade may be opened as $3011 and close at $3113.3. In this case, no matter how multiplier is set, it would be a wrong profit.
The calculation will be right, because your input for the multiplier (as in the example above) has to be for the entire point. The
ES-Mini
moves in0.25
ticks, but the input multiplier is50
which is for a full point.- I don't quite get the meaning of the margin in the parameter. Say an instrument price is 4000, and the magin is set to 2000, it should be equivalent to a leverage of 50%, is that right? But in reality leverage is defined as a percentage but not a fixed value, the margin should vary as the price movement.
Margin is NOT leverage. It's the amount of cash you need to enter a position in a future-like instrument.
Margin requirements can be automatically controlled with the param
automargin
to aCommissionInfo
instance which you may apply to your assets. The reference is in the same link as above: Docs - Commissions: Stocks vs FuturesIf the policy defined there doesn't fit your use case, you can define your own by subclassing.
-
-
ES Mini Future
Minimum movement: 0.25
Minimum movement value: $12.50
Which means that a 1 point multiplier is: $50.00 -
EuroStoxx 50 Future
Minimum movement: 0.25
Minimum movement value: €10.00
Which means that a 1 point multiplier is: €10.00
In this example, should the second example multiplier be 10.00/0.25 = 40 instead of 10?
@asuralm said in How to setup the point step and point value for data?:
- as BackTrader doesn't define the minimum movement. It would be impossible to execute trade accurately. For example, a Corn trade may be opened as $3011 and close at $3113.3. In this case, no matter how multiplier is set, it would be a wrong profit.
I am not sure if my understanding of the platform is accurate enough. But let's consider the following case:
In this example, let's use the ES-Mini instead as an example,
assume I set the multiplier = 50, and we trade ES Mini because the minimum price movement is 0.25, then theoretically, there are only 3 prices between 998 to 999 which are 998.25, 998.50 and 998.75. As backtrader doesn't specify the minimum price movement, then I am able to set a stop price to 998.7, however, the price never exist in reality. Assume I long ES-Mini @ 1000, and place stop @ 998.7 with 10 lot for simplicity. In reality, the order will be stopped @ 998.5 and the loss should be 750. But because I can set the stop loss to a non-existing price 998.7, the loss will be calculate as (1000-998.7)*50 *10=650 , which clearly a horrible mistake. -
-
@asuralm said in How to setup the point step and point value for data?:
In this example, should the second example multiplier be 10.00/0.25 = 40 instead of 10?
That was a typo from copy and paste. It has been corrected. The minimum movement is 1.00
then I am able to set a stop price to 998.7
It is your choice to do it. If you send wrong prices to the platform, you will get wrong results.
Yes, backtrader could have a formula for each and every case in the world but it doesn't (at least yet)
The front page of the repository has a listing with several other open source Python platforms you may choose from if they better suit your needs. Namely:
Alternatives
If after seeing the docs and some samples (see the blog also) you feel this is not your cup of tea, you can always have a look at similar Python platforms:- PyAlgoTrade https://github.com/gbeced/pyalgotrade
- Zipline https://github.com/quantopian/zipline
- Ultra-Finance https://code.google.com/p/ultra-finance/
- ProfitPy https://code.google.com/p/profitpy/
- pybacktest https://github.com/ematvey/pybacktest
- prophet https://github.com/Emsu/prophet
- quant https://github.com/maihde/quant
- AlephNull https://github.com/CarterBain/AlephNull
- Trading with Python http://www.tradingwithpython.com/
- visualize-wealth https://github.com/benjaminmgross/visualize-wealth
- tia: Toolkit for integration and analysis https://github.com/bpsmith/tia
- QuantSoftware Toolkit http://wiki.quantsoftware.org/index.php?title=QuantSoftware_ToolKit
- Pinkfish http://fja05680.github.io/pinkfish/
- bt http://pmorissette.github.io/bt/index.html
- PyThalesians https://github.com/thalesians/pythalesians
- QSTrader https://github.com/mhallsmoore/qstrader/
- QSForex https://github.com/mhallsmoore/qsforex
- pysystemtrade https://github.com/robcarver17/pysystemtrade
- QTPyLib https://github.com/ranaroussi/qtpylib
- RQalpha https://github.com/ricequant/rqalpha
And there are for sure a couple others which have not yet been spotted.
-
This can be easily solved if you set min price movement and price movement value as a top level constants. Then the
multiplier
can be calculated based on this data and set withCommissionInfo
. Also these constants can be used to calculate appropriate price levels forstop
andlimit
orders based on your rules. -
If after seeing the docs and some samples (see the blog also) you feel this is not your cup of tea, you can always have a look at similar Python platforms:
@backtrader
I don't mean to challenge or attack backtrader. Actually I have compared those open source platforms and finally decide to use backtrader. To me backtrader is very well structured and easy to use. However, I am new to backtrader platform so I want the configurations are correct before I actually do the testing. Hope you don't misunderstand :-)set a stop price to 998.7
It is your choice to do it. If you send wrong prices to the platform, you will get wrong results.Actually I don't think this is a unusual case. If I open an order and place the stop according to a percentage, it will for sure happens quite often.
-
@ab_trader said in How to setup the point step and point value for data?:
This can be easily solved if you set min price movement and price movement value as a top level constants. Then the
multiplier
can be calculated based on this data and set withCommissionInfo
. Also these constants can be used to calculate appropriate price levels forstop
andlimit
orders based on your rules.This seems a clever way to get this issue solved. It seems that the top level constant should contain both the minimum movement and the minimum value. Is that right? It would be better if you can give me an example please?
Thanks
-
@asuralm Ok. Concept:
# set tick size and tick value for ES contract TICK_DATA = {'tick': 0.25, 'tick_value': 12.5} # set commission scheme mult = TICK_DATA['tick_value'] / TICK_DATA['tick'] commES = bt.CommissionInfo(commission=3.0, margin=5000.0, mult=mult) # add commission to broker cerebro.broker.addcommissioninfo(commES, name='ES') # example of stop price calculation based on % of buy price risk = 2.0 # risk in %s of BuyPrice risk_ticks = BuyPrice * risk / 100 // TICK_DATA['tick'] # risk in ticks StopPrice = BuyPrice - risk_ticks * TICK_DATA['tick'] # stop rpice
-
@ab_trader
That's really nice of you.
Thanks very much!!! -
@gminorcoles I am just a user of the
bt
, not an owner. Sometimes I share pieces of the code. @backtrader is an owner.if you want/can offer any enhancements, then just create pull request with that enhancement. @backtrader will check it and incorporate if it will be suitable from his point of view.