Coder Social home page Coder Social logo

mihakralj / quantalib Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 9.0 3.95 MB

C# TA library for real-time financial analysis, offering ~100 indicators. Available on NuGet, Quantower compatible. Ensures early validity of calculated data, calculation accuracy tested against four TA libraries.

Home Page: https://mihakralj.github.io/QuanTAlib/

License: Apache License 2.0

C# 100.00%
analysis indicator stock technical average crypto equity finance forex momentum

quantalib's People

Contributors

mihakralj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

quantalib's Issues

New wheel?

Hey @mihakralj, I see you’ve forked my skender.stock.indicators library recently, but have started on a path for a new library.

Any feedback on how we can do better to meet your needs?
Or, is your library intended to be uniquely for QuantTower?

We’re always looking for contributors too, if you’re interested in joining us.

coverage.md updates

A few check marks missing for the Skender column:

  • LINREG returned with Slope
  • ZSCORE returned with Standard Deviation
  • LWMA is the same as WMA (duplicate, I think)
  • NATR returned with ATR
  • ADXR returned with ADX
  • AD is same as ADL
  • DMI returned with ADX
  • TRIX
  • CORREL
  • TR returned with ATR
  • HT Trendline

There’s a few others in the Skender library that aren’t in the list too, but I’m not sure if wanted to add those. There’s so many out there, I know, it’s hard to choose and prioritize which to add to these sort of libraries.

Strange results - please advise

Hi

Potentially a very useful library! As you say, there's a lack of C# resources that handle bar-by-bar live updating efficiently.

I realise it's still very new, but the link to the Getting Started notebook is broken, so it's quite hard to get your head around usage.

I've dug around the source, but there seems to be something I'm missing.

For example I expected the code below to output 4, 5, 6, but I'm seeing:

SMA1: 4
SMA2: 4.333333333333333
SMA3: 4.666666666666667

 TSeries vals = new() { 1, 2, 3, 4, 5 };
 SMA_Series sma = new(vals, 3);
 Print.Line("SMA1: " + sma.Last().v);

 vals.Add(6, true);
 Print.Line("SMA2: " + sma.Last().v);

 vals.Add(7, true);
 Print.Line("SMA3: " + sma.Last().v);

I didn't see any examples of the update functionality in the test suite so I'm not sure if it's my issue or yours. If I'm misunderstanding something I'd appreciate any pointers.

More generally, it would be great if you could find the time to fix the notebook, or to add some examples to the readme.

Thanks for all your hard work!

Development plan

@DaveSkender I wanted to share the broader roadmap and vision that I am slowly churning towards.

  • trading assets - currently dependent on a platform where QuanTAlib runs on, but I have simple classes for YahooFinance, Binance and Oanda half-baked already
  • Indicators - typically work on one data series (we are here now)
  • Signals - use indicators and generate buy/hold/sell signals (threshold, crossings)
  • Trades - use signals to generate trade instructions and track drag and commissions
  • Portfolios - use trades to generate a re-balanced list of assets (+ cash) owned and track performance
  • Strategy - a collection of parameters from asset selection to portfolio composition

Success of portfolio is measured by Sharpe or Sortino ratio (or any other performance measures for portfolio); an optimization algo can then fine-tune the strategy to find the highest-yielding portfolio possible within strategy constraints.

For example, a strategy could be defined as:

  • assets: use US-based ETFs in technology sector
  • indicators: use family of moving averages + family of oscillators
  • signals: use a crossover of two MAs + confirmation from an oscillator
  • trades: no more than 1 trade per day, avoid triggering PDT rule, no shorting
  • portfolios: keep at least 10 assets in the portfolio, the largest asset cannot be >25% of total value

Strategies should be re-optimized regularly to find the new possible maxima for the porftolio.

TR and ATR

@twopirllc @DaveSkender
Inconsistencies of early values between libraries on TR (True Range) and ATR (average True range):

  • TA-LIB and Pandas-TA return NaN for the first TR value and have therefore (period+1) of NaN values

  • TA-LIB does a SMA([1, period+1]) for the seeding value

  • Pandas-TA uses rma(tr) that uses .ewm(tr).mean()

  • Skender.Indicators uses RMA() starting from the first value (that's my implementation as well)

  • Among three libraries (TA-LIB, Skender.Indicators and Pandas-TA), there is no consensus on what early ATR should be (they all converge eventually):

Index      TrueRange       TA-Lib          Skender         Pandas-TA      QuanTAlib
-----------------------------------------------------------------------------------
0          2.025             NaN             NaN             NaN            2.025
1          0.891             NaN             NaN             NaN            1.458
2          2.210             NaN             NaN             NaN            1.709
3          0.296             NaN             NaN             NaN            1.356
4          1.160             NaN           1.317             NaN            1.317
5          2.005           1.313           1.454           1.374            1.454
6          1.553           1.361           1.474           1.423            1.474
7          0.723           1.233           1.324           1.246            1.324
8          0.512           1.089           1.162           1.069            1.162
9          1.297           1.130           1.189           1.122            1.189
10         2.382           1.381           1.427           1.404            1.427
11         3.052           1.715           1.752           1.765            1.752
12         1.778           1.728           1.757           1.768            1.757
13         2.485           1.879           1.903           1.919            1.903
14         0.411           1.585           1.604           1.604            1.604
15         4.338           2.136           2.151           2.171            2.151
16         1.849           2.078           2.091           2.104            2.091
17         2.289           2.120           2.130           2.142            2.130
18         2.886           2.274           2.281           2.294            2.281
19         0.499           1.919           1.925           1.929            1.925
20         0.603           1.655           1.660           1.661            1.660

What EMA is the right EMA?

@twopirllc and @DaveSkender
I wanted to hear your opinion on how to start the EMA sequence - assuming we don't want to just hide the first n results with NaNs and hope that the sequence will converge sooner than later.

I wrote a short EMA study to document my thinking, but in a nutshell:

  • calculating SMA for the first period bars - and then switching to EMA - just feels horribly wrong. Transition from SMA to EMA is unnatural and breaks the continuity. Bad option.
  • assuming that the previous phantom EMA value was 0 (prev_ema = 0) and calculate EMA that way generates undershooting EMA, requiring long sequence to converge to the real EMA
  • assuming that the previous phantom EMA value was the same as the first value (prev_ema = data[0]) generates overshooting EMA, also requires long sequence to converge to the real EMA

There is a method from digital signal processing that can adjust outputs with diminishing attenuation, generating an EMA line that seemingly converges to the real EMA within very samples.

I took a hint from David Owen's blog and created a new 'Fast-convering EMA' (you can see the algo in the EMA study).

  • Blue line: input data signal {1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
  • Upper red line: overshooting EMA(p) (assumes that prev_ema = data[0])
  • Lower red line: undershooting EMA(p) (assumes that prev_ema = 0)
  • Green Line: SMA(p) followed by EMA(p) - this is the accepted norm
  • Purple Line: Attenuated, fast-converging EMA(p)

First pic is for p=5, second one is for p=12

image

image

The name might be confusing?

There's already been a QuantLib for the last 20 years, see https://www.quantlib.org/ — having the same name can confuse users. Also, it will make your project difficult to find, since Google will point people to the other one.

Best of luck with your project!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.