Back to Posts
Listen to Thread

The goal behind this algorithm was to invest in a broad range of stocks, eliminate the ones that aren't doing well, and "double down" on the ones that are. I used 60k as the initial capital because I wanted to try and create a realistic strategy. I also ran this algorithm with a higher starting capital of $1M and buying shares in blocks of 100, which also showed high returns, peaking at 16x, and ending at 10x.

The stop loss price is set as a function of the rate of return, and trails the current price so as to lock in a profit in the event that the price of a particular security starts dropping.

There is a lot that could be done to further improve this algorithm, some of my initial thoughts:
- Refine initial investment criteria to pick fewer losers.
- Set a initial timeframe during which a stock must go up a certain % otherwise it is sold as a "loser"
- Optimize the setting of the stop loss price
- Testing on a wider range of stocks and time frames

Additionally, this algorithm works best (perhaps only?) during bull markets since it only goes long (hence the start date of 2010). You could probably modify to go short as well, particularly if it started to sense the portfolio as whole a starting to see negative returns.

Clone Algorithm
155
Loading...
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Week
Month
All
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Information Ratio
--
Benchmark Returns
--
Volatility
--
Max Drawdown
--
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

Another thing this algo would benefit from is more strict cash management/order limits. I cloned it and ran a copy, and it leveraged hundreds of thousands of dollars on the $60k initial investment. Check out the sample algorithm, and you'll see it includes some language about calculating the notional value of the portfolio, and orders can only be placed if the notional is within limits. That would make your algo closer to tradeable.

I should have started with: Nice algo! I liked reading it, it has some neat ideas.

HI Dan and Brad
Great community and work
Dan is there a link for the sample algo that you created?
Thank You
Ron

On the front page, under the Test heading, there is an option to clone a sample algorithm. This includes the context.min_notional and context.max_notional that Dan is referring to.

Dan, thanks for the feedback. Limits were definitely something I overlooked.

Here is the sample algo. And here are more samples, on several of the API features, in the help doc.

Log in to reply to this thread.
Not a member? Sign up!