Market Profile | Intro

Market Profile: a statistical view on financial markets

Main source: Towards Data Science

A gentle introduction and a short recipe on how to plot market profile in Matplotlib

Mario Emmanuel

Mario EmmanuelFollowAug 11, 2019 · 9 min read

Market profile is a technique used to contextualize current market conditions.

A brief introduction to Market Profile methodology

Market Profile was a technique developed by J. Peter Steidlmayer in the 60s. The methodology represents the statistical distribution of a given market in a given period.

Steidlmayer, son of a wealthy farmer, become a CBOT pit trader in the 60s and eventually become one of the CBOT directors in the early 80s. He merged the concepts of minimum relevant price movement, balance and gaussian distribution to define a methodology that can track how a given market is moving at a given time.

Market profile theory is properly covered in several books and there is also some good material on the Internet. It is a methodology that experienced a great interest during the late 80s and 90s, being Steidlmayer its main promoter—he also was in charge of delivering the first electronic data services at CBOT in the early 80s —. While it is no longer a mainstream analysis technique, it still counts with a base of followers who actively use it.

Market Profile uses time and price to locate the value areas of the trading session (i.e. price areas where the participants consider that the fair price of a given asset/instrument is located). While it is not a trading methodology or system, it is a sound way to analyse the current status of a given market as it helps to clarify if a market is consolidating or trending.

One of the advantages of Market Profile over Volume Profile is that volume data is not required. This is especially interesting for non-regulated OTC markets where volume information is either not available or not significative. It also enables using non-expensive historical data for simulation.

As Market Profile uses the concept of TPO (Time Price Opportunity) to reflect areas of interest, those areas are highly correlated with the high volume areas. So in the end, both methodologies can lead to similar results and it is sometimes actually astonishing to see how similar both profiles are. The explanation is that moving large volumes at a given price in the market requires time, and that time is translated into a larger number of TPOs as a given price. That effectively contributes to correlate both Market Profile and Volume Profile.

Although there are some plugins for all the major trading software, Market Profile is somehow a different beast. At its peak during the 90s, Market Profile was usually exploited through specialised software (such as Capital Flow, the software once distributed by Steildmayer). Such software packages were expensive as they were designed with funds and institutional players in mind.

I have always been very interested in both Market and Volume Profile, and during last months I have been intensively studying and working on those areas.

Those analysis techniques help you to identify where major players might be and what would be their directional move. One could argue that Market Profile is a technique from other age; we can not forget that it was a methodology conceived for commodities Pit trading at the 60s and that some of the companion information that helped Market Profile shine (such as the Liquidity Data Bank from CBOT) is no longer available, but I think the underlying statistical concepts that support the methodology still apply.

In my opinion, the usage of balance/unbalance and gaussian distribution concepts make the methodology strong and scientifically backed up, as those concepts help to deal with complex natural processes that can not be described from a deterministic way —and stock markets fit well in this category — . This is a personal opinion though, and I am probably biased because my approach to markets is one that leverages on statistics as much as possible.

My interest in Market Profile is specially focused on intraday trading. I am using specifically 30 minutes candles, which was the original timeframe defined for Market Profile. 30 minutes is a timeframe not widely used but it has the great advantage of being large enough to avoid smaller timeframes players (specially HFT) and still small enough to get enough monthly trades for an intraday operation. In the near future I would like to extend market profile concepts to larger timeframes, as it was the case for all major software used by funds in the 90s. The strong point of moving beyond the 30 minutes timeframe profiles is that efficiency periods can be detected — not easy but doable — , and by doing that larger market movements could be anticipated. Swing operations can be therefore be planned. Some information about how that is achieved is included in the books covered in the next section.

Mastering Market Profile

Market Profile is a complex methodology which requires dedication and experience to be mastered. For those interested in learning more I will point to the most relevant books I have found covering the subject.

141 West Jackson and Markets & Market Logic are the classic books writen by Steidlmayer about Market Profile

The classic books about Market Profile are “141 West Jackson” (for those wondering, that is the CBOT address in Chicago) and “Markets & Market Logic”.

A more modern revisit would be “Steidlmayer on Markets: Trading with Market Profile” by J. Peter Steidlmayer and Steven B. Hawkins.

All three books constitute a good introduction to Market Profile. “141 West Jackson” is particularly enjoyable while “Steidlmayer on Markets: Trading with Market Profile” might be the most practical one.

As constructive criticism, I would point that at certain points some excerpts might be too focused on proprietary software features without a proper explanation on how those features work, which might leave a feeling of being targeted by promotional marketing. Other than that, books are worth reading for anyone interested in the topic as they are written by the key stakeholders of this methodology.

