Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. mobile.mr_mime
    3. Best
    M
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 2
    • Groups 0
    • Blog

    Best posts made by mobile.mr_mime

    • Trying to understand trading

      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
      frml.png

      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();
      
      posted in Support
      M
      mobile.mr_mime
    • RE: Trying to understand trading

      @support Thanks for the detailed answer, that seems to be it, here is the final code:

      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
      next_price_open = data.sel(field="open").shift(time=-1)
      next2_price_open = data.sel(field="open").shift(time=-2)
      weights = xr.where(next_price_open < next2_price_open, 1.0, 0.0)
      # sell short when optimal:
      # weights = xr.where(next_price_open > next2_price_open, -1.0, weights)
      
      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();
      
      posted in Support
      M
      mobile.mr_mime
    • Documentation
    • About
    • Career
    • My account
    • Privacy policy
    • Terms and Conditions
    • Cookies policy
    Home
    Copyright © 2014 - 2021 Quantiacs LLC.
    Powered by NodeBB | Contributors