Back to Community
Is this even normal?

I am new to the topic of Algorithmic Trading but such an easy strategy of following BB breakouts seems to show fascinating results on the benchmark. My question is-Did the benchmark went wild or the actual algorithm is that efficient?

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5846b8e159ce4d62a39dfd43
There was a runtime error.
3 responses

The short answer to your question is 'no, that's not normal'. If you ever see sky high returns the first place to check is your leverage.

Attached is your algorithm but added a record of the account leverage. Look at the full backtest results and notice the 'custom data' graph. The leverage is all over the place and even goes as high as 19,000. Typically start by keeping your leverage around 1 to get an idea of performance.

Your error is that you keep ordering 5000 shares of stock without regard to whether you actually have the cash on hand. The backtest engine will happily fill your request and just assume you are Warren Buffet with unlimited funds. An easy way to ensure you don't 'over order' is to use the 'order_target_percent' function ( see documentation https://www.quantopian.com/help#api-order-target-percent ).

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5846bdadc28723637f82a624
There was a runtime error.

Greetings Dan!
Thank you for the advice. I though that it was something to do with the leverage, is it possible to make a function for dynamic change in leverage? For example-I don't want sky levels of leverage in the high volatile markets.

Yes, you can vary your leverage, but typically start with a fixed leverage (of 1). Change that later if you want to fine tune your algorithm. You will realistically only be adjusting it between 1-3 (3 is the max that Quantopian allows for their contest and brokers will only allow most of us mortals leverage less than 2).

One approach is to not think in terms of quantity of shares or dollars when ordering securities. Rather, your algorithm determines the percent of the total portfolio value, or weight, you want your security to represent. Orders can then be easily placed with desired leverage and stock weight using the 'order_target_percent' method.

order_target_percent(my_stock, leverage * my_stock_weight )  

'leverage' and 'my_stock_weight' can be constants or can be dynamically adjusted by your algorithm. As long as you ensure the sum of all the 'my_stock_weight's equals 1 you will keep your leverage to the desired level.

One caution. The 'order_target_percent' method does NOT account for any outstanding orders. It's generally good practice to not place an order for a security if there are already orders open. If you trade once a day, this isn't an issue since all orders on Quantopian are canceled at the end of the day.