Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Market profile indicator #5891

Merged

Conversation

Marinovsky
Copy link
Collaborator

@Marinovsky Marinovsky commented Aug 31, 2021

Description

Two Market profile modes implemented: TimeProfile and Volume Profile.

Related Issue

Closes #4770

Motivation and Context

Market Profile reveals several factors that provide you with
an idea of the trading activity taking place in the markets.
Monitoring the market action will enable you to determine
the type of day that is developing, whether a price trend has
started, what the value area is, the type of activity (initiative
or responsive) taking place, whether the activity is continuing
or changing from the previous day, and whether the market is
trending or bracketing.

Requires Documentation Change

These changes will require updates to the indicators documentation, showing the new indicator and explaning how it works and the parameters need it.

How Has This Been Tested?

Using a Google Collaborative notebook (https://colab.research.google.com/drive/16oMViM6SwK4FRGTztxH23xgEE1QH0d23?usp=sharing) and the Python Market Profile library shown in the issue with IBM historical prices from 02/01/2020 to 31/01/2020 from Yahoo finance it was calculated the Market Profile with TPO (Time Price Opportunity) and VOL(Volume Profile) modes while manually rolling a period of three. Then those values were appended into two .csv files with the IBM historical prices previously mentioned, those files are called tp_datatest.csv for TimeProfile tests and vp_datatest.csv for VolumeProfile tests. Finally, using TestIndicator from TestHelper it was made an assertion for each Market Profile value in each mentioned mode.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Final graphical sanity tests

IBM Volume Profile in January 2020 with a period of 3 days. Link: https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_dfcca7b9a96cf6c60b3353115e919bcb.html

image

IBM Volume Profile from January first to June first of 2020 with a period of 15 days. Link: https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_981f843cabd2a93e8daac76de830e532.html

image

IBM Time Profile in January 2020 with a period of 3 days. Link: https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_6a86e887054c8b4c32a89f62f9148f0a.html

image

IBM Time Profile from January first to June first with a period of 15 days. Link: https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_2502126741241ced2aff0274b4870171.html

image

- TimeProfile and VolumeProfile created and tested.
- tp_datatest.csv and vp_datatest.csv extracted from https://github.com/bfolkens/py-market-profile
All unit test made it and the indicator is passing all of them
Test cases made it with python library from GH issue
Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @Marinovsky! Great first PR 🙌
Leaving some requests and some code styling request changes

Algorithm/QCAlgorithm.Indicators.cs Outdated Show resolved Hide resolved
Algorithm/QCAlgorithm.Indicators.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Tests/Indicators/TimeProfileTests.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!
Leaving minor comments and as final request suggest testing it in the cloud and charting the indicators values in a plot with an assets price and volume as a final graphical sanity test. Let's add those chart images into the PR description too 👍

Algorithm/QCAlgorithm.Indicators.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
Tests/Indicators/TimeProfileTests.cs Outdated Show resolved Hide resolved
Indicators/MarketProfile.cs Outdated Show resolved Hide resolved
@Martin-Molinero Martin-Molinero merged commit da60daa into QuantConnect:master Sep 3, 2021
@ikamanu
Copy link

ikamanu commented Sep 4, 2021

Great work and timely too --there is an effort currently underway to add VolumeProfile to Lean, but it seems like you beat us to it, @Marinovsky! :)

Question: is the histogram data easily accessible? Specifically, I'd like to be able to detect the shape of the volume profile distribution, and would need to be able to inspect the data in order to do so.

See attached image for example of 'shape'. I aim to detect this by measuring skewness, kurtosis, mean, median and mode.

Thanks for this good work!

Screen Shot 2021-08-22 at 12 24 28 AM

@Marinovsky
Copy link
Collaborator Author

Marinovsky commented Sep 6, 2021

Great work and timely too --there is an effort currently underway to add VolumeProfile to Lean, but it seems like you beat us to it, @Marinovsky! :)

Question: is the histogram data easily accessible? Specifically, I'd like to be able to detect the shape of the volume profile distribution, and would need to be able to inspect the data in order to do so.

See attached image for example of 'shape'. I aim to detect this by measuring skewness, kurtosis, mean, median and mode.

Thanks for this good work!

Screen Shot 2021-08-22 at 12 24 28 AM

Hi @ikamanu, thanks for your question!

Regarding your question: sure, the histogram data is accessible, the method VolumePerPrice returns a SortedList where close values are the keys and the volume for each of them are the values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Market Profile Indicator
3 participants