A trader wants to place an order with the amount of W before NASDAQ closes, how the trader should break up the order volume to gain the highest profit?
QUANTCONNECT COMMUNITY
A trader wants to place an order with the amount of W before NASDAQ closes, how the trader should break up the order volume to gain the highest profit?
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Milad Resketi
Â
plt.style.use('ggplot') # fetch data start_date = datetime(2017, 1, 1, 0, 0) end_date = datetime(2017, 12, 31, 23, 59) instruments = "AMZN" qb = QuantBook() security = qb.AddEquity(instruments) # add equity data history = qb.History(security.Symbol, start_date, end_date, Resolution.Minute) # primary inputs W = 100 #number of stocks to buy # Frei-Yan parameters alpha = 5.72e-6 beta = 1e-6 lamda = 5e-4 sigma_N = 6.6e8 sigma_Z = 1.96e-8 sigma_Y = 3.21e-8 for T in [20, 25, 30, 35, 40, 45]: #look back time in minute from 16:00pm NYC market close Tau = T-10 #look back time in minute from 16:00pm NYC market inital imbalance market_close_time = datetime(1974, 1, 1, 16, 0) market_before_close_time = datetime(1974, 1, 1, 16, 0)-timedelta(minutes=T-1) # Frei-Yan variables m_t = np.arange(T,0,-1)*lamda*sigma_Z+lamda*sigma_Y+lamda*sigma_N*alpha**2+alpha x_plus = 1+lamda*sigma_Z/(2*beta)+((lamda*sigma_Z/beta)*(1+(lamda*sigma_Z/(4*beta))))**0.5 x_minus = 1+lamda*sigma_Z/(2*beta)-((lamda*sigma_Z/beta)*(1+(lamda*sigma_Z/(4*beta))))**0.5 p_t = (1+lamda*sigma_Z/beta-x_minus)*(x_plus**np.arange(1,T+1))/(x_plus**2-1) + (1+lamda*sigma_Z/beta-x_plus)*(x_minus**np.arange(1,T+1))/(x_minus**2-1) # Frei-Yan weights v = np.zeros(T) v[0] = alpha*W/(2*(beta+m_t[0]+sum(p_t[1:Tau-1]*m_t[1:Tau-1]))) v[1:Tau-1] = p_t[1:Tau-1]*v[0] v[T-1] = W-(1+sum(p_t[1:Tau-1]))*v[0] # calculation df0 = history.reset_index().drop(columns=["symbol"]).set_index("time") df0 = df0.between_time(market_before_close_time.time(), market_close_time.time()) df1 = W*df0[["close"]].groupby(df0.index.date).last() df1["Frei-Yan close"] = df0["close"].groupby(df0.index.date).apply(lambda x:sum(x*v)) try: df2[f"T = {T} minutes"] = (100*(df1["close"]-df1["Frei-Yan close"])/(df1["close"])).cumsum() except: df2 = pd.DataFrame(index=df1.index) df2[f"T = {T} minutes"] = (100*(df1["close"]-df1["Frei-Yan close"])/(df1["close"])).cumsum() # plot ax = df2.plot(figsize=(18,8)) ax.set_ylabel("Frei-Chan Cumulative Relative Performance(%)")
Shile Wen
Hi Milad,
Thanks for sharing this! It'd be awesome if someone incorporated this research into their algorithm.
Best,
Shile Wen
Milad Resketi
Hi Shile,
Yes, I've been thinking about turning into an execution model. I need a bit more time to read about how to estimate Frei-Yan parameters.
I keep you updated on how I went with it.
Milad Resketi
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!