Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. Popular
    Log in to post
    • All categories
    • Support
    •      Request New Features
    • Strategy help
    • General Discussion
    • News and Feature Releases
    • All Topics
    • New Topics
    • Watched Topics
    • Unreplied Topics
    • All Time
    • Day
    • Week
    • Month
    • M

      Why we need to limit the time to process the strategy ?
      Support • • multi_byte.wildebeest

      4
      0
      Votes
      4
      Posts
      321
      Views

      support

      @multi_byte-wildebeest Hi, these limitations refer to the processing time per point in time, not for the full strategy.

      If it takes 10 minutes per historical day, and the simulation has to take into account 250 days for let us say 10 years, the multi-pass simulation would process 6 days per hour, 144 days per real day, that means 2 weeks of processing time for the full submission, it is a lot of time.

    • magenta.grimer

      Importing external data
      General Discussion • • magenta.grimer

      4
      1
      Votes
      4
      Posts
      440
      Views

      support

      @penrose-moore Thank you for the idea. For the Bitcoin Futures contest we are indeed patching the Bitcoin Futures data with the BTC spot price to build a meaningful time series. For the other Futures contracts, for the moment we will keep the futures histories only, but add spot prices + patching with spot prices to increase the length of the time series to our to-do list.

    • S

      Stocks strategy
      Strategy help • • spancham

      4
      0
      Votes
      4
      Posts
      489
      Views

      support

      @sheikh Hi, when it comes to stocks and historical simulations, the biggest issue is dealing with survivorship bias. The stock universe must include also stocks which have been delisted and we need to define trading rules which allow for trading instruments which make sense at each point in time. This week we are announing a new contest which is preparing the ground for stocks.

    • magenta.grimer

      Optimizer for simple MA crypto strategy
      Strategy help • • magenta.grimer

      4
      0
      Votes
      4
      Posts
      417
      Views

      A

      There is a way to use the optimizer with a (stateful) mulit pass algo, but depending on the total number of changed parameters it can take a very long time. However, if it runs on a local computer with many workers this can still be useful.

      We could run the backtester with the multi pass algo to get all the weights for the test period and pass these weights to the optimizer.
      There's just one problem with this: you can't pass changed parameters to the strategy using the backtester.
      In order to solve this I created a nested function where the outer function takes the changed parameters from the optimizer. The inner function is the actual multi pass strategy and doesn't define the params but just uses the ones from the outer function. Still within the outer function we run the backtester with one set of params, get the weights it returns and return them to the optimizer.

      The time it takes to run the optimization would roughly be
      (time for 1 multi pass backtest) x (total number of parameter changes) / (number of workers that are able to run)
      So if one multi pass takes 1 minute, you want to optimize 10 parameter changes and can run 5 workers it would take about 2 minutes.

      Here's an example based on the one above with 2 parameter changes and 2 workers:

      import qnt.data as qndata import qnt.ta as qnta import qnt.optimizer as qnop import qnt.backtester as qnbt import xarray as xr def load_data(period): """Loads the BTC Futures data for the BTC Futures contest""" return qndata.cryptofutures.load_data(tail=period, dims=("time", "field", "asset")) def multi_pass_strategy(data, ma_slow_param=50, ma_fast_param=10): """The outer function gets called by the optimizer with changed params, the inner function gets passed to the backtester.""" def strategy(data, state): # The state isn't used in this example, this is just to show that it can be used while optimizing. if state is None: state = 0 state += 1 close = data.sel(field="close") ma_slow = qnta.lwma(close, ma_slow_param).isel(time=-1) ma_fast = qnta.lwma(close, ma_fast_param).isel(time=-1) weights = xr.zeros_like(close.isel(time=-1)) weights[:] = 1 if ma_fast > ma_slow else -1 return weights, state """The backtester returns all weights for the test period which will then be returned to the optimizer""" weights, state = qnbt.backtest( strategy=strategy, competition_type="cryptofutures", load_data=load_data, lookback_period=700, start_date='2014-01-01', build_plots=False, ) return weights data = qndata.cryptofutures.load_data(min_date='2014-01-01') result = qnop.optimize_strategy( data, multi_pass_strategy, qnop.full_range_args_generator( ma_slow_param=range(50, 60, 5), # min, max, step # ma_fast_param=range(5, 100, 5) # min, max, step ), workers=2 # you can set more workers on your PC ) print("---") print("Best iteration:") print(result['best_iteration']) qnop.build_plot(result)

      There might be more efficient ways to do this, so if anyone has one feel free to post it here.

    • O

      How long will the submission of a strategy take?
      Support • • omohyoid

      4
      0
      Votes
      4
      Posts
      284
      Views

      support

      Dear @quani42,

      Your submissions are in the queue and will be processed. Also, all submissions that are sent to the contest before the deadline will be eligible to take part in it.

      Regards

    • S

      Pairs trading with states iterations
      Strategy help • • spancham

      4
      0
      Votes
      4
      Posts
      435
      Views

      S

      @support
      Cool, thanks very much! 👍

    • A

      Correlation fails although Sharpe ratio > 1
      Support • • agent.hitmonlee

      4
      0
      Votes
      4
      Posts
      257
      Views

      A

      Thanks for the answer!

      I still think something is wrong with this correlation checker. I even used this function to randomize the weights a few times, and I got the same correlation error:

      def add_random_noise(weights, noise_level=0.01): noise = np.random.uniform(-noise_level, noise_level, size=weights.shape) return weights + noise

      I am pretty sure it's impossible to have 90% correlation in this case.

    • A

      Submission Logic Questions
      Support • • auxiliary.snail

      4
      0
      Votes
      4
      Posts
      902
      Views

      support

      @auxiliary-snail Hi,

      unfortunately, this is not allowed and in accordance with the rules. Using hard-coded time periods in which trading algorithm will work differently, is not a quantitative method (just like manual asset selection, e.g. "trade only Apple or Microsoft"). We still haven't implemented a mechanism for automatic recognition of such behaviors in trading strategies, and even though a strategy could be successfully submitted, it will not be eligible for prize winning.
      What we are searching for, is well performing strategy over entire in_sample period (SR>0.7), robust to all market movements 2006-2025, so we can expect it will perform well in future, too.

    • magenta.grimer

      Trend following strategy BUG
      Strategy help • • magenta.grimer

      3
      0
      Votes
      3
      Posts
      317
      Views

      support

      @magenta-grimer

      Hello.

      I confirm this bug.
      It is fixed now.
      If you clone this template again, it will work ok.

      Thank you very much for your report.

    • magenta.grimer

      Can't apply optimizer to another simple strategy!
      Strategy help • • magenta.grimer

      3
      0
      Votes
      3
      Posts
      244
      Views

      support

      @magenta-grimer

      Hello.

      Remove .isel(time=-1).

      ma_slow = close.rolling(time=parameter1).mean() #.isel(time=-1) ma_fast = close.rolling(time=parameter2).mean()#.isel(time=-1)

      It selects the last day, you need an entire series.

      Regards.

    • S

      Error for importing quantiacs module
      Support • • steel.camel

      3
      0
      Votes
      3
      Posts
      755
      Views

      support

      @steel-camel Sorry for the issue, it has been fixed.

    • L

      Error message when enter JupyterLab
      Support • • lemonpie

      3
      0
      Votes
      3
      Posts
      149
      Views

      L

      @support Thanks. Works fine now.

    • O

      I can't find why the submission failed
      Support • • omohyoid

      3
      0
      Votes
      3
      Posts
      243
      Views

      O

      @support
      Actually, I've write the weights to the output function.
      螢幕擷取畫面 2024-04-24 235034.png
      I think the reason might be that the data was out-of-date when the strategy received at the weekend. After the data update in the next day, it failed to pass the test.

    • A

      Saving and recalling a dictionary of trained models
      Support • • alfredaita

      3
      0
      Votes
      3
      Posts
      425
      Views

      A

      @alfredaita
      In case you don't want to run init.py every time in order to install external libraries, I came up with a solution for this. You basically install the library in a folder in your home directory and let the strategy create symlinks to the module path at runtime. More details in this post.

    • N

      Use of Technical indicators
      Support • • noka'sworld

      3
      0
      Votes
      3
      Posts
      175
      Views

      N

      @support that is really useful! thank you very much!

    • M

      Error in Online Enviroment
      Support • • magenta.kabuto

      3
      0
      Votes
      3
      Posts
      224
      Views

      support

      Dear magenta.kabuto,

      It appears to be a pandas version mismatch. You can try using different pandas version but it's not documented nor supported and our library could behave in an unexpected manner.

    • A

      Clarification regarding execution time
      Support • • anshul96go

      3
      0
      Votes
      3
      Posts
      325
      Views

      support

      @anshul96go Dear Anshul, it means that the weights for each day have to be generated in less than 10 minutes of time per day.

      Note that all submissions are processed on the server after submission using a muti-pass approach (not single-pass).

      10 minutes per day, times 250 days, times 10 years, that is more than 400 hours of running time.

    • A

      notebook for googlecolab not working
      Support • • alfredaita

      3
      1
      Votes
      3
      Posts
      225
      Views

      A

      @support Thanks seems fine

    • A

      Erroneous Data?
      Support • • antinomy

      3
      1
      Votes
      3
      Posts
      589
      Views

      support

      @antinomy Hello, sorry for delay again. We found a problem with the data provider, sorry.

    • M

      How can we have the estimation of Sharpe submitted ?
      Support • • multi_byte.wildebeest

      3
      2
      Votes
      3
      Posts
      696
      Views

      V

      @multi_byte-wildebeest Hello.

      How to get the Sharpe Ratio is in the Quick Start template.
      https://github.com/quantiacs/strategy-q20-nasdaq100-quick-start/blob/master/strategy.ipynb

      import qnt.stats as qnstats def get_sharpe(market_data, weights): rr = qnstats.calc_relative_return(market_data, weights) sharpe = qnstats.calc_sharpe_ratio_annualized(rr).values[-1] return sharpe sharpe = get_sharpe(data, weights) # weights.sel(time=slice("2006-01-01",None))

      or

      import qnt.output as qnout qnout.check(weights, data, "stocks_nasdaq100")

      or

      stat = qnstats.calc_stat(data, weights) display(stat.to_pandas().tail())

      or

      import qnt.graph as qngraph statistics = qnstats.calc_stat(data, weights) display(statistics.to_pandas().tail()) performance = statistics.to_pandas()["equity"] qngraph.make_plot_filled(performance.index, performance, name="PnL (Equity)", type="log") display(statistics[-1:].sel(field=["sharpe_ratio"]).transpose().to_pandas()) qnstats.print_correlation(weights, data)

      Please look at this post
      https://quantiacs.com/community/topic/515/what-is-forward-looking-and-why-it-s-effective-badly-to-strategy/6?_=1711712434795

    • Documentation
    • About
    • Career
    • My account
    • Privacy policy
    • Terms and Conditions
    • Cookies policy
    Home
    Copyright © 2014 - 2021 Quantiacs LLC.
    Powered by NodeBB | Contributors