+ Reply to Thread
Results 1 to 11 of 11

Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Greetings All,

    I am trying to figure out a way to generate a random time series in Excel 2010 between two numbers that can vary. Yes, RANDBETWEEN is good for this, but I want a time series to be generated from a single cell start point (i.e., maybe RANDBETWEEN as a random seed generator), so that I don't have a huge amount of cells that just say "=RANDBETWEEN(min,max)", where all of the cells would be reliant on the static values of "min" and "max" in my worksheet. However, the RANDBETWEEN function can be used in the resultant time series column if they are governed by the starting seed value (not just the min/max values) -- I just can't think of how to get this done.

    The reason that I want the randomization process to happen in this fashion is that I need to incorporate the Solver to manipulate the RANDBETWEEN value to ultimately produce some distribution parameters across the time series, but I am trying to work around the onboard Solver's 200 variable limit, and I may have to work with time series that are well in excess of 200 periods. If I can just have a time series generated by a single seed, it would be highly advantageous.

    Many thanks in advance,

    LBF

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Hello
    RANDBETWEEN only works with whole values >=0. Time values are fractions of 1 so you can use RAND() which takes no arguments but randomizes between 0 and <1. These can be formatted to show as time values.

    DBY

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Hi LBF,

    Perhaps something like:

    =DATE(2015,RANDBETWEEN(1,6),RANDBETWEEN(1,31)) + TIME(RANDBETWEEN(1,24),RANDBETWEEN(0,60),RANDBETWEEN(1,60))

    Where you can set the year and months but still have it randomly pick days and times? See the attached for an example.

    (the site is having problems adding my attachment to this post )
    Attached Files Attached Files
    Last edited by MarvinP; 07-02-2015 at 10:37 AM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    08-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Sorry, what I mean by "time series" is in the statistical sense; basically it's just a series of numbers. Dates and times don't actually come into play...

  5. #5
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,367

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    For random Time

    =TIME(RANDBETWEEN(0,24),RANDBETWEEN(0,59),RANDBETWEEN(0,59))

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    I can't think of a way to get a random sequence of numbers without using RAND (or RANDBETWEEN) in each cell.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Maybe you could explain what you're trying to do.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    08-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    shg,

    At the risk of being too technical, what I'm trying to do is basically generate random series of financial returns that conform to certain distribution parameters so that I can perform skewed Monte Carlo-style simulations with more realistic randomized distributions. For example, suppose I take the S&P500 over some frequency (say, monthly) and with some length of time (say, 30 years) and calculate the descriptive statistics for the data. Specifically, I'll be interested in MIN, MAX, AVERAGE, STDEV, SKEW, KURT, MEDIAN and SUM for what I'm trying to achieve (Note that I AM NOT interested in generating random numbers from a pure normal distribution; I already know how to do this. Also note that I already know the workaround for RANDBETWEEN to get decimalized results to a certain number of decimal places).

    I then want to generate random series of the same length as the original reference series that are constrained as follows:
    • each number in the series is not less than X% below the min, nor more than Y% the max, of the original reference series
    • the series as a whole has the roughly the same mean, standard deviation, skew and excess kurtosis as the original reference series
    • to ensure that the bulk of the distribution is where it is expected, the randomly-generated series should have roughly the same median as the original reference series
    • to ensure data magnitude is not that far from expectation, the new series should roughly sum up to the same amount as the original reference column

    Because of the mathematical complexities involved and limitations of Excel in generating random series this precisely-defined, I believe that I have developed a unique solution using the Frontline Solver in Excel to effectively achieve the results I'm looking for. I am getting very good results when I am working with series below a count of 200 cells (where each one of the "by changing" cells in the Solver dialog box each houses the =RANDBETWEEN(min/max) formula), but then after that I am limited by the Solver's variable limit of 200. If only one cell was changed that could then cause the simulation series to change, then I could manipulate the single cell and not be in violation of the Solver variable limit.

    Ultimately, I plan on creating a function or sub where the Solver will programmatically be called to generate this simulated series, assuming that the user already has a reference to the Solver add-in in Excel.

    Thanks very much!

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    You can create a table with the CDF of the (arbitrarily complex) distribution, and do a lookup (or piecewise-linear interpolation) using a random uniform variable (i.e., RAND()). That method can be used to generate deviates from any distribution.

    For a discussion, see https://en.wikipedia.org/wiki/Invers...ing#The_method
    Last edited by shg; 07-02-2015 at 08:20 PM.

  10. #10
    Registered User
    Join Date
    08-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    shg,

    I spent the better part of last night and this morning exploring your suggestion, and I am intrigued by this approach. I know how to create a CDF (which will obviously be impacted by how I striate the buckets, but that is a separate matter), but I am getting hung up on what the procedure is, in plain language, once I have the CDF of my initial distribution.

    Say I have a cumulative value column created now using the histogram function in the Data Analysis toolpak, and my data is binned in 1% increments. I am now getting stuck on how to mathematically perform the transform that is being described in the link (and many others I have searched). Everyone seems to be implementing this sort of approach in R, but there doesn't seem to be anything about this that Excel can't handle (for smaller distributions, anyhow). Any way you could provide detail?

    Thanks. Also, while I haven't posted much until recently, I have to say that I have benefited greatly from the solutions you have provided to others as an anonymous chronic Googler of VBA solutions over the years. Many thanks in advance.

    LBF

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate Random Time Series using RANDBETWEEN, but NOT with RANDBETWEEN in Each Cell

    Here's a sloppy example for 50 deviates from a normal distribution by interpolation:

    Row\Col
    A
    B
    C
    D
    E
    F
    1
    Mean
    10
    Mean
    9.73
    E1: =AVERAGE(E5:E54)
    2
    SD
    2
    SD
    1.99
    E2: =STDEV(E5:E54)
    3
    4
    P
    NormInv(P)
    RAND()
    Deviate
    5
    0.00001
    1.4702
    B5: =NORMINV(A5, $B$1, $B$2)
    0.8627
    12.198
    E5: =PERCENTILE($B$5:$B$25, PERCENTRANK($A$5:$A$25, D5, 5))
    6
    0.05
    6.7103
    0.6749
    10.909
    7
    0.10
    7.4369
    0.7810
    11.556
    8
    0.15
    7.9271
    0.0212
    3.688
    9
    0.20
    8.3168
    0.3473
    9.215
    10
    0.25
    8.6510
    0.7664
    11.458
    11
    0.30
    8.9512
    0.0727
    7.040
    12
    0.35
    9.2294
    0.6338
    10.685
    13
    0.40
    9.4933
    0.0357
    5.210
    14
    0.45
    9.7487
    0.2690
    8.765
    15
    0.50
    10.0000
    0.3194
    9.059
    16
    0.55
    10.2513
    0.8169
    11.815
    17
    0.60
    10.5067
    0.0884
    7.268
    18
    0.65
    10.7706
    0.4738
    9.868
    19
    0.70
    11.0488
    0.7773
    11.531
    20
    0.75
    11.3490
    0.7695
    11.479
    21
    0.80
    11.6832
    0.2020
    8.330
    22
    0.85
    12.0729
    0.2327
    8.535
    23
    0.90
    12.5631
    0.4085
    9.537
    24
    0.95
    13.2897
    0.1250
    7.682
    25
    0.99999
    18.5298
    0.0920
    7.321
    26
    0.6530
    10.788
    27
    0.4410
    9.703
    28
    0.1580
    7.990
    29
    0.1950
    8.277
    30
    0.1763
    8.132
    31
    0.5210
    10.105
    32
    0.7391
    11.284
    33
    0.4538
    9.768
    34
    0.7381
    11.277
    35
    0.7621
    11.430
    36
    0.9326
    13.036
    37
    0.4151
    9.570
    38
    0.3918
    9.450
    39
    0.7031
    11.067
    40
    0.1312
    7.743
    41
    0.2067
    8.361
    42
    0.1169
    7.603
    43
    0.4358
    9.676
    44
    0.9214
    12.875
    45
    0.7858
    11.588
    46
    0.2388
    8.576
    47
    0.3763
    9.368
    48
    0.6529
    10.787
    49
    0.7644
    11.445
    50
    0.9164
    12.802
    51
    0.6006
    10.510
    52
    0.4814
    9.906
    53
    0.1206
    7.639
    54
    0.9160
    12.795


    But again, the inverse CDF could be for ANY distribution.
    Last edited by shg; 07-03-2015 at 04:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HELP: How to get random data from a 'table' using 'randbetween'
    By faizzsheikh in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2015, 08:03 PM
  2. Using Randbetween to generate specific amounts of numbers
    By ryanch69 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-31-2014, 08:41 AM
  3. Randbetween or Random Number (1,3)
    By itselflearn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-27-2013, 02:34 PM
  4. Replies: 8
    Last Post: 09-21-2011, 06:50 PM
  5. Random numbers not using randbetween()
    By davehill1974 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-07-2005, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1