About the platform¶
QuantNet — a company that develops tools for creating trading strategies.
We invite users
to participate in the drawing of 500 thousand rubles every quarter, by sending strategies to the competition.
open tools for downloading data from financial exchanges.
open tools for creating trading strategies. You can apply them for private trade.
test trading ideas.
Develop strategies in Jupyter Notebook or JupyterLab.
We provide instances up to 8GB RAM for each strategy.
Getting started¶
The necessary conditions
Click «create strategy» or «copy» any template of ready-made articles.
Below are the main steps involved in most strategies. You can copy the entire strategy and open it in your account.
1. Preparations¶
At first one needs to prepare the workspace - load data and libraries
import xarray as xr
import numpy as np
import pandas as pd
import qnt.data as qndata
import qnt.stepper as qnstepper
import qnt.stats as qnstats
import qnt.graph as qngraph
import qnt.ta as qnta
import qnt.forward_looking as qnfl
import qnt.exposure as qne
import datetime as dt
data = qndata.load_data(min_date = "2017-01-01",
max_date = None,
dims = ("time", "field", "asset"))
«data» is xarray.DataArray that contains stocks historical data. For instance, we want Apple stock open and close prices:
apple_close = data.loc[::, "close", "NASDAQ:AAPL"]
apple_open = data.loc[::, "open", "NASDAQ:AAPL"]
# you can also work with pandas:
# apple_close = data.loc[::, "close", :].to_pandas()["NASDAQ:AAPL"]
Available data explanation is here. Some other data:
all_close = data.loc[::, "close", :]
all_open = data.loc[::, "open", :]
liquid = data.loc[::, "is_liquid", :]
Liquid is a True/False xarray DataArray. A true value for a specific day for a specific company means that the stock has been in the top 500 liquid stocks in the last month.
2. Weights allocation¶
The trading algorithm uses financial data to form the weights, in proportion to which the capital is distributed. A positive weight means a long position (buy), a negative value means a short position (sell).
Suppose, we have a traiding idea - invest money when the growth in stock price is positive. In other words, we want to redistribute capital between portfolio instruments every day in proportion to the formula:
where index i indicates specific stock (detailed description of algorithmic trading is here).
We can allocate capital by assigning weights to the portfolio instuments:
changes = qnta.change(all_close, 122)
weights = xr.where(changes > 0, 1, 0)
You can implement and test any idea you want. Some other examples:
# buy all positions: weights = all_open/all_open
# sell all positions: weights = -all_open/all_open
# the more price change, the more we buy = (all_close - all_open)/all_open
Notice that we trade only liquid stocks. One can form output weights:
output = weights*liquid
# If you worked with pandas and weigths is pandas.Dataframe:
# output = xr.DataArray(weights.values, dims = ["time","asset"], coords= {"time":weights.index,"asset":weights.columns} )
Output normalization, weights sum for one day should be <= 1:
output = output / abs(output).sum('asset')
Accourding to the rules, we should fix exposure:
output = qne.drop_bad_days(output)
qnstats.check_exposure(output)
Ok. The exposure check succeed.
3. Perfomance estimation¶
Once we have constructed an algorithm we need to evaluate it. At first, we need to calculate statistic.
stat = qnstats.calc_stat(data, output)
display(stat.to_pandas().tail())
Algorithm results, calculated on historical data, are usually presented on an equity graph in order to understand the behavior of the cumulative profit:
performance = stat.to_pandas()["equity"]
qngraph.make_plot_filled(performance.index, performance, name="PnL (Equity)", type="log")
We use a set of criteria to evaluate the performance. You can submit your algorithm and take part in a competition if it passes all the requirements.
For instance, according to the rules the Sharpe ratio must be greater than 1, the correlation with other strategies must be less than 90%:
display(stat[-1:].sel(field = ["sharpe_ratio"]).transpose().to_pandas())
qnstats.print_correlation(output, data)
4. Submit¶
If you are satisfied enough with your algorithm and it passes all the requirements you can submit it.
qnstepper.write_output(output)
At this stage, the code is ready for submission. Just click on the submission button on your account page and we will evaluate your strategy live on our servers!
Don“t forget to register on the platform.
Here we briefly presented the most basic features of the QuantNet platform - the rest of this guide is devoted to a more detailed explanation of these and other features.