From a6c6b87bc82426a3dc2d61685aa4070afec7f13d Mon Sep 17 00:00:00 2001 From: robwsc Date: Thu, 23 Mar 2023 15:27:14 -0400 Subject: [PATCH] add builtins --- app/components/strategy/builtins/ta/__init__.py | 1 + app/components/strategy/builtins/ta/correlation.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 app/components/strategy/builtins/ta/correlation.py diff --git a/app/components/strategy/builtins/ta/__init__.py b/app/components/strategy/builtins/ta/__init__.py index 15ac378..72fa10f 100644 --- a/app/components/strategy/builtins/ta/__init__.py +++ b/app/components/strategy/builtins/ta/__init__.py @@ -1,2 +1,3 @@ from components.strategy.builtins.ta.sma import * +from components.strategy.builtins.ta.correlation import * from components.strategy.builtins.ta.logic import Logic as logic \ No newline at end of file diff --git a/app/components/strategy/builtins/ta/correlation.py b/app/components/strategy/builtins/ta/correlation.py new file mode 100644 index 0000000..c5e1423 --- /dev/null +++ b/app/components/strategy/builtins/ta/correlation.py @@ -0,0 +1,12 @@ +import numpy as np + +from components.strategy import Series + + +def correlation_coefficient(x: Series, y: Series, period: int) -> Series: + """ Calculate the correlation coefficient between two lists """ + x = np.array(x) + y = np.array(y) + + # Calculate the correlation coefficient + return Series(np.corrcoef(x, y)[0, 1])