Simples Framework to Backtest Strategies using pandas
- Installation
- Calculating a factor using zscore
- Calculating Buy and Sell signals
- Calculate a Higher Timeframe using a Lower Timeframe
pip install pandasbt
import pandasbt as pbt
df_test = pd.DataFrame([
{"close": 25}, {"close": 15}, {"close": 41}, {"close": 7},
{"close": 5}, {"close": 115}, {"close": 45}, {"close": 32},
])
pbt.zscore(df_test, period=20)
or you can specify the column
pbt.zscore(df_test, 20, "close")
That mean add a signal column into dataframe.
0 - means nothing
-1 - means sell
1 - means buy
import pandasbt as pbt
df_test = pd.DataFrame([
{"close": 25}, {"close": 15}, {"close": 41}, {"close": 7},
{"close": 5}, {"close": 115}, {"close": 45}, {"close": 32},
])
pbt.calc_signal(df_test, buy_query="close > 20", sell_query="close < 10")
import pandasbt as pbt
pbt.build_timeframe(df_test, timeframe="M5)