Lean  $LEAN_TAG$
FinancialStatementsFormType.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2023 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 
17 using System;
18 using System.Linq;
19 using Python.Runtime;
20 using Newtonsoft.Json;
21 using System.Collections.Generic;
23 
25 {
26  /// <summary>
27  /// The type of filing of the report: for instance, 10-K (annual report) or 10-Q (quarterly report).
28  /// </summary>
30  {
31  /// <summary>
32  /// The default period
33  /// </summary>
34  protected override string DefaultPeriod => "ThreeMonths";
35 
36  /// <summary>
37  /// Gets/sets the OneMonth period value for the field
38  /// </summary>
39  [JsonProperty("1M")]
40  public string OneMonth => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_OneMonth);
41 
42  /// <summary>
43  /// Gets/sets the TwoMonths period value for the field
44  /// </summary>
45  [JsonProperty("2M")]
46  public string TwoMonths => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_TwoMonths);
47 
48  /// <summary>
49  /// Gets/sets the ThreeMonths period value for the field
50  /// </summary>
51  [JsonProperty("3M")]
52  public string ThreeMonths => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_ThreeMonths);
53 
54  /// <summary>
55  /// Gets/sets the SixMonths period value for the field
56  /// </summary>
57  [JsonProperty("6M")]
58  public string SixMonths => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_SixMonths);
59 
60  /// <summary>
61  /// Gets/sets the NineMonths period value for the field
62  /// </summary>
63  [JsonProperty("9M")]
64  public string NineMonths => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_NineMonths);
65 
66  /// <summary>
67  /// Gets/sets the TwelveMonths period value for the field
68  /// </summary>
69  [JsonProperty("12M")]
70  public string TwelveMonths => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_TwelveMonths);
71 
72  /// <summary>
73  /// Returns true if the field contains a value for the default period
74  /// </summary>
75  public override bool HasValue => !BaseFundamentalDataProvider.IsNone(typeof(string), FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_ThreeMonths));
76 
77  /// <summary>
78  /// Returns the default value for the field
79  /// </summary>
80  public override string Value
81  {
82  get
83  {
84  var defaultValue = FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_FormType_ThreeMonths);
85  if (!BaseFundamentalDataProvider.IsNone(typeof(string), defaultValue))
86  {
87  return defaultValue;
88  }
89  return base.Value;
90  }
91  }
92 
93  /// <summary>
94  /// Gets a dictionary of period names and values for the field
95  /// </summary>
96  /// <returns>The dictionary of period names and values</returns>
97  public override IReadOnlyDictionary<string, string> GetPeriodValues()
98  {
99  var result = new Dictionary<string, string>();
100  foreach (var kvp in new[] { new Tuple<string, string>("1M", OneMonth), new Tuple<string, string>("2M", TwoMonths), new Tuple<string, string>("3M", ThreeMonths), new Tuple<string, string>("6M", SixMonths), new Tuple<string, string>("9M", NineMonths), new Tuple<string, string>("12M", TwelveMonths) })
101  {
102  if (!BaseFundamentalDataProvider.IsNone(typeof(string), kvp.Item2))
103  {
104  result[kvp.Item1] = kvp.Item2;
105  }
106  }
107  return result;
108  }
109 
110  /// <summary>
111  /// Gets the value of the field for the requested period
112  /// </summary>
113  /// <param name="period">The requested period</param>
114  /// <returns>The value for the period</returns>
115  public override string GetPeriodValue(string period) => FundamentalService.Get<string>(TimeProvider.GetUtcNow(), SecurityIdentifier, Enum.Parse<FundamentalProperty>($"FinancialStatements_FormType_{ConvertPeriod(period)}"));
116 
117  /// <summary>
118  /// Creates a new empty instance
119  /// </summary>
121  {
122  }
123 
124  /// <summary>
125  /// Creates a new instance for the given time and security
126  /// </summary>
127  public FinancialStatementsFormType(ITimeProvider timeProvider, SecurityIdentifier securityIdentifier) : base(timeProvider, securityIdentifier)
128  {
129  }
130  }
131 }