Market Profile in Matplotlib and Python

As a hands-on example on Market Profile, I include a routine to get a Market Profile distribution and its plot in Python, using Matplotlib.

Assume you have the following market profile data in Python:

day_market_profile = [
(Decimal(1.4334), 1, 'n'),
(Decimal(1.4335), 1, 'n'),
(Decimal(1.4336), 1, 'n'),
...
(Decimal(1.4360), 14, 'bcdijklmpqrsuv'),
...
(Decimal(1.4482), 1, 'E'),
(Decimal(1.4483), 1, 'E'),
]

The data is obtained within a custom market_profile routine which generates a daily market profile using 30 minutes TPOs.

day = datetime(2010,1,5)
day_market_profile = market_profile(day, Decimal('0.0001'))
for i in day_market_profile:
print(str(i[0]) + ' | ' + str(i[1]).rjust(2,' ') + ' | ' + i[2])

Printing the list of tuples results in:

1.4334 |  1 | n
1.4335 | 1 | n
1.4336 | 1 | n
1.4337 | 1 | n
1.4338 | 1 | n
1.4339 | 1 | n
1.4340 | 1 | n
1.4341 | 1 | n
1.4342 | 3 | noq
1.4343 | 3 | noq
1.4344 | 3 | noq
1.4345 | 4 | noqr
1.4346 | 5 | bnoqr
1.4347 | 6 | bmnoqr
1.4348 | 6 | bmnoqr
1.4349 | 7 | bcmnoqr
1.4350 | 8 | bckmnoqr
1.4351 | 9 | bckmnoqrs
1.4352 | 10 | bckmnoqrst
1.4353 | 11 | bckmnopqrst
1.4354 | 14 | bcklmnopqrstuv
1.4355 | 14 | bcklmnopqrstuv
1.4356 | 13 | bcklmopqrstuv
1.4357 | 13 | bcklmopqrstuv
1.4358 | 12 | bcklmopqrsuv
1.4359 | 12 | bcdklmpqrsuv
1.4360 | 14 | bcdijklmpqrsuv
1.4361 | 14 | bcdijklmpqrsuv
1.4362 | 13 | bcdijklmpqrsu
1.4363 | 11 | bdhijklmpqs
1.4364 | 10 | bdhijklmpq
1.4365 | 11 | bdfhijklmpq
1.4366 | 12 | bdfghijklmpq
1.4367 | 11 | bdefghjklpq
1.4368 | 10 | bdefghklpq
1.4369 | 9 | bdefghklq
1.4370 | 7 | befghkl
1.4371 | 7 | abefghk
1.4372 | 6 | abefgh
1.4373 | 5 | abegh
1.4374 | 2 | ab
1.4375 | 1 | a
1.4376 | 1 | a
1.4377 | 1 | a
1.4378 | 1 | a
1.4379 | 1 | a
1.4380 | 1 | a
1.4381 | 1 | a
1.4382 | 1 | a
1.4383 | 2 | Ya
1.4384 | 2 | Ya
1.4385 | 2 | Ya
1.4386 | 4 | XYZa
1.4387 | 5 | TXYZa
1.4388 | 5 | TXYZa
1.4389 | 5 | TXYZa
1.4390 | 5 | TXYZa
1.4391 | 5 | TXYZa
1.4392 | 5 | TXYZa
1.4393 | 5 | TXYZa
1.4394 | 4 | TXYZ
1.4395 | 4 | TXYZ
1.4396 | 4 | TXYZ
1.4397 | 5 | TWXYZ
1.4398 | 5 | TWXYZ
1.4399 | 4 | TWXY
1.4400 | 5 | MTWXY
1.4401 | 6 | MTUWXY
1.4402 | 6 | MTUWXY
1.4403 | 5 | MTUWY
1.4404 | 5 | MTUWY
1.4405 | 5 | MTUWY
1.4406 | 7 | HMSTUWY
1.4407 | 6 | HMSTUW
1.4408 | 6 | HMSTUW
1.4409 | 8 | HMNSTUVW
1.4410 | 8 | HMNSTUVW
1.4411 | 8 | HMNSTUVW
1.4412 | 8 | HMNSTUVW
1.4413 | 8 | HMNSTUVW
1.4414 | 10 | HILMNSTUVW
1.4415 | 10 | HILMNSTUVW
1.4416 | 11 | AHILMNSTUVW
1.4417 | 12 | AHILMNOSTUVW
1.4418 | 13 | AHIJLMNOSTUVW
1.4419 | 13 | AHIJLMNOSTUVW
1.4420 | 14 | AHIJKLNORSTUVW
1.4421 | 14 | AHIJKLNORSTUVW
1.4422 | 15 | AGHIJKLNORSTUVW
1.4423 | 15 | AGHIJKLNORSTUVW
1.4424 | 15 | ABGHIJKLNORSUVW
1.4425 | 14 | ABGHIJKLNORSUV
1.4426 | 13 | ABGHIJKLORSUV
1.4427 | 13 | ABGHIJKLORSUV
1.4428 | 12 | ABGHIJKLORUV
1.4429 | 11 | BGIJKLOPRUV
1.4430 | 11 | BGIJKLOPRUV
1.4431 | 12 | BGIJKLOPQRUV
1.4432 | 12 | BGIJKLOPQRUV
1.4433 | 12 | BGIJKLOPQRUV
1.4434 | 11 | BGIJKLOPQRU
1.4435 | 10 | BGIJKLOPQR
1.4436 | 9 | BGIJKLPQR
1.4437 | 9 | BGIJKLPQR
1.4438 | 6 | BGIPQR
1.4439 | 5 | BGPQR
1.4440 | 5 | BGPQR
1.4441 | 4 | BGPQ
1.4442 | 4 | BGPQ
1.4443 | 4 | BGPQ
1.4444 | 4 | BGPQ
1.4445 | 4 | BGPQ
1.4446 | 5 | BCGPQ
1.4447 | 5 | BCFGP
1.4448 | 5 | BCFGP
1.4449 | 5 | BCFGP
1.4450 | 5 | BCFGP
1.4451 | 5 | BCFGP
1.4452 | 6 | BCDFGP
1.4453 | 6 | BCDFGP
1.4454 | 6 | BCDFGP
1.4455 | 5 | BCDFP
1.4456 | 4 | BCDF
1.4457 | 4 | BCDF
1.4458 | 4 | BCDF
1.4459 | 5 | BCDEF
1.4460 | 5 | BCDEF
1.4461 | 5 | BCDEF
1.4462 | 5 | BCDEF
1.4463 | 5 | BCDEF
1.4464 | 5 | BCDEF
1.4465 | 3 | BDE
1.4466 | 3 | BDE
1.4467 | 3 | BDE
1.4468 | 3 | BDE
1.4469 | 3 | BDE
1.4470 | 3 | BDE
1.4471 | 3 | BDE
1.4472 | 3 | BDE
1.4473 | 3 | BDE
1.4474 | 3 | BDE
1.4475 | 2 | DE
1.4476 | 2 | DE
1.4477 | 1 | E
1.4478 | 1 | E
1.4482 | 1 | E
1.4483 | 1 | E

