Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Nifty Crossed 22000. How many days it took to Cross all the Round Numbers: Python Tutorial

1 min read

Nifty today crossed 22000+ levels with a fresh all-time high. Have you ever calculated how many trading days it took for Nifty to move from 21000 to 22000 levels? Did you know that Nifty took 38 days to move from 21000 levels to 22000 levels? In this Python tutorial, we will be computing the duration it took for the Nifty to transition between two consecutive round numbers starting from 1000 to 22000 levels.

MilestoneFirst Date Crossed (Based on ‘High’)Days Taken to Reach from Previous Milestone
10001992-03-09NaN
20002004-01-094323
30002006-01-30752
40002006-12-01305
50002007-09-27300
60002007-11-0135
70002014-05-122384
80002014-09-01112
90002015-03-03183
100002017-07-25875
110002018-01-23182
120002019-05-23485
130002020-11-24551
140002020-12-3137
150002021-02-0536
160002021-08-03179
170002021-08-3128
180002021-10-1141
190002023-06-28625
200002023-09-1175
210002023-12-0888
220002024-01-1538

Python Code to Fetch the Dates When the Round Number Milestones crossed along with the time taken

Prerequisites

  • Basic understanding of Python.
  • Pandas library installed (pip install pandas).
import pandas as pd

# URL of the CSV file
csv_url = 'https://raw.githubusercontent.com/marketcalls/data/main/NIFTY_daily_data.csv'

# Load the CSV file from the URL
data = pd.read_csv(csv_url)

# Convert the date column to datetime for easier calculations
data['date'] = pd.to_datetime(data['date'])

# Generate the milestones list using a for loop
milestones = [i * 1000 for i in range(1, 23)]  # Generates 1000, 2000, ..., 22000

# Function to find the first date a milestone is reached and days to reach next milestone
def find_milestone_dates(data, column):
    milestone_data = []
    last_milestone_date = None

    for milestone in milestones:
        # Finding the first occurrence where the milestone was crossed
        milestone_record = data[data[column] >= milestone].iloc[0]
        milestone_date = milestone_record['date']

        # Calculating days taken from the last milestone
        if last_milestone_date is not None:
            days_taken = (milestone_date - last_milestone_date).days
        else:
            days_taken = None  # For the first milestone

        milestone_data.append({
            'Milestone': milestone,
            'First Date Crossed': milestone_date,
            'Days Taken': days_taken
        })

        # Updating the last milestone date
        last_milestone_date = milestone_date

        milestone_df = pd.DataFrame(milestone_data)
        # Convert 'Days Taken' to integer, handling NaN values
        milestone_df['Days Taken'] = milestone_df['Days Taken'].astype('Int64')


    return milestone_df

# Analysis using the 'high' column
milestone_data_high = find_milestone_dates(data, 'high')

# Display the results for the 'high' column analysis
print("Analysis using the 'high' column:")
print(milestone_data_high)

Python Output

Analysis using the 'high' column:
    Milestone First Date Crossed  Days Taken
0        1000         1992-03-09        <NA>
1        2000         2004-01-09        4323
2        3000         2006-01-30         752
3        4000         2006-12-01         305
4        5000         2007-09-27         300
5        6000         2007-11-01          35
6        7000         2014-05-12        2384
7        8000         2014-09-01         112
8        9000         2015-03-03         183
9       10000         2017-07-25         875
10      11000         2018-01-23         182
11      12000         2019-05-23         485
12      13000         2020-11-24         551
13      14000         2020-12-31          37
14      15000         2021-02-05          36
15      16000         2021-08-03         179
16      17000         2021-08-31          28
17      18000         2021-10-11          41
18      19000         2023-06-28         625
19      20000         2023-09-11          75
20      21000         2023-12-08          88
21      22000         2024-01-15          38

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Voice Commands to Trade on OpenAlgo Platform Using Google…

Trading platforms are always getting better by using the newest technologies to make things easier and more efficient for users. A great example of...
Rajandran R
5 min read

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

How to Place Orders Concurrently using ThreadPoolExecutor – Python…

Creating concurrent orders is essential for active traders, especially those handling large funds, as it allows for executing multiple trade orders simultaneously, thereby maximizing...
Rajandran R
2 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More