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
    • nosaai

      AttributeError: module 'qnt.data' has no attribute 'stocks_load_spx_data'
      Support • • nosaai

      4
      0
      Votes
      4
      Posts
      172
      Views

      nosaai

      @vyacheslav_b Apologies for the late response. Thanks for the assistance, all is now well. Cheers

    • C

      Why Sharp ratios is not inverted ?
      Strategy help • • cyan.gloom

      4
      0
      Votes
      4
      Posts
      347
      Views

      C

      @support
      Thanks a lot !

    • C

      How to load data to work with Multi-backtesting_ml
      Strategy help • • cyan.gloom

      4
      1
      Votes
      4
      Posts
      346
      Views

      V

      @cyan-gloom

      Hello. The provided code is insufficient to understand the problem.

      I assume that a certain function might not be returning the required value (for instance, the function where your model is being created).

      I recommend that you check all return values of functions, using tools like display or print. Then, compare them with what is returned in properly working examples.

      The state allows you to use data from previous iterations. You can find an example here:
      https://github.com/quantiacs/toolbox/blob/2f4c42e33c7ce789dfad5d170444fd542e28c8ae/qnt/examples/004-strategy-futures-multipass-stateful.py

    • S

      Q22 submission, strategies excluded
      Support • • Sun-73

      4
      1
      Votes
      4
      Posts
      346
      Views

      S

      Hi @support, everything is all right now. Thank you!

    • J

      Fundamental Data: Periodic indicators & Instant indicators
      Strategy help • • johback

      4
      1
      Votes
      4
      Posts
      314
      Views

      V

      @johback

      Hello

      More examples are here https://github.com/quantiacs/toolbox/blob/main/qnt/tests/test_fundamental_data.py

      This is a simple example.

      import qnt.data as qndata import datetime as dt import qnt.data.secgov_indicators import qnt.data as qndata import qnt.stats as qns assets = qndata.stocks.load_ndx_list(tail=dt.timedelta(days=5 * 365)) assets_names = [i["id"] for i in assets] data = qndata.stocks.load_ndx_data(tail=dt.timedelta(days=5 * 365), dims=("time", "field", "asset"), assets=assets_names, forward_order=True) facts_names = ['operating_expense'] # 'assets', 'liabilities', 'ivestment_short_term' and other fundamental_data = qnt.data.secgov_load_indicators(assets, time_coord=data.time, standard_indicators=facts_names) # Operating expenses include marketing, noncapitalized R&D, # travel and entertainment, office supply, rent, salary, cogs... weights = fundamental_data.sel(field='operating_expense') is_liquid = data.sel(field="is_liquid") weights = weights * is_liquid # calc stats stats = qns.calc_stat(data, weights.sel(time=slice("2006-01-01", None))) display(stats.to_pandas().tail()) # graph performance = stats.to_pandas()["equity"] import qnt.graph as qngraph qngraph.make_plot_filled(performance.index, performance, name="PnL (Equity)", type="log")
    • P

      Xarray Value Error
      Strategy help • • pink.seel

      4
      0
      Votes
      4
      Posts
      373
      Views

      support

      @pink-seel Super that you found it, please do not hesitate to ask for support!

    • R

      Processing Time
      General Discussion • • rezhak21

      4
      0
      Votes
      4
      Posts
      450
      Views

      R

      @support ok, thank you!

    • E

      Q17 Machine learning - RidgeRegression (Long/Short); there is an error in the code
      Strategy help • • EDDIEE

      4
      1
      Votes
      4
      Posts
      549
      Views

      E

      @support

      This is a possible fix, but no gurantee. You have to adjust also the prediction function.

      def train_model(data):
      """Create and train the models working on an asset-by-asset basis."""

      models = dict()

      asset_name_all = data.coords['asset'].values

      data = data.sel(time=slice('2013-05-01',None)) # cut the noisy data head before 2013-05-01

      features_all = get_features(data)
      target_all = get_target_classes(data)

      model = create_model()

      for asset_name in asset_name_all:

      # drop missing values: target_cur = target_all.sel(asset=asset_name).dropna('time', 'any') features_cur = features_all.sel(asset=asset_name).dropna('time', 'any') # align features and targets: target_for_learn_df, feature_for_learn_df = xr.align(target_cur, features_cur, join='inner') if len(features_cur.time) < 10: # not enough points for training continue try: model.fit(feature_for_learn_df.values, target_for_learn_df) models[asset_name] = model except KeyboardInterrupt as e: raise e except: logging.exception('model training failed')

      return models

    • O

      How to turn off "WARNING: some dates are missed in the portfolio_history"
      Support • • omohyoid

      4
      0
      Votes
      4
      Posts
      358
      Views

      support

      @omohyoid Hi, we do not have such calls, sorry

    • A

      Submission Logic Questions
      Support • • auxiliary.snail

      4
      0
      Votes
      4
      Posts
      321
      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.

    • E

      Improving Quantiacs: Aligning Developer Objectives with the ones of Quantiacs
      General Discussion • developers improvement quantiacs rankings risk • • EDDIEE

      4
      3
      Votes
      4
      Posts
      494
      Views

      N

      @eddiee Hi, Mr. Eddie.

      I am new to building strategies using ML/DL on Quantiacs and am very impressed with the OS performance of your ML strategies. I hope you can give me your contact (mail, limkedin,...) so I can learn from your experience in building an ML/DL strategy.

      Sincerely thank.

    • A

      Jupyter/Jupyter Lab are not working for code editing/running
      Support • • AlgoQuant

      4
      0
      Votes
      4
      Posts
      264
      Views

      support

      @captain-nidoran Fixed, sorry for issue

    • cespadilla

      Question about the Q17 Machine Learning Example Algo
      Strategy help • • cespadilla

      4
      1
      Votes
      4
      Posts
      461
      Views

      V

      @cespadilla Hello.

      The reason is in "train_model" function.

      def train_model(data): asset_name_all = data.coords['asset'].values features_all = get_features(data) target_all = get_target_classes(data) models = dict() for asset_name in asset_name_all: # drop missing values: target_cur = target_all.sel(asset=asset_name).dropna('time', 'any') features_cur = features_all.sel(asset=asset_name).dropna('time', 'any') target_for_learn_df, feature_for_learn_df = xr.align(target_cur, features_cur, join='inner') if len(features_cur.time) < 10: continue model = get_model() try: model.fit(feature_for_learn_df.values, target_for_learn_df) models[asset_name] = model except: logging.exception('model training failed') return models

      If there are less than 10 features for training the model, then the model is not created (if len(features_cur.time) < 10).

      This condition makes sense. I would not remove it.

      The second thing that can affect is the retraining interval of the model ("retrain_interval").

      weights = qnbt.backtest_ml( train=train_model, predict=predict_weights, train_period=2 *365, # the data length for training in calendar days retrain_interval=10 *365, # how often we have to retrain models (calendar days) retrain_interval_after_submit=1, # how often retrain models after submission during evaluation (calendar days) predict_each_day=False, # Is it necessary to call prediction for every day during backtesting? # Set it to true if you suspect that get_features is looking forward. competition_type='crypto_daily_long_short', # competition type lookback_period=365, # how many calendar days are needed by the predict function to generate the output start_date='2014-01-01', # backtest start date analyze = True, build_plots=True # do you need the chart? )
    • M

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

      4
      0
      Votes
      4
      Posts
      239
      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.

    • A

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

      4
      0
      Votes
      4
      Posts
      216
      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.

    • T

      Calculation time exceeded on submission
      Support • • TheFlyingDutchman

      4
      1
      Votes
      4
      Posts
      331
      Views

      V

      @theflyingdutchman Hello,

      Another option is to rewrite your strategy for a single-pass version before submitting it. This approach will significantly speed up the calculations. However, it's important to note that the actual statistical values can only be tracked after submitting the strategy to the competition.

      For example:
      https://github.com/quantiacs/strategy-ml-crypto-long-short/blob/master/strategy.ipynb

      To adapt this strategy for a single-pass version, follow these steps:

      Comment out or delete the line where qnbt.backtest_ml is used. Insert the following code: import xarray as xr import qnt.ta as qnta import qnt.data as qndata import qnt.output as qnout import qnt.stats as qnstats retrain_interval = 3*365 + 1 data = qndata.stocks.load_ndx_data(tail=retrain_interval) models = train_model(data) weights = predict(models, data) In a new cell, insert code to save the weights: qnout.write(weights)

      To view the strategy's statistics, use the following code in a new cell:

      # Calculate stats stats = qnstats.calc_stat(data, weights) display(stats.to_pandas().tail()) # Graph performance = stats.to_pandas()["equity"] import qnt.graph as qngraph qngraph.make_plot_filled(performance.index, performance, name="PnL (Equity)", type="log")

      The qnbt.backtest_ml function is a unique tool for evaluating machine learning strategies, which stands out from what is offered on other platforms. It allows users to set retraining intervals and analyze statistical metrics of the strategy, as opposed to the traditional evaluation of the machine learning model. This provides a deeper understanding of the strategy's effectiveness under various market conditions.

    • magenta.grimer

      Importing external data
      General Discussion • • magenta.grimer

      4
      1
      Votes
      4
      Posts
      328
      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.

    • N

      SMA Example
      Support • • Nikos84

      4
      0
      Votes
      4
      Posts
      244
      Views

      N

      @support Thank you!

    • S

      Stocks strategy
      Strategy help • • spancham

      4
      0
      Votes
      4
      Posts
      429
      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
      318
      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.

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