December 30, 2022, 7:40pm
In Python you can set a range for random number. A specific example would be:
Better would be to make a random seed available for example:
For rank performance adding a small random number to a factor would make each bucket have the same number of stocks. Useful for the problem posted here:
'Clustered' ranking output - #7 by Jrinne
With the seed it could be used to select a sub-universe of stocks. Many people do this using mod() now. The problem with mod is that sometimes the sub-universe is very small and can be used only a limited number of times before exhaustion creative uses of mod(). See this link for a discussion of this problem:
How to choose a ranking system? A or B - #6 by test_user
How would one create a random integer between MIN and MAX?
This almost works if I could lop off the decimal portion, like python’s int() does.
@rand:(Random * (MAX - MIN) + 1)
for example where MAX = 5 and MIN = 1 would give me a random number between 1 and 5
But even this isn’t really right because it would only very rarely give me 5, only when Random() returned a 1.
I just found this thread from Marco that I think does what I am trying to do.
There’s been a lot of talk about robustness test, Monte Carlo sims, etc. Has anybody tried using the Random function in a buy Rule ?
For example in a 10 stock simulation simply add this Buy Rule:
Random < 0.9
This rule will throw out 1 rec out of 10 on average and produce different results every time the sim is run.
See the image below. It’s an Optimizer run that has exactly the same parameters that is basically generating a Montecarlo-ish output. Annual returns range from 25-33%, DDowns fro…
But I am still curious if a random int can be generated.
This is what I was trying to come up with in order to do some kind of monte carlo cross-validation. Marco’s idea is far simpler.
setvar( @Min, 1)
mod(StockID, 5) = @TrueRand