-
Notifications
You must be signed in to change notification settings - Fork 636
Access to mplfinance Calculated Values
Daniel Goldfarb edited this page Jan 2, 2022
·
3 revisions
Sometimes you may want to see or use values that mplfinance calculated internally. This is particularly helpful to gain access to Renko and/or Point-and-Figure data. But other values (such as moving averages, minimums and maximums) are also returned.
To gain access to calculated values, you must set a variable equal to an empty dictionary. Then pass this variable as the value of kwarg return_calculated_values
. Mplfinance will fill the empty dictionary with various calculated values.
Note well: If you do this more than once with the same variable you must reset the variable to be an empty dict every time.
Here is an example:
import pandas as pd
import mplfinance as mpf
import pprint
daily = pd.read_csv('data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)
renko_kwargs = dict(type='renko',mav=(8,20,30), volume=True,figratio=(10,8),figscale=0.75)
cv = {}
mpf.plot(daily,**renko_kwargs,style='blueskies',return_calculated_values=cv)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(cv)
Here is the output from pp.pprint(cv)
{ 'mav20': array([ nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, 119.75656377,
118.96970631, 118.37956322, 117.78942013, 117.19927704,
116.60913394, 116.01899085, 115.62556212, 115.42884776,
115.42884776, 115.62556212, 116.01899085, 116.41241958,
116.80584831, 117.19927704, 117.59270576, 117.98613449,
118.37956322, 118.57627759, 118.57627759, 118.57627759,
118.77299195, 118.96970631, 119.36313504, 119.75656377,
120.34670686, 121.13356432, 121.92042178, 122.70727924,
123.49413669, 124.28099415, 125.06785161, 125.85470906,
126.64156652, 127.23170961, 127.82185271, 128.4119958 ,
128.80542453, 129.19885326, 129.78899635, 130.57585381]),
'mav30': array([ nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, nan, nan, nan,
nan, 118.1172774 , 117.72384867, 117.46156285,
117.33041995, 117.33041995, 117.33041995, 117.33041995,
117.46156285, 117.59270576, 117.72384867, 117.85499158,
118.1172774 , 118.37956322, 118.64184904, 118.77299195,
119.03527777, 119.4287065 , 119.82213523, 120.21556395,
120.60899268, 121.13356432, 121.78927887, 122.44499342,
123.23185087, 124.01870833, 124.80556579, 125.59242325,
126.24813779, 126.77270943, 127.29728107, 127.82185271]),
'mav8': array([ nan, nan, nan, nan,
nan, nan, nan, 125.06785161,
123.10070796, 121.13356432, 119.16642068, 117.69106295,
116.70749112, 116.21570521, 115.7239193 , 115.23213339,
115.23213339, 115.7239193 , 116.70749112, 117.19927704,
117.19927704, 117.19927704, 117.19927704, 117.19927704,
116.70749112, 115.7239193 , 114.74034748, 114.24856157,
114.24856157, 114.24856157, 114.74034748, 115.7239193 ,
117.19927704, 119.16642068, 120.64177841, 121.62535023,
122.60892205, 123.10070796, 123.10070796, 122.60892205,
122.11713614, 121.62535023, 121.62535023, 121.62535023,
121.62535023, 122.11713614, 123.10070796, 124.5760657 ,
126.05142343, 127.52678116, 129.00213889, 130.96928254,
132.93642618, 134.41178391, 135.39535573, 135.88714164,
135.88714164, 135.39535573, 134.90356982, 134.41178391]),
'maxx': 59.983333333333334,
'maxy': 141.78857257142855,
'minx': -0.9833333333333333,
'miny': 110.3142742857142,
'renko_bricks': [ 131.95285435714285,
129.98571071428572,
128.01856707142858,
126.05142342857143,
124.08427978571427,
122.11713614285712,
120.14999249999997,
118.18284885714282,
116.21570521428566,
114.24856157142851,
112.28141792857136,
114.24856157142851,
116.21570521428566,
118.18284885714282,
116.21570521428566,
114.24856157142851,
116.21570521428566,
118.18284885714282,
120.14999249999997,
118.18284885714282,
116.21570521428566,
118.18284885714282,
116.21570521428566,
114.24856157142851,
112.28141792857136,
110.3142742857142,
112.28141792857136,
114.24856157142851,
116.21570521428566,
118.18284885714282,
120.14999249999997,
122.11713614285712,
124.08427978571427,
126.05142342857143,
124.08427978571427,
122.11713614285712,
124.08427978571427,
122.11713614285712,
120.14999249999997,
118.18284885714282,
120.14999249999997,
122.11713614285712,
124.08427978571427,
122.11713614285712,
124.08427978571427,
126.05142342857143,
128.01856707142858,
129.98571071428572,
131.95285435714285,
133.919998,
135.88714164285713,
137.85428528571427,
139.8214289285714,
137.85428528571427,
135.88714164285713,
133.919998,
131.95285435714285,
129.98571071428572,
131.95285435714285,
133.919998],
'renko_dates': [ datetime.datetime(2011, 7, 11, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 7, 28, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 1, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 1, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 3, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 3, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 4, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 5, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 5, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 5, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 5, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 8, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 12, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 12, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 17, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 18, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 26, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 26, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 8, 30, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 1, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 8, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 14, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 21, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 21, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 30, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 9, 30, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 4, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 5, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 7, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 11, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 13, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 21, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 26, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 26, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 31, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 10, 31, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 2, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 16, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 18, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 22, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 29, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 11, 29, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 12, 2, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 12, 13, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2011, 12, 22, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 1, 4, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 1, 17, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 1, 24, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 2, 2, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 2, 15, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 3, 12, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 3, 12, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 3, 30, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 4, 9, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 5, 8, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 5, 14, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 5, 16, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 5, 17, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 6, 14, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 6, 28, 0, 0, tzinfo=datetime.timezone.utc)],
'renko_size': 1.9671436428571505,
'renko_volumes': [ 1072136600,
2461593000,
632829300,
632829300,
717484600,
717484600,
520721800,
655619200,
655619200,
655619200,
655619200,
1404527800,
2182147400,
801711300,
1582213800,
512956300,
1908239500,
1204867600,
432292900,
1112828600,
1461390500,
1277892800,
1388006000,
316251300,
2266779400,
288392300,
824314300,
284108000,
570458700,
439754300,
494083700,
1500243400,
760866200,
760866200,
847273400,
228146700,
1322566800,
2301143000,
546800000,
446106500,
1467627200,
733813600,
722504000,
1552868600,
1381226800,
837360600,
1079327000,
660333400,
1102601500,
1336059400,
2375255800,
2375255800,
1961458100,
719439100,
3254948800,
688294900,
414894800,
247992900,
3601584000,
2110620800]}