CODE:-
from datetime import date
from datetime import timedelta
from nsepy import get_history
import pandas as pd
import datetime
end1 = date.today()
start1 = end1 - timedelta(days=180)
stock = ['RELIANCE']#,'HDFCBANK','INFY','ICICIBANK','HDFC'] ,'TCS','KOTAKBANK','LT','SBIN','HINDUNILVR','AXISBANK',
# 'ITC','BAJFINANCE','BHARTIARTL','ASIANPAINT','HCLTECH','MARUTI','TITAN','BAJAJFINSV','TATAMOTORS',
# 'TECHM','SUNPHARMA','TATASTEEL','M&M','WIPRO','ULTRACEMCO','POWERGRID','HINDALCO','NTPC','NESTLEIND',
# 'GRASIM','ONGC','JSWSTEEL','HDFCLIFE','INDUSINDBK','SBILIFE','DRREDDY','ADANIPORTS','DIVISLAB','CIPLA',
# 'BAJAJ-AUTO','TATACONSUM','UPL','BRITANNIA','BPCL','EICHERMOT','HEROMOTOCO','COALINDIA','SHREECEM','IOC']
for stock in stock:
vol = get_history(symbol=stock,
start=start1,
end=end1)
d_vol = pd.concat([vol['Deliverable Volume']])
symbol_s = pd.concat([vol['Symbol']])
close = pd.concat([vol['Close']])
df = pd.DataFrame(symbol_s)
df['D_vol'] = d_vol
pd.set_option('display.max_columns',10)
pd.set_option('display.max_rows',200)
print(df)
PRODUCT:-
Symbol D_vol
Date
2022-02-17 RELIANCE 2872619
2022-02-18 RELIANCE 1216161
2022-02-21 RELIANCE 2888548
2022-02-22 RELIANCE 3920789
2022-02-23 RELIANCE 1928054
2022-02-24 RELIANCE 7266877
2022-02-25 RELIANCE 3670287
2022-02-28 RELIANCE 5321030
2022-03-02 RELIANCE 6277829
2022-03-03 RELIANCE 2479449
2022-03-04 RELIANCE 2754095
2022-03-07 RELIANCE 4962748
2022-03-08 RELIANCE 5602260
2022-03-09 RELIANCE 4647153
2022-03-10 RELIANCE 4102149
2022-03-11 RELIANCE 3028604
2022-03-14 RELIANCE 1800381
2022-03-15 RELIANCE 3924279
2022-03-16 RELIANCE 2824434
2022-03-17 RELIANCE 5961590
2022-03-21 RELIANCE 3019258
2022-03-22 RELIANCE 5753732
2022-03-23 RELIANCE 4321837
2022-03-24 RELIANCE 3208900
2022-03-25 RELIANCE 3821279
2022-03-28 RELIANCE 2149565
2022-03-29 RELIANCE 2280912
2022-03-30 RELIANCE 4259734
2022-03-31 RELIANCE 3893403
2022-04-01 RELIANCE 1845831
2022-04-04 RELIANCE 1859891
2022-04-05 RELIANCE 3962890
2022-04-06 RELIANCE 3640461
2022-04-07 RELIANCE 4936384
2022-04-08 RELIANCE 4458242
2022-04-11 RELIANCE 2103573
2022-04-12 RELIANCE 4019726
2022-04-13 RELIANCE 3009160
2022-04-18 RELIANCE 3079230
2022-04-19 RELIANCE 6735937
2022-04-20 RELIANCE 5767347
2022-04-21 RELIANCE 5151153
2022-04-22 RELIANCE 3113096
2022-04-25 RELIANCE 4210856
2022-04-26 RELIANCE 2382379
2022-04-27 RELIANCE 4014016
2022-04-28 RELIANCE 6937716
2022-04-29 RELIANCE 4308908
2022-05-02 RELIANCE 1939501
2022-05-04 RELIANCE 4758487
2022-05-05 RELIANCE 4135949
2022-05-06 RELIANCE 4117945
2022-05-09 RELIANCE 3496083
2022-05-10 RELIANCE 4214002
2022-05-11 RELIANCE 3471644
2022-05-12 RELIANCE 5344949
2022-05-13 RELIANCE 4652716
2022-05-16 RELIANCE 3089139
2022-05-17 RELIANCE 4085578
2022-05-18 RELIANCE 3948750
2022-05-19 RELIANCE 3713450
2022-05-20 RELIANCE 5198311
2022-05-23 RELIANCE 3078691
2022-05-24 RELIANCE 3094755
2022-05-25 RELIANCE 2740033
2022-05-26 RELIANCE 3568836
2022-05-27 RELIANCE 3519149
2022-05-30 RELIANCE 2716871
2022-05-31 RELIANCE 19734107
2022-06-01 RELIANCE 2072536
2022-06-02 RELIANCE 4788206
2022-06-03 RELIANCE 5136072
2022-06-06 RELIANCE 1680712
2022-06-07 RELIANCE 2712556
2022-06-08 RELIANCE 3012536
2022-06-09 RELIANCE 4301647
2022-06-10 RELIANCE 4608963
2022-06-13 RELIANCE 4242241
2022-06-14 RELIANCE 3299932
2022-06-15 RELIANCE 1888736
2022-06-16 RELIANCE 3664860
2022-06-17 RELIANCE 5410573
2022-06-20 RELIANCE 2410448
2022-06-21 RELIANCE 1906058
2022-06-22 RELIANCE 2129069
2022-06-23 RELIANCE 2980195
2022-06-24 RELIANCE 3440303
2022-06-27 RELIANCE 4127406
2022-06-28 RELIANCE 2590698
2022-06-29 RELIANCE 3617967
2022-06-30 RELIANCE 5419202
2022-07-01 RELIANCE 16124097
2022-07-04 RELIANCE 8925205
2022-07-05 RELIANCE 3241427
2022-07-06 RELIANCE 5356881
2022-07-07 RELIANCE 6400200
2022-07-08 RELIANCE 5266144
2022-07-11 RELIANCE 2790542
2022-07-12 RELIANCE 2091493
2022-07-13 RELIANCE 3820557
2022-07-14 RELIANCE 3162562
2022-07-15 RELIANCE 2013822
2022-07-18 RELIANCE 3641338
2022-07-19 RELIANCE 3280412
2022-07-20 RELIANCE 5571093
2022-07-21 RELIANCE 4032523
2022-07-22 RELIANCE 2374481
2022-07-25 RELIANCE 5024203
2022-07-26 RELIANCE 2368186
2022-07-27 RELIANCE 2097378
2022-07-28 RELIANCE 2973888
2022-07-29 RELIANCE 3783646
2022-08-01 RELIANCE 3695549
2022-08-02 RELIANCE 3420282
2022-08-03 RELIANCE 3725408
2022-08-04 RELIANCE 3215051
2022-08-05 RELIANCE 4106312
2022-08-08 RELIANCE 2615697
2022-08-10 RELIANCE 2941793
2022-08-11 RELIANCE 2296573
2022-08-12 RELIANCE 2683554
PROBLEM:-
See in above data frame there are around 180 rows. I have a list of 50 stocks but here I have displayed only one stock and its product and 49 comment out.
Now from the above data frame column D_vol
contains around 180 rows. My criteria is that the last row of column D_vol
should contain highest number than previous 90 rows or more than 90 rows. And if this condition satisfy any stock then it should reflect on output table.
ex:- if suppose RELIANCE contain 10000 as D_vol
on 12-aug-2022 and before 12-aug it was contain less than 10000 for 90 days or more than 90 then that stock should reflect on my output table.
thank you.
CodePudding user response:
You can use a condition like this:
result = list()
if df['D_vol'].iloc[-1] > max(df['D_vol'].iloc[-91:-1]):
result.append(df)
Thus you get datasets where the last value is bigger than 90 previous ones.