Hi!
I'm trying to understand how long/short future trading works, by creating an optimal long-only strategy that can see future prices, and invests if there will be profit. This is an unrealistic strategy for the sake of learning.
By looking at the formulas at the link below, we should gain equity if the price of a stock bough long at open is greater at close, and at the open of the next day (ignoring slippage).
https://quantiacs.com/documentation/en/theory/theoretical_basis.html
However, the performance of said strategy is very poor/lossy for some reason (even going constantly long performs way better).
I'm trying to find out why. There is a minimal working example of the strategy below.
Thanks in advance.
import xarray as xr
import qnt.stats as qns
import qnt.output as qnout
import qnt.data as qndata
# single-stock trading
data = qndata.futures.load_data(min_date="2005-01-01", assets=["F_ES"])
# attempting an optimal (unrealistic) long-only strategy
# by looking at future prices, and investing only if there will be profit
price_open = data.sel(field="open")
price_close = data.sel(field="close")
next_price_open = data.sel(field="open").shift(time=-1)
weights = xr.where((price_open < price_close) &
(price_close < next_price_open),
1.0, 0.0)
weights = qnout.clean(weights, data)
qnout.check(weights, data)
qnout.write(weights)
stats = qns.calc_stat(
data, weights,
# ignoring slippage for simplicity
slippage_factor=0, roll_slippage_factor=0)
stats.loc[:, "equity"].plot.step();