Changing file name as Stock_name and the series #99
Closed
cotton1234
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
You can actually filter the latest bhavcopy by the stock series. See the below code. The latest bhav copy is stored in Stocks keep flipping between BE and EQ. Keeping track of their status would require a lot of extra code. from typing import Literal, Union
import pandas as pd
from pathlib import Path
from datetime import datetime
def filter_stock_by_series(
date: Union[str, datetime],
series: Literal["EQ", "BE", "BZ", "SM", "ST"],
folder: Union[str, Path],
) -> pd.Index:
"""
Filter bhavcopy by series and return the pandas index
date: iso format string or Datetime
series: stock series string
folder: Path to src/nseBhav
"""
if isinstance(folder, str):
folder = Path(folder).expanduser().resolve()
if isinstance(date, str):
date = datetime.fromisoformat(date)
dt_str = f"{date:%d%b%Y}".upper()
file = folder / str(date.year) / f"cm{dt_str}bhav.csv"
df = pd.read_csv(file, index_col="SYMBOL")
return df[df["SERIES"] == series].index
if __name__ == "__main__":
filtered_series = filter_stock_by_series(
"2024-02-05", "BE", "~/Documents/python/eod2/src/nseBhav"
)
for sym in filtered_series:
print(sym) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Benny,
As of now , the code is just using stock name as the file name without the series appended to it.
Is it possible to add the series to the file name,
I know it will change the logic and also all the files need to be changed.
Why i saying so is, if we code any strategy on top if it, then it is difficult to pick the stock based on series as some times we need to trade in BE series stock so focus will be there only.
Let me know what you think.
Thanks
Saurabh
Beta Was this translation helpful? Give feedback.
All reactions