I want to backtest a trading strategy + portfolio optimization but I have never used a backtesting program before. I am comfortable with python I think.

My outputs from my trading logic (after portfolio optimization) is a dictionary of stocks to hold in my portfolio each day. I have around 21 days and 50 on each day. No price info. So for example,

dictionary_15march[1] = {'AAPL':15,
                         'BA' : 20,

dictionary_15march[2] = {'AAPL':15,
                         'MSFT': 20,


I have around 50 different combinations of these everyday.

I can convert it into a dataframe as well. 1 dataframe per day.

Is there a way to backtest my strategy with this information?

From the documentation I've seen in backtrader, it can only do simple algorithmic stuff, like buy if today's close is higher than yesterday's close, or moving average crossovers.

Can backtrader take strategies like mine where I provide it how many of a certain stock to buy or sell on a certain day?

If it can't is there a better way to test my strategies?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.