2022-03-28

how do i parse log data and extract time, profit,position,volume from text file into a dataframes and plot profit vs time volume vs time

03/17/17 10:30:01.511363338 W (leg0)1621573201394718152:TRADE:ins=BSE/GBPINR17JUNEFUT,q=1,p=893900000,pos=0,risk_pos=0,cashflow=-89390.000000,pnl=-18.050891,net_pnl=-18.050891,tgt=893935108.275274,market_volume=16229,bbo=91/893900000 893975000/136, qty_behind=91,realized_pnl=-18.050891,unrealized_pnl=0.00000093711,market_volume=16229,bbo=91/893900000 893975000/136, qty_behind=91,realized_pnl=-18.050891,unrealized_pnl=0.000000

My code:

import datetime as dt import pandas as pd import numpy as np import re import matplotlib.pyplot as plt

filename='C:\Users\Goog\Downloads\loggg.txt' pp=[]

pnl=re.compile(r',pnl=(-?[\d]+.\d{6})\b') vol=re.compile(r'market_volume=(\d{5})')

result = [] vol1=[] with open(filename) as n: line=n.readline() while line: result +=re.findall(pnl , line) vol1+=re.findall(vol ,line) line = n.readline() print(result,vol1)

I need to parse the data only if :trade happens, note this is only one single line of data in the entire log file.


import datetime as dt
import pandas as pd
import numpy as np
import re
import matplotlib.pyplot as plt


filename='C:\\Users\\googg\Downloads\\loggg.txt'
pp=[]

pnl=re.compile(r',pnl=(-?[\d]+.\d{6})\b')
vol=re.compile(r'market_volume=(\d{5})')

result = []
vol1=[]
with open(filename) as n:
    line=n.readline()
    while line:
        result +=re.findall(pnl , line)
        vol1+=re.findall(vol ,line)
        line = n.readline()
print(result,vol1)

how do i combine both the date into a single dataframe also i need to extract time and put all of them together in a single data frame such as index is time and rest pnl,volume are set in columns?



No comments:

Post a Comment