This is an old school stem and leaf diagram and it is the canonical way to represent a Market Profile. While the information is relevant as the letter codes give you a visual guidance on “when and where the price was”, often you might be interested in just the price-time distribution which can be easily viewed in a chart without letter codes. This is specially true if your profile covers 24 hours, as it is difficult to follow so many letter codes. In that simplified scenario it is easier to plot the data as a regular chart, although you lose the information on how price evolved during the trading session:

%matplotlib inlinempl.rcParams['interactive'] = False
mpl.rcParams['figure.figsize'] = (16.0, 12.0)
mpl.rcParams['lines.markerfacecolor'] = 'blue'# Define price labels, we print just values ending in 0.0005 or 0.0010
df.loc[df['price'] % Decimal('0.0005') == 0, 'label'] = df['price']
df['label'].fillna('',inplace=True)
df['label']=df['label'].astype(str)df.plot.barh(x='label', y='tpo_count', legend=None)
plt.xlabel('TPO Count')
plt.ylabel('Price')
plt.title('Market Profile | EURUSD | January 5th, 2010')
plt.show()

Notice how we create a new label column to hold the y axis tick labels. We will just print prices ending in 0.0005 and 0.0010 so we use .loc, .fillna and a final conversion to str to get our Pandas series to be used as labels.

The graphical alternative removing the code letters enable a quick read on the areas of interest of the trading session. While the letter code is relevant information, if we want to detect areas of high activity in the session this chart is easier to read.

Summary

In the article, I have briefly presented Market Profile. I have covered why I think Market Profile is still relevant today and some reasoning on why I think in that way. I have also enumerated the three main classic books which cover the theory and a small excerpt of code on how to plot market profiles. A routine to get market profile is not presented because it is highly specific on how do you store your data, but in this example, a prototype in Python was build in just 50 lines. That is just one page of code.

Get in touch

I am deeply interested and involved in this specific area, so if you work in the industry and are interested in Market Profile feel free to contact me. I would be happy to explore any cooperation (also services/hiring) related to both Market Profile and Volume Profile.

Social Sharing

Share on facebook
Share on twitter
Share on whatsapp