Lean  $LEAN_TAG$
MovingAverageTypeExtensions.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 
16 using System;
17 
19 {
20  /// <summary>
21  /// Provides extension methods for the MovingAverageType enumeration
22  /// </summary>
23  public static class MovingAverageTypeExtensions
24  {
25  /// <summary>
26  /// Creates a new indicator from the specified MovingAverageType. So if MovingAverageType.Simple
27  /// is specified, then a new SimpleMovingAverage will be returned.
28  /// </summary>
29  /// <param name="movingAverageType">The type of averaging indicator to create</param>
30  /// <param name="period">The smoothing period</param>
31  /// <returns>A new indicator that matches the MovingAverageType</returns>
32  public static IndicatorBase<IndicatorDataPoint> AsIndicator(this MovingAverageType movingAverageType, int period)
33  {
34  switch (movingAverageType)
35  {
36  case MovingAverageType.Simple:
37  return new SimpleMovingAverage(period);
38 
39  case MovingAverageType.Exponential:
40  return new ExponentialMovingAverage(period);
41 
42  case MovingAverageType.Wilders:
43  return new WilderMovingAverage(period);
44 
45  case MovingAverageType.LinearWeightedMovingAverage:
46  return new LinearWeightedMovingAverage(period);
47 
48  case MovingAverageType.DoubleExponential:
49  return new DoubleExponentialMovingAverage(period);
50 
51  case MovingAverageType.TripleExponential:
52  return new TripleExponentialMovingAverage(period);
53 
54  case MovingAverageType.Triangular:
55  return new TriangularMovingAverage(period);
56 
57  case MovingAverageType.T3:
58  return new T3MovingAverage(period);
59 
60  case MovingAverageType.Kama:
61  return new KaufmanAdaptiveMovingAverage(period);
62 
63  case MovingAverageType.Hull:
64  return new HullMovingAverage(period);
65 
66  case MovingAverageType.Alma:
67  return new ArnaudLegouxMovingAverage(period);
68 
69  default:
70  throw new ArgumentOutOfRangeException(nameof(movingAverageType));
71  }
72  }
73 
74  /// <summary>
75  /// Creates a new indicator from the specified MovingAverageType. So if MovingAverageType.Simple
76  /// is specified, then a new SimpleMovingAverage will be returned.
77  /// </summary>
78  /// <param name="movingAverageType">The type of averaging indicator to create</param>
79  /// <param name="name">The name of the new indicator</param>
80  /// <param name="period">The smoothing period</param>
81  /// <returns>A new indicator that matches the MovingAverageType</returns>
82  public static IndicatorBase<IndicatorDataPoint> AsIndicator(this MovingAverageType movingAverageType, string name, int period)
83  {
84  switch (movingAverageType)
85  {
86  case MovingAverageType.Simple:
87  return new SimpleMovingAverage(name, period);
88 
89  case MovingAverageType.Exponential:
90  return new ExponentialMovingAverage(name, period);
91 
92  case MovingAverageType.Wilders:
93  return new WilderMovingAverage(name, period);
94 
95  case MovingAverageType.LinearWeightedMovingAverage:
96  return new LinearWeightedMovingAverage(name, period);
97 
98  case MovingAverageType.DoubleExponential:
99  return new DoubleExponentialMovingAverage(name, period);
100 
101  case MovingAverageType.TripleExponential:
102  return new TripleExponentialMovingAverage(name, period);
103 
104  case MovingAverageType.Triangular:
105  return new TriangularMovingAverage(name, period);
106 
107  case MovingAverageType.T3:
108  return new T3MovingAverage(name, period);
109 
110  case MovingAverageType.Kama:
111  return new KaufmanAdaptiveMovingAverage(name, period);
112 
113  case MovingAverageType.Hull:
114  return new HullMovingAverage(name, period);
115 
116  case MovingAverageType.Alma:
117  return new ArnaudLegouxMovingAverage(name, period);
118 
119  default:
120  throw new ArgumentOutOfRangeException(nameof(movingAverageType));
121  }
122  }
123  }
124 }