before I start backtesting, may I hold some stock share?
As I can set cash at the begining, can I set a stock share like this?
cerebro.broker.set_position(size=10, price=100)
before I start backtesting, may I hold some stock share?
As I can set cash at the begining, can I set a stock share like this?
cerebro.broker.set_position(size=10, price=100)
Share
Improve this question
asked Mar 19 at 2:58
Alightor LiAlightor Li
715 bronze badges
1 Answer
Reset to default 0Yes, you can use order history for that.
# must be sorted ascending
# (datetime, size, prize, data)
ORDER_HISTORY = (('2012-04-11', 10, 100, 'AAPL'),)
cerebro = bt.Cerebro()
cerebro.adddata(data=bt.feeds.PandasData(dataname=aapl,),name='AAPL')
cerebro.add_order_history(ORDER_HISTORY)
cerebro.addstrategy(Strat)
cerebro.run()
for more information check this post out:
https://www.backtrader/blog/posts/2017-07-05-order-history/order-history/