Ohkthx/tatk-rs

Canonical struct naming?

virtualritz opened this issue · 7 comments

Hey, I just found this crate after you mentioned you rolled your own crate on ta-rs. Nice!

One thing I saw is that you use non-canonical struct names (all uppercase).

From the Rust API Guidelines on naming:

In UpperCamelCase, acronyms and contractions of compound words count as one word: use Uuid rather than UUID, Usize rather than USize or Stdin rather than StdIn.

Ohkthx commented

Hey, I just found this crate after you mentioned you rolled your own crate on ta-rs. Nice!

Welcome! Thank you for your input and glad you found me. I didn't want to come of as advertising on their great project. This actually started off with writing my own version of EMA for testing your issue, haha.

One thing I saw is that you use non-canonical struct names (all uppercase).

I struggled with this initially when designing the toolkit for acronyms, for instance EMA and DEMA were much more identifiable than Ema and Dema for me. Most other places I followed the guidelines that weren't acronyms and went with the UpperCamelCase such as LineReg for linear regression, Buffer, and Cross.

I do see your point, and would like to note that I was inconsistent with STDEV instead of StDev, Stdev, or SD, but that idea originated from being similar to Excels naming. I am open to renaming the structs since it is so early and there has not been many downloads or attention on the project. My goal for changes such as these is catch them early especially if they're good for long term growth.

If you think it is a healthy change, I have no problems with the refactor right now and it would not be much work to do. Any suggestions for changing names of some indicators, I am also open ears for!

Ohkthx commented

Let me know what you think about the alternates

original alternate 1 alternate 2 macro name
Variance Var var!() Variance
STDEV Sd Stdev sd!() Standard Deviation
Cross cross!() Cross, Golden / Death
LineReg Lr Linereg lr!() Linear Regression
BBands Bb Bbands bb!() Bollinger Bands
SMA Sma sma!() Simple Moving Average
EMA Ema ema!() Exponential Moving Average
DEMA Dema dema!() Double Exponential Moving Average
MD Mdi Md mdi!() McGinley Dynamic Indicator
OBV Obv obv!() On-Balance Volume
ROC Roc roc!() Rate of Change
RSI Rsi rsi!() Relative Strength Index
MACD Macd macd!() Moving Average Convergence / Divergence
TR Tr tr!() True Range
ATR Atr atr!() Average True Range

You could also use the full names. That would make it stringent. Currently it isn't, even with alternative 2.
Why are Bollinger Bands non simply BB?, Why is Linear Regression not simply LR?

If you use full names you can add macros with the abbreviations that can be used as replacements for Foo::new().

For example:

let ema = ExponentialMovingAverage::new(30, &data);
let ema = ema!(30, &data);
Ohkthx commented

I actually really like the macro idea! Full names are what I wanted to do initially but they took up too much space such as with DEMA. I'll start looking at macros right now and expanding your whole idea, full names are the most descriptive and using short-hand macro names is a nice balance. I'm new to Rust so thanks for giving me the opportunity to learn a something I was partially avoiding (macros), it is good to step out of the comfort zone.

// Why I ended up with DEMA.
let dema = DoubleExponentialMovingAverage::new(30, &data);

Why are Bollinger Bands non simply BB?, Why is Linear Regression not simply LR?

BBands came from wanting to be similar to TA-Lib/ta_BBANDS.c. Great point with LR, TA-Lib used LINEARREG and I wanted to be somewhat true to that.

I updated the chart above with the potential macro names, let me know if any names could be improved on further. Thanks again for the input, it is appreciated.

Ohkthx commented

In the develop branch, 81fa816 introduces all of the indicators names to UpperCamelCase along with implementing all of the macros. All macros reside in macros.rs

Notes:

  • examples/ have been updated to use the macros.
  • tests/ use the UpperCamelCase indicator names.

The macro format I went with is: macro_name!(period, data), I was debating a macro_name![period; data] format but it might be less clear. period being the length of time, and data a vector/array of data. Looking forward to your input or corrections.

Very cool.

Are the values in the assert_eq!()s in tests copied from TA-Lib as well btw.?

Ohkthx commented

Some, not all. I had difficulty parsing some of TA-Libs source, especially the tests portions. A lot of my formulas come from investopedia with using TA-Lib as a reference for further clarification.