@@ -17,16 +17,12 @@ public class GreekClient : Intrinio.Realtime.Equities.ISocketPlugIn, Intrinio.Re
1717{
1818 #region Data Members
1919 private readonly IDataCache _cache ;
20- public const string BlackScholesImpliedVolatilityKeyName = "IntrinioBlackScholesImpliedVolatility" ;
21- public const string BlackScholesDeltaKeyName = "IntrinioBlackScholesDelta" ;
22- public const string BlackScholesGammaKeyName = "IntrinioBlackScholesGamma" ;
23- public const string BlackScholesThetaKeyName = "IntrinioBlackScholesTheta" ;
24- public const string BlackScholesVegaKeyName = "IntrinioBlackScholesVega" ;
2520 public const string DividendYieldKeyName = "DividendYield" ;
2621 public const string RiskFreeInterestRateKeyName = "RiskFreeInterestRate" ;
2722 public const string BlackScholesKeyName = "IntrinioBlackScholes" ;
2823 private readonly ConcurrentDictionary < string , CalculateNewGreek > _calcLookup ;
29- private readonly SupplementalDatumUpdate _updateFunc = ( string key , double ? oldValue , double ? newValue ) => { return newValue ; } ;
24+ private readonly GreekDataUpdate _updateFunc = ( string key , Greek ? oldValue , Greek ? newValue ) => { return newValue ; } ;
25+ private readonly SupplementalDatumUpdate _updateFuncNumber = ( string key , double ? oldValue , double ? newValue ) => { return newValue ; } ;
3026 private Timer ? _dividendFetchTimer ;
3127 private Timer ? _riskFreeInterestRateFetchTimer ;
3228 private readonly Intrinio . SDK . Client . ApiClient _apiClient ;
@@ -50,9 +46,9 @@ public int ApiCallSpacerMilliseconds
5046 private bool _dividendYieldWorking = false ;
5147 private readonly bool _selfCache ;
5248
53- public OnOptionsContractSupplementalDatumUpdated ? OnGreekValueUpdated
49+ public OnOptionsContractGreekDataUpdated ? OnGreekValueUpdated
5450 {
55- set { _cache . OptionsContractSupplementalDatumUpdatedCallback += value ; }
51+ set { _cache . OptionsContractGreekDataUpdatedCallback += value ; }
5652 }
5753 #endregion //Data Members
5854
@@ -65,7 +61,7 @@ public OnOptionsContractSupplementalDatumUpdated? OnGreekValueUpdated
6561 /// <param name="onGreekValueUpdated"></param>
6662 /// <param name="apiKey"></param>
6763 /// <param name="cache"></param>
68- public GreekClient ( GreekUpdateFrequency greekUpdateFrequency , OnOptionsContractSupplementalDatumUpdated onGreekValueUpdated , string apiKey , IDataCache ? cache = null )
64+ public GreekClient ( GreekUpdateFrequency greekUpdateFrequency , OnOptionsContractGreekDataUpdated onGreekValueUpdated , string apiKey , IDataCache ? cache = null )
6965 {
7066 _apiCallSpacerMilliseconds = 1100 ;
7167 _dividendYieldUpdatePeriodHours = 4 ;
@@ -279,7 +275,7 @@ private void FetchInitialCompanyDividends(int daysAgo)
279275 {
280276 if ( ! String . IsNullOrWhiteSpace ( companyDailyMetric . Company . Ticker ) && companyDailyMetric . DividendYield . HasValue )
281277 {
282- _cache . SetSecuritySupplementalDatum ( companyDailyMetric . Company . Ticker , DividendYieldKeyName , Convert . ToDouble ( companyDailyMetric . DividendYield ?? 0m ) , _updateFunc ) ;
278+ _cache . SetSecuritySupplementalDatum ( companyDailyMetric . Company . Ticker , DividendYieldKeyName , Convert . ToDouble ( companyDailyMetric . DividendYield ?? 0m ) , _updateFuncNumber ) ;
283279 _seenTickers [ String . Intern ( companyDailyMetric . Company . Ticker ) ] = DateTime . UtcNow ;
284280 }
285281 }
@@ -305,13 +301,13 @@ private void RefreshDividendYield(string ticker)
305301 string securityId = _securityApi . GetSecurityByIdAsync ( $ "{ ticker } :US") . Result . Id ;
306302 Thread . Sleep ( _apiCallSpacerMilliseconds ) ; //don't try to get rate limited.
307303 decimal ? result = _securityApi . GetSecurityDataPointNumberAsync ( securityId , dividendYieldTag ) . Result ;
308- _cache . SetSecuritySupplementalDatum ( ticker , DividendYieldKeyName , Convert . ToDouble ( result ?? 0m ) , _updateFunc ) ;
304+ _cache . SetSecuritySupplementalDatum ( ticker , DividendYieldKeyName , Convert . ToDouble ( result ?? 0m ) , _updateFuncNumber ) ;
309305 _seenTickers [ ticker ] = DateTime . UtcNow ;
310306 Thread . Sleep ( _apiCallSpacerMilliseconds ) ; //don't try to get rate limited.
311307 }
312308 catch ( Exception e )
313309 {
314- _cache . SetSecuritySupplementalDatum ( ticker , DividendYieldKeyName , 0.0D , _updateFunc ) ;
310+ _cache . SetSecuritySupplementalDatum ( ticker , DividendYieldKeyName , 0.0D , _updateFuncNumber ) ;
315311 _seenTickers [ ticker ] = DateTime . UtcNow ;
316312 Thread . Sleep ( _apiCallSpacerMilliseconds ) ; //don't try to get rate limited.
317313 }
@@ -358,7 +354,7 @@ private void FetchRiskFreeInterestRate(object? _)
358354 Decimal ? results = _indexApi . GetEconomicIndexDataPointNumber ( "$DTB3" , "level" ) ;
359355 if ( results . HasValue )
360356 {
361- _cache . SetSupplementaryDatum ( RiskFreeInterestRateKeyName , Convert . ToDouble ( results . Value ) / 100.0D , _updateFunc ) ;
357+ _cache . SetSupplementaryDatum ( RiskFreeInterestRateKeyName , Convert . ToDouble ( results . Value ) / 100.0D , _updateFuncNumber ) ;
362358 success = true ;
363359 }
364360
@@ -395,13 +391,35 @@ public void UpdateGreeks(ISecurityData securityData, IDataCache dataCache)
395391 foreach ( KeyValuePair < string , IOptionsContractData > keyValuePair in securityData . AllOptionsContractData )
396392 UpdateGreeks ( keyValuePair . Value , dataCache , securityData ) ;
397393 }
394+
395+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
396+ public void UpdateGreeks ( ISecurityData securityData , IDataCache dataCache , Equities . Trade ? trade )
397+ {
398+ UpdateGreeks ( securityData , dataCache ) ;
399+ }
400+
401+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
402+ public void UpdateGreeks ( ISecurityData securityData , IDataCache dataCache , Equities . Quote ? quote )
403+ {
404+ UpdateGreeks ( securityData , dataCache ) ;
405+ }
398406
399407 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
400408 private void UpdateGreeks ( IOptionsContractData optionsContractData , IDataCache dataCache , ISecurityData securityData )
401409 {
402410 foreach ( CalculateNewGreek calculateNewGreek in _calcLookup . Values )
403411 calculateNewGreek ( optionsContractData , securityData , dataCache ) ;
404- }
412+ }
413+
414+ private void UpdateGreeks ( IOptionsContractData optionsContractData , IDataCache dataCache , ISecurityData securityData , Options . Trade ? trade )
415+ {
416+ UpdateGreeks ( optionsContractData , dataCache , securityData ) ;
417+ }
418+
419+ private void UpdateGreeks ( IOptionsContractData optionsContractData , IDataCache dataCache , ISecurityData securityData , Options . Quote ? quote )
420+ {
421+ UpdateGreeks ( optionsContractData , dataCache , securityData ) ;
422+ }
405423
406424 private void BlackScholesCalc ( IOptionsContractData optionsContractData , ISecurityData securityData , IDataCache dataCache )
407425 {
@@ -416,13 +434,7 @@ private void BlackScholesCalc(IOptionsContractData optionsContractData, ISecurit
416434 Greek result = BlackScholesGreekCalculator . Calculate ( riskFreeInterestRate . Value , dividendYield . Value , equitiesTrade . Value . Price , optionsQuote . Value ) ;
417435
418436 if ( result . IsValid )
419- {
420- dataCache . SetOptionSupplementalDatum ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesImpliedVolatilityKeyName , result . ImpliedVolatility , _updateFunc ) ;
421- dataCache . SetOptionSupplementalDatum ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesDeltaKeyName , result . Delta , _updateFunc ) ;
422- dataCache . SetOptionSupplementalDatum ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesGammaKeyName , result . Gamma , _updateFunc ) ;
423- dataCache . SetOptionSupplementalDatum ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesThetaKeyName , result . Theta , _updateFunc ) ;
424- dataCache . SetOptionSupplementalDatum ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesVegaKeyName , result . Vega , _updateFunc ) ;
425- }
437+ dataCache . SetOptionGreekData ( securityData . TickerSymbol , optionsContractData . Contract , BlackScholesKeyName , result , _updateFunc ) ;
426438 }
427439
428440 #endregion //Private Methods
0 commit comments