For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
'Series' object has no attribute 'columns'
-
Hi there,
I am using the bt.Backtest(bt_strategy, price_data)
For price_data I am trying to use a Data Frame of my own, extracted from a broker (Oanda) in order to test on batches of timeframes and instruments I want.
The only thing is after edits of the Dataframe in order to make it similar to the bt.get option my price_data which stores the Dataframe doesn't work and gives me the following error: 'Series' object has no attribute 'columns'
#I changed the index format to make my strategy with BT work EURUSD_df.index=pd.to_datetime(EURUSD_df.index, format = '%Y-%m-%d').strftime('%Y-%m-%d') EURUSD_df.tail() close high low open 2018-12-27 1.14448 1.14728 1.14271 1.14296 2018-12-30 1.14649 1.14696 1.14216 1.14372 2019-01-01 1.13447 1.14970 1.13250 1.14649 2019-01-02 1.13942 1.14112 1.13077 1.13431 2019-01-03 1.13951 1.14191 1.13457 1.13930 import talib !pip install bt import bt import matplotlib.pyplot as plt EMA_short=talib.EMA(EURUSD_df['close'],timeperiod=10).to_frame() EMA_long=talib.EMA(EURUSD_df['close'],timeperiod=40).to_frame() signal=EMA_long.copy() signal[EMA_long.isnull()]=0 signal[EMA_short>EMA_long]=1 signal[EMA_short<EMA_long]=-1 combined_df=bt.merge(signal,EURUSD_df["close"],EMA_short,EMA_long) combined_df.columns=["Signal","Price","EMA_short","EMA_long"] combined_df.plot(secondary_y=["Signal"]) print(EURUSD_df[['close']]) #EURUSD_df=EURUSD_df['close'].reset_index #print(EURUSD_df['close']) price_data=EURUSD_df['close'] price_data=price_data.append(pd.Series(name='NameOfNewRow')) print(price_data) bt_strategy = bt.Strategy('EMA_crossover', [bt.algos.WeighTarget(signal), bt.algos.Rebalance()]) bt_backtest = bt.Backtest(bt_strategy,price_data) bt_result = bt.run(bt_backtest) bt_result.plot(title='Backtest result')
Can someone help/guide me, please?
Much appreciated!
Ciprian
-
@nairpic I think you are in the wrong forum.
pip install bt
is not backtrader, it's bt. https://github.com/pmorissette/bt