Questions tagged [backtrader]

backtrader is a python backtesting library for trading strategies

107 questions
1
vote
1 answer

How to backtest portfolio compositions using backtrader?

I have a csv file / pandas dataframe which looks like this. It contains various portfolio compositions for a portfolio which is re-balanced everyday according to my own calculations. date asset percentage 4-Jan-21 AAPL 12.00% 4-Jan-21…
anarchy
  • 3,709
  • 2
  • 16
  • 48
1
vote
1 answer

Backtrader problems in resampling to daily

Using backtrader, I would like to retrieve quotes at a five minute scale and resample at a daily scale. I am able to resample five minutes to sixty minutes, but can't do daily. Here is the code: from __future__ import absolute_import, division,…
rajah9
  • 11,645
  • 5
  • 44
  • 57
1
vote
2 answers

Backtesting a portfolio in Python

I am trying to do a backtest on a Markowitz portfolio. So far I've tried zipline, backtrader and QSTrader (although QSTrader may work, but there is no documentation so its very hard). I haven't had any luck with creating the backtest as I've…
sword134
  • 91
  • 1
  • 11
1
vote
0 answers

Backtrader giving IndexError: array assignment index out of range

I am trying to run the following strategy: def max_n(array, n): return np.argpartition(array, -n)[-n:] class CrossSectionalMR(bt.Strategy): params = ( ('num_positions', 100), ) def __init__(self, temp): self.inds =…
Pob Livsig
  • 95
  • 1
  • 9
1
vote
0 answers

Child class not inheriting from parent class

I currently have a: parent class, called bt.strategy (which is a default class in the Backtrader library) child class, called Strategy (which inherits from bt.strategy) child of a child class, called OpeningVolHigh (which inherits from Strategy) I…
01jayss
  • 1,400
  • 6
  • 19
  • 28
1
vote
1 answer

when running backtest and buying I always get Order Canceled/Margin/Rejected

I've just started using backtrader. I've fetched 1min candles data from pandas dataframe. When running backtrader I get this log message after every buy order: "Order Canceled/Margin/Rejected" I'm using jupyter notebook This is my trading…
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
1
vote
1 answer

Why am I receiving this error using BackTrader on Python?

I am trying to learn how to use the backtrader module on Python. I copied the code directly from the website but receiving an error message. Here is the website: https://www.backtrader.com/docu/quickstart/quickstart/ I downloaded S&P500 stock data…
Able Archer
  • 579
  • 5
  • 19
1
vote
3 answers

Python Backtrader Error: FileNotFoundError: [Errno 2] No such file or directory: 'AAPL'

I am trying to use the backtrader package in Python 3.8 to run a backtest on AAPL historical stock prices obtained from Yahoo Finance using backtrader's YahooFinanceData module. Problem: The data appears to be downloaded from Yahoo Finance, but…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
0
votes
0 answers

VWAP-session/Day based

I have this code: https://pastebin.com/n9QHrHN7 What should he do?: This code should only draw the VWAP indicator for me, which it does! what is the problem?: The VWAP indicator is there but I want to use it on a daily basis. This means that the…
0
votes
0 answers

Unusual results in 5 EMA sell strategy pine script

I am using the below code for the 5 EMA sell strategy - POS backtesting. When i see the list of trades, i feel there are some exits which were taken randomly and other were ok. I dont understand where the problem is in the code or trading veiw. Can…
0
votes
0 answers

AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'signal_add'

hi i have a big problem please help me the error is Attributes Error lines i have alredy use ( 'matplotlib.use'("Qt5Agg")) but nothin !pip install matplotlib==3.2.2 !pip install backtrader !pip install yfinance from datetime import datetime import…
Ryan99
  • 1
0
votes
0 answers

I can not simulate TradingView in backtrader: ROI mismatch for same strategy

I got data of 'TSLA' with yfinance library for same period of TradingView platform StrategyTester assumes. For example I have used RSI_SMA Strategy with 14 period parameters in both. Here is the parameters: Interval is 1 minute for both of…
mece1390
  • 161
  • 2
  • 13
0
votes
0 answers

ta-lib ATR method number of arguments error

i am re-using a code which calculates trailing stop of a trade strategy def calculate_trailing_stop(): xATR = talib.ATR(list(src), atrperiod) here atrperiod is 10 and src is an array of last 10 samples. when I run this program I got following…
0
votes
0 answers

Adding constituent lists to a backtrader strategy in python

I am able to make a strategy in backtrader which equally invest in stocks based on a yearly constituent list. But if I change the code to monthly constituent lists the portfolio value remains the same. I cannot find what the problem is and how there…
jondej
  • 1
0
votes
2 answers

Identifying minor swings with major swings - Price charts

I am developing a stock analysis program in Python One of the fundamental things I need to is to recognise swings from price feed (open, high, low, close data) Price data is fractal by nature - smaller structures are found within larger…