jealous / stockstats

Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support.
Other
1.29k stars 299 forks source link

calculating high price in the next 10 periods #135

Closed maciejbak85 closed 1 year ago

maciejbak85 commented 1 year ago

There is Max Min period:

Max and Min of the Periods Retrieve the max/min value of specified periods. They require column and window. Note the window does NOT simply stand for the rolling window.

Examples:

close_-3,2max stands for the max of 2 periods later and 3 periods ago close-2~0_min stands for the min of 2 periods ago till now I think I dont get how it work.. I want to every row to see what is Max value for Close price in NEXT 5 rows.

ie:

start_date =  "2022-01-01"
end_date =  "2022-02-28"

df = yf.download("EURUSD=X",
                 start="2023-01-13",
                 end="2023-02-28")

stock_df = StockDataFrame.retype(df)

stock_df["close_0,5_max"]

print(stock_df)

this gives me:

                open      high       low     close  adj close  volume  close_0_s  close_5_s  close_0,5_max
Date                                                                                                      
2023-01-13  1.086024  1.086779  1.078063  1.086024   1.086024       0   1.086024   1.083388       1.086024
2023-01-16  1.082462  1.087548  1.080264  1.082462   1.082462       0   1.082462   1.086508       1.086508
2023-01-17  1.083013  1.086909  1.078702  1.083013   1.083013       0   1.083013   1.087429       1.087429
2023-01-18  1.079331  1.088447  1.076704  1.079331   1.079331       0   1.079331   1.088815       1.088815
2023-01-19  1.079785  1.083306  1.078295  1.079785   1.079785       0   1.079785   1.092204       1.092204
2023-01-20  1.083388  1.085658  1.080462  1.083388   1.083388       0   1.083388   1.089443       1.089443
2023-01-23  1.086472  1.091953  1.084752  1.086508   1.086508       0   1.086508   1.087146       1.087146
2023-01-24  1.087429  1.089681  1.083929  1.087429   1.087429       0   1.087429   1.085069       1.087429
2023-01-25  1.088815  1.092263  1.085812  1.088815   1.088815       0   1.088815   1.086095       1.088815
2023-01-26  1.092204  1.093255  1.085164  1.092204   1.092204       0   1.092204   1.101285       1.101285
2023-01-27  1.089443  1.090156  1.083882  1.089443   1.089443       0   1.089443   1.090513       1.090513

I wonder why for example in this row:

2023-01-20  1.083388  1.085658  1.080462  1.083388   1.083388       0   1.089443       1.089443
as a result is 1.089443 instead of 1.092204..

can someone help me ? thanks

jealous commented 1 year ago

To retrieve the move max of close in 10 days, you can now us:

stock_df.mov_max(stock_df['close'], 10)