HLdensity()
The High and Low - Range Density for a ticker.
Class: HLdensity
HLdensity
Method: run
run
The run
method is the primary entry point for executing the analysis. It fetches and processes the data, and optionally displays a chart or prints high/low data.
Arguments
client (
str
): The data provider to use for fetching historical data. Currently, the class supports'yahoo'
as the client for Yahoo Finance.ticker_symbol (
str
): The stock ticker symbol (e.g.,'AAPL'
,'SPY'
). This specifies the stock for which the OHLC data will be fetched.days (
int
, optional): The number of past days to fetch the OHLC data for. Default is100
.chart (
bool
, optional): Set toTrue
to generate and display a density map chart of the price movements. Default isFalse
.printdata (
bool
, optional): Set toTrue
to print the high and low price order for each day. Default isFalse
.
Returns
None: This method does not return a value but prints the output or plots a chart depending on the
printdata
andchart
parameters.
Usage Guide
Step 1: Initialize the Data Provider
Currently, the HLdensity
class supports Yahoo Finance as the data provider. You must specify 'yahoo'
as the client
argument to fetch data from Yahoo Finance.
Step 2: Select the Stop Timeframe
Specify the stock ticker symbol and the number of days for which you want to analyze the stock. For example, if you want to analyze Apple stock (AAPL
) over the past 100 days:
Step 3: Run Price Movement Analysis
You can use the HLdensity.run
method to fetch data, normalize it, and print high/low price information or plot a price movement density map. Depending on your requirements, you can choose to print data, generate a chart, or both.
Examples
Example 1: Print High/Low Data to the Terminal
In this example, the high/low price order for the past 100 days of Apple (AAPL
) stock will be printed to the terminal. No chart will be displayed.
Output:
This will print a message for each trading day, indicating whether the day’s low or high was reached first.
Example 2: Generate and Plot a Price Movement Density Map
In this example, a price movement density map for Apple (AAPL
) over the past 100 days will be generated and plotted.
Expected Behavior: A Matplotlib chart will be displayed, showing the price movements over normalized time. The X-axis will represent the normalized time (start of the day to the end), and the Y-axis will show the price movement relative to the opening price.
The chart will look like this:
Customization Options
The HLdensity
class allows for flexible customization of outputs. Below are some of the key options:
Print High/Low Price Order (printdata
)
printdata
)By setting the printdata
argument to True
, you can print a daily log of whether the high or low price was reached first. This can help traders identify recurring patterns in price movements.
Plotting a Price Movement Density Map (chart
)
chart
)When the chart
argument is set to True
, a density map will be plotted using normalized price movements. The chart shows how the stock's price moves relative to the opening price during the day.
Output
When printdata=True
printdata=True
The output will be a printed log of daily high and low price information:
This allows you to see whether the price's low or high point was reached first in each session.
When chart=True
chart=True
The output will be a Matplotlib-generated chart, displaying the normalized price movements. The chart will plot normalized price movements relative to the opening price throughout the day.
Last updated