Lean  $LEAN_TAG$
IRandomValueGenerator.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
17 using System;
18 
20 {
21  /// <summary>
22  /// Defines a type capable of producing random values for use in random data generation
23  /// </summary>
24  /// <remarks>
25  /// Any parameters referenced as a percentage value are always in 'percent space', meaning 1 is 1%.
26  /// </remarks>
27  public interface IRandomValueGenerator
28  {
29  /// <summary>
30  /// Randomly return a <see cref="bool"/> value with the specified odds of being true
31  /// </summary>
32  /// <param name="percentOddsForTrue">The percent odds of being true in percent space, so 10 => 10%</param>
33  /// <returns>True or false</returns>
34  bool NextBool(double percentOddsForTrue);
35 
36  /// <summary>
37  /// Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0
38  /// </summary>
39  /// <returns>A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.</returns>
40  double NextDouble();
41 
42  /// <summary>
43  /// Returns a random integer that is within a specified range.
44  /// </summary>
45  /// <param name="minValue">the inclusive lower bound of the random number returned</param>
46  /// <param name="maxValue">the exclusive upper bound of the random number returned</param>
47  /// <returns>A 32-bit signed integer greater than or equal to minValue and less than maxValue.</returns>
48  int NextInt(int minValue, int maxValue);
49 
50  /// <summary>
51  /// Returns a non-negative random integer that is less than the specified maximum.
52  /// </summary>
53  /// <param name="maxValue">the exclusive upper bound of the random number to be generated.</param>
54  /// <returns>A 32-bit signed integer that is greater than or equal to 0, and less than maxValue.</returns>
55  int NextInt(int maxValue);
56 
57  /// <summary>
58  /// Generates a random <see cref="DateTime"/> between the specified <paramref name="minDateTime"/> and
59  /// <paramref name="maxDateTime"/>. <paramref name="dayOfWeek"/> is optionally specified to force the
60  /// result to a particular day of the week
61  /// </summary>
62  /// <param name="minDateTime">The minimum date time, inclusive</param>
63  /// <param name="maxDateTime">The maximum date time, inclusive</param>
64  /// <param name="dayOfWeek">Optional. The day of week to force</param>
65  /// <returns>A new <see cref="DateTime"/> within the specified range and optionally of the specified day of week</returns>
66  DateTime NextDate(DateTime minDateTime, DateTime maxDateTime, DayOfWeek? dayOfWeek);
67 
68  /// <summary>
69  /// Generates a random <see cref="decimal"/> suitable as a price. This should observe minimum price
70  /// variations if available in <see cref="SymbolPropertiesDatabase"/>, and if not, truncating to 2
71  /// decimal places.
72  /// </summary>
73  /// <exception cref="ArgumentException">Throw when the <paramref name="referencePrice"/> or <paramref name="maximumPercentDeviation"/>
74  /// is less than or equal to zero.</exception>
75  /// <param name="securityType">The security type the price is being generated for</param>
76  /// <param name="market">The market of the security the price is being generated for</param>
77  /// <param name="referencePrice">The reference price used as the mean of random price generation</param>
78  /// <param name="maximumPercentDeviation">The maximum percent deviation. This value is in percent space,
79  /// so a value of 1m is equal to 1%.</param>
80  /// <returns>A new decimal suitable for usage as price within the specified deviation from the reference price</returns>
81  decimal NextPrice(SecurityType securityType, string market, decimal referencePrice, decimal maximumPercentDeviation);
82 
83  }
84 }