Support Board
Date/Time: Sat, 23 Nov 2024 15:02:35 +0000
Post From: Python for Sierra Chart
[2024-05-05 15:10:40] |
User656492 - Posts: 143 |
<BUMP> I'm using code from above: import sys
from pathlib import Path import numpy as np import pandas as pd def get_scid_df(filename, limitsize=sys.maxsize): f = Path('/Users/Me/SierraPython/NQM4.CME.scid' ) assert f.exists(), f"{f} file not found" stat = f.stat() offset = 56 if stat.st_size < limitsize else stat.st_size - ((limitsize // 40) * 40) sciddtype = np.dtype( [ ("Time", "<u8"), ("Open", "<f4"), ("High", "<f4"), ("Low", "<f4"), ("Close", "<f4"), ("Trades", "<i4"), ("Volume", "<i4"), ("BidVolume", "<i4"), ("AskVolume", "<i4"), ] ) df = pd.DataFrame( data=np.memmap(f, dtype=sciddtype, offset=offset, mode="r"), copy=False ) df.dropna(inplace=True) df["Time"] = df["Time"] - 2209161600000000 df.drop(df[(df.Time < 1)].index, inplace=True) df.set_index("Time", inplace=True) df.index = pd.to_datetime(df.index, unit="us") df.index = df.index.tz_localize(tz="utc") return df def resample_scdf(scdf_or_filename, period="1Min", tz="UTC", limitsize=sys.maxsize): df = ( get_scid_df(scdf_or_filename, limitsize) if isinstance(scdf_or_filename, str) else scdf_or_filename ) assert isinstance( df, pd.DataFrame ), f"{scdf_or_filename} has to be SC df or valid scid file" df = df.resample(period).agg( { "Open": "first", "High": "max", "Low": "min", "Close": "last", "Trades": "sum", "Volume": "sum", "BidVolume": "sum", "AskVolume": "sum", } ) if tz != "UTC": tz = "America/New_York" if tz == "EST" else tz tz = "America/Los_Angeles" if tz == "PST" else tz df.index = df.index.tz_convert(tz) return df print(resample_scdf("NQM4.CME.scid", tz="EST")) And I get this: Open High Low Close \ Time 2024-02-25 19:01:00-05:00 0.000000e+00 1822300.0 1822125.0 1822125.0 2024-02-25 19:02:00-05:00 -1.999001e+37 1820775.0 1820275.0 1820775.0 2024-02-25 19:03:00-05:00 0.000000e+00 1820850.0 1820250.0 1820875.0 2024-02-25 19:04:00-05:00 0.000000e+00 1820900.0 1820025.0 1820625.0 2024-02-25 19:05:00-05:00 0.000000e+00 1820700.0 1819900.0 1820600.0 ... ... ... ... ... 2024-04-30 12:20:00-04:00 0.000000e+00 1777300.0 1776650.0 1777175.0 2024-04-30 12:21:00-04:00 0.000000e+00 1777625.0 1776950.0 1777000.0 2024-04-30 12:22:00-04:00 0.000000e+00 1777350.0 1776950.0 1777150.0 2024-04-30 12:23:00-04:00 -1.999001e+37 1777575.0 1776900.0 1777175.0 2024-04-30 12:24:00-04:00 -1.999001e+37 1777350.0 1777125.0 1777175.0 Trades Volume BidVolume AskVolume Time 2024-02-25 19:01:00-05:00 1 1 1 0 2024-02-25 19:02:00-05:00 2 2 0 2 2024-02-25 19:03:00-05:00 4 4 0 4 2024-02-25 19:04:00-05:00 10 10 0 10 2024-02-25 19:05:00-05:00 6 6 2 4 ... ... ... ... ... 2024-04-30 12:20:00-04:00 869 959 376 583 2024-04-30 12:21:00-04:00 861 1023 430 593 2024-04-30 12:22:00-04:00 462 518 225 293 2024-04-30 12:23:00-04:00 522 548 279 269 2024-04-30 12:24:00-04:00 58 58 18 40 [93144 rows x 8 columns] As you can see the Open field is fubar. I think time stamp is being parsed incorrectly but have no idea how to address it. Any thoughts? |