### Install marketprofile Library Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Install the library using pip. No additional setup is required. ```default pip install marketprofile ``` -------------------------------- ### Run All Test Environments in Parallel Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Utilize detox to run all test environments concurrently. Ensure detox is installed via pip. ```bash detox ``` -------------------------------- ### Get Market Profile Series Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Access the calculated market profile as a Pandas Series, showing volume at different price levels within the selected time slice. ```pycon mp_slice.profile ``` -------------------------------- ### Get Full Price Range of Market Profile Slice Source: https://context7.com/bfolkens/py-market-profile/llms.txt Retrieves the minimum and maximum price levels within a specific time slice of the market profile. Requires MarketProfile and pandas to be imported. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] low, high = mp_slice.profile_range print(f"Profile range: {low} – {high}") # Profile range: 927.75 – 959.3 ``` -------------------------------- ### Get Profile Range Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Obtain the overall price range (low to high) covered by the market profile for the selected time slice. This is returned as a tuple of (low, high) prices. ```pycon mp_slice.profile_range ``` -------------------------------- ### Get Low Value Nodes Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Identify and retrieve price levels with the lowest volume traded within the selected market profile slice. This is returned as a Pandas Series. ```pycon mp_slice.low_value_nodes ``` -------------------------------- ### Get Point of Control (POC) Price Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Retrieve the price level with the highest volume traded during the selected period. This is a key indicator in Market Profile analysis. ```pycon mp_slice.poc_price ``` -------------------------------- ### Get High Value Nodes Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Identify and retrieve price levels with the highest volume traded within the selected market profile slice. This is returned as a Pandas Series. ```pycon mp_slice.high_value_nodes ``` -------------------------------- ### Get Point of Control Price and Volume Source: https://context7.com/bfolkens/py-market-profile/llms.txt The `.poc_price` attribute returns the price level with the highest volume (or TPO count) in the slice. If multiple levels share the maximum, the one closest to the distribution midpoint is chosen. `.poc_volume` returns the volume at that price level. Returns `None` if the profile is empty. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.poc_price) # 944.5 print(mp_slice.poc_volume) # 186489 (volume at the POC) ``` -------------------------------- ### Slice MarketProfile Data by Timestamp Range Source: https://context7.com/bfolkens/py-market-profile/llms.txt Create a MarketProfileSlice object by slicing the underlying DataFrame using a Python slice object (e.g., `[start:stop]`). This pre-computes all profile statistics for the specified time range. Access the raw profile Series using the `.profile` attribute. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) # Slice over the full dataset mp_slice = mp[df.index.min():df.index.max()] # Slice a single trading session (e.g., one day) session_start = pd.Timestamp('2017-06-01 09:30:00') session_end = pd.Timestamp('2017-06-01 16:00:00') session_slice = mp[session_start:session_end] # Access the raw profile Series (price level → volume) print(mp_slice.profile) # Close # 927.75 13627 # 928.00 30366 # ... # 959.30 238489 # Name: Volume, dtype: int64 ``` -------------------------------- ### Get High Value Nodes (HVN) from Market Profile Slice Source: https://context7.com/bfolkens/py-market-profile/llms.txt Extracts High Value Nodes (HVN), which are price levels with significant volume, from a Market Profile slice. These nodes often indicate support or resistance. The output can be a Pandas Series or a list of prices. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.high_value_nodes) # Close # 944.50 186489 # 951.75 238489 # ... # Name: Volume, dtype: int64 hvn_prices = mp_slice.high_value_nodes.index.tolist() print(f"HVN prices: {hvn_prices}") ``` -------------------------------- ### Get Value Area Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Determine the value area, which typically encompasses the price range where a certain percentage (usually 70%) of the day's volume was traded. This is returned as a tuple of (low, high) prices. ```pycon mp_slice.value_area ``` -------------------------------- ### Load Data and Initialize MarketProfile Source: https://github.com/bfolkens/py-market-profile/blob/master/README.rst Import necessary libraries and load historical stock data using pandas-datareader. Then, create a MarketProfile object with the loaded DataFrame. ```python from market_profile import MarketProfile import pandas_datareader as data amzn = data.get_data_yahoo('AMZN', '2019-12-01', '2019-12-31') ``` ```python mp = MarketProfile(amzn) ``` -------------------------------- ### Clone Repository Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Clone your forked repository locally to begin development. ```bash git clone git@github.com:your_name_here/py-market-profile.git ``` -------------------------------- ### Load Data and Initialize MarketProfile Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Import necessary libraries and load historical stock data using pandas-datareader. Initialize the MarketProfile object with the loaded DataFrame. ```pycon from market_profile import MarketProfile import pandas_datareader as data amzn = data.get_data_yahoo('AMZN', '2019-12-01', '2019-12-31') ``` ```pycon mp = MarketProfile(amzn) mp_slice = mp[amzn.index.min():amzn.index.max()] ``` -------------------------------- ### Import Libraries and Load Data Source: https://github.com/bfolkens/py-market-profile/blob/master/examples/example.ipynb Imports necessary libraries and loads Google Finance data. Ensure 'google.txt' exists or is created by downloading data. ```python %matplotlib inline import os from market_profile import MarketProfile from google_finance import * if not os.path.exists('google.txt'): get_google_data('google.txt', 'GOOG', 60 * 30, 5) df = read_google_data('google.txt') ``` -------------------------------- ### Create MarketProfile Object with Default and Custom Configurations Source: https://context7.com/bfolkens/py-market-profile/llms.txt Instantiate a MarketProfile object with OHLCV data. Default settings use volume mode, a tick size of 0.05, a 70% value area, and a 1-hour initial balance. Custom configurations allow for TPO mode, different tick sizes, row sizes, open range durations, initial balance durations, and value area percentages. ```python import pandas as pd from market_profile import MarketProfile # Load OHLCV data with a Timestamp index df = pd.read_csv( 'data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp'], ) # Default: vol mode, 0.05 tick size, 70% value area, 1-hour initial balance mp = MarketProfile(df) # Custom configuration: TPO mode, larger tick bucket, 60% value area mp_tpo = MarketProfile( df, tick_size=0.25, # minimum price increment prices_per_row=1, # prices grouped per row row_size=0.25, # overrides tick_size * prices_per_row open_range_size=pd.to_timedelta('30 minutes'), # open range window initial_balance_delta=pd.to_timedelta('2 hours'), # initial balance window value_area_pct=0.60, # 60% of volume defines the value area mode='tpo' # 'vol' (default) or 'tpo' ) ``` -------------------------------- ### MarketProfileSlice.initial_balance() Source: https://context7.com/bfolkens/py-market-profile/llms.txt Calculates the Initial Balance range (IB Low, IB High), representing the price range traded during the default first hour of the trading session. ```APIDOC ## MarketProfileSlice.initial_balance() ### Description Returns a tuple `(ib_low, ib_high)` representing the Low and High price traded during the initial balance period (default: first hour of the session). The initial balance is a key reference range in Market Profile theory, defining the range set by early institutional participants. ### Usage ```python ib_low, ib_high = mp_slice.initial_balance() print(f"IB Low: {round(ib_low, 2)}, IB High: {round(ib_high, 2)}") ``` ### Returns - `tuple`: A tuple containing the Initial Balance Low (IB Low) and Initial Balance High (IB High). ``` -------------------------------- ### Run Development Checks with Tox Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Execute all checks, including the documentation builder and spell checker, using tox. ```bash tox ``` -------------------------------- ### Calculate Initial Balance Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Determine the initial balance range, which is typically the price range covered by the first hour of trading. This is returned as a tuple of (low, high) prices. ```pycon mp_slice.initial_balance() ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Stage all changes, commit them with a descriptive message, and push the branch to GitHub. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Calculate Initial Balance Range (IB) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Returns the low and high price range traded during the initial balance period, defaulting to the first hour. This range is crucial in Market Profile theory for identifying early institutional activity. Requires MarketProfile and pandas. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) # Default: 1-hour initial balance window mp = MarketProfile(df, row_size=0.05, initial_balance_delta=pd.to_timedelta('1 hour')) mp_slice = mp[df.index.min():df.index.max()] ib_low, ib_high = mp_slice.initial_balance() print(f"IB Low: {round(ib_low, 2)}, IB High: {round(ib_high, 2)}") # IB Low: 927.74, IB High: 935.53 ib_range = ib_high - ib_low print(f"IB Range size: {round(ib_range, 2)}") # 7.79 ``` -------------------------------- ### Create and Slice MarketProfile Source: https://github.com/bfolkens/py-market-profile/blob/master/examples/example.ipynb Initializes a MarketProfile object from a Pandas DataFrame and selects a specific time slice for analysis. ```python mp = MarketProfile(df, tick_size=1) mp_slice = mp[df.index.max() - pd.Timedelta(6.5, 'h'):df.index.max()] ``` -------------------------------- ### Calculate and Print Market Profile Indicators Source: https://github.com/bfolkens/py-market-profile/blob/master/examples/example.ipynb Calculates and prints key market profile indicators such as initial balance, opening range, POC, profile range, value area, and balanced target. ```python print "Initial balance: %f, %f" % mp_slice.initial_balance() print "Opening range: %f, %f" % mp_slice.open_range() print "POC: %f" % mp_slice.poc_price print "Profile range: %f, %f" % mp_slice.profile_range print "Value area: %f, %f" % mp_slice.value_area print "Balanced Target: %f" % mp_slice.balanced_target ``` -------------------------------- ### MarketProfileSlice.open_range() Source: https://context7.com/bfolkens/py-market-profile/llms.txt Calculates the Open Range (OR Low, OR High), the price range covered during the default first 10 minutes of the trading session. ```APIDOC ## MarketProfileSlice.open_range() ### Description Returns a tuple `(or_low, or_high)` for the price range covered during the open range period (default: first 10 minutes). The open range captures early price discovery and is frequently used as a breakout or reference level. ### Usage ```python or_low, or_high = mp_slice.open_range() print(f"Open Range: {round(or_low, 2)} – {round(or_high, 2)}") ``` ### Returns - `tuple`: A tuple containing the Open Range Low (OR Low) and Open Range High (OR High). ``` -------------------------------- ### Select a Time Slice for Analysis Source: https://github.com/bfolkens/py-market-profile/blob/master/README.rst Create a market profile slice for a specific date range from the initialized MarketProfile object. This slice is used for subsequent calculations. ```python mp_slice = mp[amzn.index.min():amzn.index.max()] ``` -------------------------------- ### Create Feature Branch Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Create a new branch for your bugfix or feature development. ```bash git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### MarketProfile(df, **kwargs) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Instantiates a MarketProfile object with OHLCV data and configuration options. This object serves as the entry point for generating market profile analyses. ```APIDOC ## MarketProfile(df, **kwargs) — Create a Market Profile object ### Description Instantiates a `MarketProfile` object wrapping a Pandas DataFrame of OHLCV data. All configuration — tick size, row size, open range duration, initial balance duration, value area percentage, and profiling mode — is set here. The object is then sliced by timestamp range to produce a `MarketProfileSlice` for analysis. ### Parameters - **df** (Pandas DataFrame) - Required - DataFrame with a `timestamp` index and OHLCV columns. - **tick_size** (float) - Optional - Minimum price increment. - **prices_per_row** (int) - Optional - Number of price levels to group per row. - **row_size** (float) - Optional - Overrides `tick_size * prices_per_row`. Defines the size of price buckets. - **open_range_size** (timedelta) - Optional - Duration of the open range window. - **initial_balance_delta** (timedelta) - Optional - Duration of the initial balance window. - **value_area_pct** (float) - Optional - Percentage of volume defining the value area (e.g., 0.60 for 60%). - **mode** (str) - Optional - Profiling mode: 'vol' (default) or 'tpo'. ### Request Example ```python import pandas as pd from market_profile import MarketProfile # Load OHLCV data with a Timestamp index df = pd.read_csv( 'data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp'], ) # Default configuration mp = MarketProfile(df) # Custom configuration mp_tpo = MarketProfile( df, tick_size=0.25, prices_per_row=1, row_size=0.25, open_range_size=pd.to_timedelta('30 minutes'), initial_balance_delta=pd.to_timedelta('2 hours'), value_area_pct=0.60, mode='tpo' ) ``` ``` -------------------------------- ### Access Market Profile Distribution and Statistics Source: https://context7.com/bfolkens/py-market-profile/llms.txt The `.profile` attribute provides the core histogram (price level to volume/TPO count). `.total_volume` gives the sum of all volume within the slice. The profile Series can be plotted as a horizontal bar chart. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] profile = mp_slice.profile print(profile) # Close # 927.75 13627 # 928.00 30366 # 944.50 186489 <- Point of Control (highest volume) # ... # Name: Volume, dtype: int64 # Total volume across all price levels print(mp_slice.total_volume) # 12953400 # Plot the profile as a horizontal bar chart profile.plot.barh(title='Volume Profile', figsize=(8, 12)) ``` -------------------------------- ### Export Market Profile Statistics as Dictionary Source: https://context7.com/bfolkens/py-market-profile/llms.txt Exports all computed Market Profile statistics for a given slice into a flat dictionary. This is useful for storing session data in databases, building summary DataFrames, or serializing to JSON. Keys include various profile metrics like POC, VAL, VAH, LVN, and HVN. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] stats = mp_slice.as_dict() print(stats) # { # 'or_low': 927.74, 'or_high': 927.74, # 'ib_low': 927.74, 'ib_high': 935.53, # 'poc': 944.50, # 'low': 927.75, 'high': 959.30, # 'val': 944.20, 'vah': 958.95, # 'bt': 961.25, # 'lvn': , # 'hvn': # } # Build a DataFrame of per-session statistics sessions = [] for date, session_df in df.groupby(df.index.date): mp_s = MarketProfile(session_df, row_size=0.05) sl = mp_s[session_df.index.min():session_df.index.max()] row = {k: v for k, v in sl.as_dict().items() if k not in ('lvn', 'hvn')} row['date'] = date sessions.append(row) summary = pd.DataFrame(sessions).set_index('date') print(summary.head()) ``` -------------------------------- ### Identify Low Value Nodes (LVN) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Provides a Pandas Series of price levels with local volume minima, indicating areas where price traded relatively little. These nodes act as thin zones for quick price movement and are often used as targets or support/resistance levels. Requires MarketProfile and pandas. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.low_value_nodes) # Close # 928.00 13627 # 931.25 30366 # ... # Name: Volume, dtype: int64 # LVN price levels as a list lvn_prices = mp_slice.low_value_nodes.index.tolist() print(f"LVN prices: {lvn_prices}") ``` -------------------------------- ### Determine Open Range (OR) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Returns the price range covered during the open range period, defaulting to the first 10 minutes. This range is used to capture early price discovery and as a breakout or reference level. Requires MarketProfile and pandas. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05, open_range_size=pd.to_timedelta('10 minutes')) mp_slice = mp[df.index.min():df.index.max()] or_low, or_high = mp_slice.open_range() print(f"Open Range: {round(or_low, 2)} – {round(or_high, 2)}") # Open Range: 927.74 – 927.74 ``` -------------------------------- ### MarketProfile.__getitem__(slice) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Slices the MarketProfile object by a timestamp range to create a MarketProfileSlice, which contains pre-computed profile statistics. ```APIDOC ## MarketProfile.__getitem__(slice) — Create a time-range slice ### Description Slices the underlying DataFrame by a timestamp range and returns a `MarketProfileSlice` with all profile statistics pre-computed. The slice must be provided as a Python `slice` object (using the `[start:stop]` syntax). All profile attributes and methods become available on the returned slice object. ### Parameters - **slice** (slice) - Required - A Python slice object defining the start and end timestamps (e.g., `[start_timestamp:end_timestamp]`). ### Request Example ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) # Slice over the full dataset mp_slice = mp[df.index.min():df.index.max()] # Slice a single trading session session_start = pd.Timestamp('2017-06-01 09:30:00') session_end = pd.Timestamp('2017-06-01 16:00:00') session_slice = mp[session_start:session_end] # Access the raw profile Series print(mp_slice.profile) ``` ### Response #### Success Response (MarketProfileSlice) - **profile** (Pandas Series) - The core profile distribution (volume or TPO counts per price level). - Other attributes and methods for accessing profile statistics. ``` -------------------------------- ### Determine Balanced Target Price Source: https://context7.com/bfolkens/py-market-profile/llms.txt Projects a price target based on profile symmetry around the Point of Control (POC). If the profile extends further above the POC, the target is projected an equal distance below, and vice versa. Requires MarketProfile and pandas. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.balanced_target) # 961.25 print(mp_slice.poc_price) # 944.5 # Area above POC: 959.3 - 944.5 = 14.8 → BT = 944.5 + 16.75 = 961.25 ``` -------------------------------- ### Calculate Balanced Target Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Calculate a potential price target based on the concept of market balance. This is a derived metric used in some trading strategies. ```pycon mp_slice.balanced_target ``` -------------------------------- ### MarketProfileSlice.profile Source: https://context7.com/bfolkens/py-market-profile/llms.txt Provides the core profile distribution as a Pandas Series, indexed by price level and containing volume or TPO counts. ```APIDOC ## MarketProfileSlice.profile — Volume/TPO distribution Series ### Description A Pandas Series indexed by price level (rounded to `row_size`) containing either the total traded volume (`vol` mode) or the count of time periods (`tpo` mode) at each price. This is the core histogram from which all other Market Profile statistics are derived. ### Response #### Success Response (Pandas Series) - **Index**: Price level (float). - **Values**: Volume (int) or Time Period Count (int). ### Request Example ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] profile = mp_slice.profile print(profile) # Access total volume print(mp_slice.total_volume) # Plot the profile profile.plot.barh(title='Volume Profile', figsize=(8, 12)) ``` ``` -------------------------------- ### Calculate Value Area Low and High (VAL/VAH) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Calculates the price range containing a specified percentage (default 70%) of total traded volume, expanding from the POC. Ensure MarketProfile and pandas are imported. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05, value_area_pct=0.70) mp_slice = mp[df.index.min():df.index.max()] val, vah = mp_slice.value_area print(f"Value Area Low (VAL): {val}") # 944.2 print(f"Value Area High (VAH): {vah}") # 958.95 # Check if current price is inside the value area current_price = 950.00 inside_va = val <= current_price <= vah print(f"Price {current_price} inside value area: {inside_va}") # True ``` -------------------------------- ### Run Subset of Tests Source: https://github.com/bfolkens/py-market-profile/blob/master/CONTRIBUTING.rst Execute a specific subset of tests by specifying the environment name and a pytest filter. ```bash tox -e envname -- py.test -k test_myfeature ``` -------------------------------- ### MarketProfileSlice.as_dict() Source: https://context7.com/bfolkens/py-market-profile/llms.txt Exports all computed Market Profile statistics for a given slice into a single flat dictionary, facilitating storage, DataFrame construction, or JSON serialization. ```APIDOC ## MarketProfileSlice.as_dict() ### Description Returns all computed Market Profile statistics for the slice in a single flat dictionary, making it easy to store results in a database, build a DataFrame of session statistics, or serialize to JSON. Keys include `or_low`, `or_high`, `ib_low`, `ib_high`, `poc`, `low`, `high`, `val`, `vah`, `bt`, `lvn`, and `hvn`. ### Usage ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] stats = mp_slice.as_dict() print(stats) # { # 'or_low': 927.74, 'or_high': 927.74, # 'ib_low': 927.74, 'ib_high': 935.53, # 'poc': 944.50, # 'low': 927.75, 'high': 959.30, # 'val': 944.20, 'vah': 958.95, # 'bt': 961.25, # 'lvn': , # 'hvn': # } # Build a DataFrame of per-session statistics sessions = [] for date, session_df in df.groupby(df.index.date): mp_s = MarketProfile(session_df, row_size=0.05) sl = mp_s[session_df.index.min():session_df.index.max()] row = {k: v for k, v in sl.as_dict().items() if k not in ('lvn', 'hvn')} row['date'] = date sessions.append(row) summary = pd.DataFrame(sessions).set_index('date') print(summary.head()) ``` ``` -------------------------------- ### MarketProfileSlice.profile_range Source: https://context7.com/bfolkens/py-market-profile/llms.txt Retrieves the full price range (minimum and maximum) of the market profile for a given time slice. ```APIDOC ## MarketProfileSlice.profile_range ### Description A tuple `(low_price, high_price)` representing the minimum and maximum price levels present in the profile distribution for the sliced time range. ### Usage ```python low, high = mp_slice.profile_range print(f"Profile range: {low} – {high}") ``` ### Returns - `tuple`: A tuple containing the low price and high price of the profile range. ``` -------------------------------- ### Plot Market Profile Source: https://github.com/bfolkens/py-market-profile/blob/master/examples/example.ipynb Generates a bar plot of the calculated market profile data for the selected slice. ```python data = mp_slice.profile data.plot(kind='bar') ``` -------------------------------- ### Calculate Open Range Source: https://github.com/bfolkens/py-market-profile/blob/master/docs/index.md Calculate the open range, which represents the high and low prices of the trading session. This is returned as a tuple of (low, high) prices. ```pycon mp_slice.open_range() ``` -------------------------------- ### MarketProfileSlice.low_value_nodes Source: https://context7.com/bfolkens/py-market-profile/llms.txt Provides a Pandas Series of price levels that represent local volume minima (Low Value Nodes) within the profile. ```APIDOC ## MarketProfileSlice.low_value_nodes ### Description A Pandas Series of price levels that are local volume minima within the profile — areas where price traded relatively little. Low value nodes act as thin zones where price tends to move through quickly, and are often used as price targets or areas of low support/resistance. ### Usage ```python print(mp_slice.low_value_nodes) lvn_prices = mp_slice.low_value_nodes.index.tolist() print(f"LVN prices: {lvn_prices}") ``` ### Returns - `pandas.Series`: A Series where the index represents the price levels of the Low Value Nodes and the values represent their corresponding volumes. ``` -------------------------------- ### Round Price to Nearest Market Profile Row Boundary Source: https://context7.com/bfolkens/py-market-profile/llms.txt Rounds a given price value up to the nearest configured row boundary based on the `row_size` parameter. This utility is used internally for building the profile histogram and can be used externally to map prices onto the profile grid. ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, tick_size=0.05) print(mp.round_to_row(0.10)) # 0.10 (already on boundary) print(mp.round_to_row(0.11)) # 0.15 (rounds up to next row) print(mp.round_to_row(0.15)) # 0.15 (already on boundary) print(mp.round_to_row(944.42)) # 944.45 # Map a list of prices to their profile row prices = [927.74, 935.22, 944.01, 959.30] rows = [mp.round_to_row(p) for p in prices] print(rows) # [927.75, 935.25, 944.05, 959.30] ``` -------------------------------- ### MarketProfileSlice.high_value_nodes Source: https://context7.com/bfolkens/py-market-profile/llms.txt Retrieves a Pandas Series of price levels that are local volume maxima within the profile, representing areas of acceptance that can act as support/resistance. ```APIDOC ## MarketProfileSlice.high_value_nodes ### Description A Pandas Series of price levels that are local volume maxima within the profile — areas where significant volume was traded. High value nodes represent price areas of acceptance and often act as support/resistance zones or areas where price consolidates. ### Usage ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.high_value_nodes) # Close # 944.50 186489 # 951.75 238489 # ... # Name: Volume, dtype: int64 hvn_prices = mp_slice.high_value_nodes.index.tolist() print(f"HVN prices: {hvn_prices}") ``` ``` -------------------------------- ### MarketProfileSlice.balanced_target Source: https://context7.com/bfolkens/py-market-profile/llms.txt Determines the Balanced Target price, a projected price target based on profile symmetry around the Point of Control (POC). ```APIDOC ## MarketProfileSlice.balanced_target ### Description The projected price target based on profile symmetry around the POC. If the profile extends further above the POC, the balanced target is projected an equal distance below (and vice versa). Useful for identifying potential mean-reversion or extension targets. ### Usage ```python balanced_target = mp_slice.balanced_target print(balanced_target) ``` ### Returns - `float`: The calculated Balanced Target price. ``` -------------------------------- ### MarketProfile.round_to_row(x) Source: https://context7.com/bfolkens/py-market-profile/llms.txt Rounds a given price value up to the nearest configured row boundary (`row_size`), useful for mapping arbitrary prices onto the profile grid. ```APIDOC ## MarketProfile.round_to_row(x) ### Description A utility method that rounds any price value up to the nearest configured row boundary (`row_size`). Used internally when building the profile histogram, but also available for external use when mapping arbitrary prices onto the profile grid. ### Usage ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, tick_size=0.05) print(mp.round_to_row(0.10)) # 0.10 (already on boundary) print(mp.round_to_row(0.11)) # 0.15 (rounds up to next row) print(mp.round_to_row(0.15)) # 0.15 (already on boundary) print(mp.round_to_row(944.42)) # 944.45 # Map a list of prices to their profile row prices = [927.74, 935.22, 944.01, 959.30] rows = [mp.round_to_row(p) for p in prices] print(rows) # [927.75, 935.25, 944.05, 959.30] ``` ``` -------------------------------- ### MarketProfileSlice.value_area Source: https://context7.com/bfolkens/py-market-profile/llms.txt Calculates the Value Area Low (VAL) and Value Area High (VAH), which represent the price range containing a specified percentage of the total volume. ```APIDOC ## MarketProfileSlice.value_area ### Description A tuple `(VAL, VAH)` — the price range that contains the configured percentage (default 70%) of total traded volume. The value area expands outward from the POC, preferring the side with higher volume at each step, until the cumulative volume threshold is met. ### Usage ```python val, vah = mp_slice.value_area print(f"Value Area Low (VAL): {val}") print(f"Value Area High (VAH): {vah}") ``` ### Returns - `tuple`: A tuple containing the Value Area Low (VAL) and Value Area High (VAH). ``` -------------------------------- ### MarketProfileSlice.poc_price Source: https://context7.com/bfolkens/py-market-profile/llms.txt Returns the price level with the highest traded volume or TPO count within the slice, representing the Point of Control. ```APIDOC ## MarketProfileSlice.poc_price — Point of Control price ### Description The price level with the highest traded volume (or most TPO periods) in the slice. When multiple price levels share the same maximum volume, the one closest to the midpoint of the distribution is selected. Returns `None` if the profile is empty. ### Response #### Success Response (float or None) - **poc_price**: The price level of the Point of Control (float), or `None` if the profile is empty. - **poc_volume**: The volume (or TPO count) at the Point of Control (int). ### Request Example ```python import pandas as pd from market_profile import MarketProfile df = pd.read_csv('data/GOOG_1min.csv', index_col=['Timestamp'], parse_dates=['Timestamp']) mp = MarketProfile(df, row_size=0.05) mp_slice = mp[df.index.min():df.index.max()] print(mp_slice.poc_price) # Example output: 944.5 print(mp_slice.poc_volume) # Example output: 186489 ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.