Back to Community
How can I shift the date to the nearest trading day?

I want to close all my position before er earnings to lower the volatility.
My data looks like:

date symbol
2010/1/10 mu
2010/1/12 aapl
....

so, I want to close all position on 2010/1/9 if I have mu, and close all position on 2010/1/11 if I have aapl.
I am trying to shift the dataframe by shift(1,freq='D'), but if 2010/1/9 is Sat. I want to shift to 2010/1/8,which
is a trading day.
Can someone help me on this?

Best

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59fbc012bc13113f01382a63
There was a runtime error.
1 response

sorry, I attached the wrong algorithm

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59fbe9a0c9259d444661fc15
There was a runtime error.