- ago
The Wall Street Journal's Dart Throwing experiment randomly selected stocks by throwing darts at a newspaper's stock page to test random stock picking. I think it would be cool to replicate this in Wealth-Lab by randomly selecting stocks from a given dataset and seeing if it can beat it's benchmark.

Is there a method in Wealth-Lab for random symbol selection in a dataset? Also, we need to consider if the symbol exited the index at some point during its holding, and if it does, have the strategy find a new random position.
0
528
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
QUOTE:
Is there a method in Wealth-Lab for random symbol selection in a dataset?

Please feel free to come up with one, it's not too complex with C#'s support for Random method.

QUOTE:
Also, we need to consider if the symbol exited the index at some point during its holding, and if it does, have the strategy find a new random position.

Wealth-Data takes care of it for the supported indices automatically.
0
- ago
#2
My prediction:
As long as you have a large enough portfolio to choose symbols from, and as long as you choose enough symbols (>20) you'll get (on average) a performance close to the portfolio's (correct) benchmark.

Other details (holding time, etc.) will not have a big influence.

Just make sure exposure is close to 100%.
0
Glitch8
 ( 11.87% )
- ago
#3
Here you go, how's that for service??

Be sure to give it a small margin factor like 1.2 to ensure all entries in case of gaps up.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {       //constructor       public MyStrategy() : base()       {          AddParameter("Number of Symbols", ParameterType.Int32, 10, 1, 100, 1);       }        //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          symsBought.Clear(); } //determine candidate symbols that could be bought on this bar public override void PreExecute(DateTime dt, List<BarHistory> participants) {          //how many symbols should we buy?          int numToBuy = Parameters[0].AsInt - OpenPositionsAllSymbols.Count;          //buy random symbols          if (numToBuy > 0)          {             //get list of candidates             candidates.Clear();             foreach(BarHistory bars in participants)                if (!symsBought.Contains(bars.Symbol))                   candidates.Add(bars);             //divide the available cash to determine how many shares to buy             double cashPerPos = CurrentCash / numToBuy;             Backtester.PositionSize.PositionSizeType = PositionSizeType.Dollar;             Backtester.PositionSize.Amount = cashPerPos;             //buy random symbols from candidates list             while(numToBuy > 0 && candidates.Count > 0)             {                BarHistory buy = candidates.RemoveRandomValue;                numToBuy--;                PlaceTrade(buy, TransactionType.Buy, OrderType.Market);                symsBought.Add(buy.Symbol);             }          } } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { }       //declare private variables below       private static List<string> symsBought = new List<string>();       private static RandomList<BarHistory> candidates = new RandomList<BarHistory>(); } }
0
Best Answer
Cone8
 ( 6.30% )
- ago
#4
The BuyAtMarket block without any condition will give you a random result.

For the test, select a large DataSet like the S&P 500 or a Russell n000.
Use % of Equity Sizing and adjust sizing for the number of positions - e.g., 5% for 20 positions.

Run the result in Monte Carlo-Lab for thousands of trials.
0
Glitch8
 ( 11.87% )
- ago
#5
My Dart Board Strategy code in Post #3 takes care of sizing new Positions based on available cash when symbols exit the index historically. Running it again and again on the Nasdaq 100 and looking at the equity curve, it beats the benchmark QQQ about half the time which is what I'd expect from a dart throwing approach.

0
- ago
#6
Thanks you guys! Very interesting results.
0

Reply

Bookmark

Sort