Lean  $LEAN_TAG$
ConvertibleLoansCurrentBalanceSheet.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  /// This represents loans that entitle the lender (or the holder of loan debenture) to convert the loan to common or preferred stock (ordinary or preference shares) within the next 12 months or operating cycle.
28  /// </summary>
30  {
31  /// <summary>
32  /// The default period
33  /// </summary>
34  protected override string DefaultPeriod => "TwelveMonths";
35 
36  /// <summary>
37  /// Gets/sets the TwelveMonths period value for the field
38  /// </summary>
39  [JsonProperty("12M")]
40  public double TwelveMonths => FundamentalService.Get<double>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_BalanceSheet_ConvertibleLoansCurrent_TwelveMonths);
41 
42  /// <summary>
43  /// Returns true if the field contains a value for the default period
44  /// </summary>
45  public override bool HasValue => !BaseFundamentalDataProvider.IsNone(typeof(double), FundamentalService.Get<double>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_BalanceSheet_ConvertibleLoansCurrent_TwelveMonths));
46 
47  /// <summary>
48  /// Returns the default value for the field
49  /// </summary>
50  public override double Value
51  {
52  get
53  {
54  var defaultValue = FundamentalService.Get<double>(TimeProvider.GetUtcNow(), SecurityIdentifier, FundamentalProperty.FinancialStatements_BalanceSheet_ConvertibleLoansCurrent_TwelveMonths);
55  if (!BaseFundamentalDataProvider.IsNone(typeof(double), defaultValue))
56  {
57  return defaultValue;
58  }
59  return base.Value;
60  }
61  }
62 
63  /// <summary>
64  /// Gets a dictionary of period names and values for the field
65  /// </summary>
66  /// <returns>The dictionary of period names and values</returns>
67  public override IReadOnlyDictionary<string, double> GetPeriodValues()
68  {
69  var result = new Dictionary<string, double>();
70  foreach (var kvp in new[] { new Tuple<string, double>("12M",TwelveMonths) })
71  {
72  if(!BaseFundamentalDataProvider.IsNone(typeof(double), kvp.Item2))
73  {
74  result[kvp.Item1] = kvp.Item2;
75  }
76  }
77  return result;
78  }
79 
80  /// <summary>
81  /// Gets the value of the field for the requested period
82  /// </summary>
83  /// <param name="period">The requested period</param>
84  /// <returns>The value for the period</returns>
85  public override double GetPeriodValue(string period) => FundamentalService.Get<double>(TimeProvider.GetUtcNow(), SecurityIdentifier, Enum.Parse<FundamentalProperty>($"FinancialStatements_BalanceSheet_ConvertibleLoansCurrent_{ConvertPeriod(period)}"));
86 
87  /// <summary>
88  /// Creates a new empty instance
89  /// </summary>
91  {
92  }
93 
94  /// <summary>
95  /// Creates a new instance for the given time and security
96  /// </summary>
97  public ConvertibleLoansCurrentBalanceSheet(ITimeProvider timeProvider, SecurityIdentifier securityIdentifier) : base(timeProvider, securityIdentifier)
98  {
99  }
100  }
101 }