I'm using the database QuestDB, and trying to compute moving averages with some market data Is this something that is already available out of the box (like in Influxdb or kdb+), or is there a way around it?
Asked
Active
Viewed 242 times
3
-
This is currently not possible inside QuestDB natively. Once you query the data you can use whatever method you want to compute it. If you'd like to see this in QuestDB consider voting here: https://github.com/questdb/questdb/discussions/1162 – Newskooler Oct 31 '22 at 11:06
1 Answers
0
If you are using Pandas / Python, the following example shows how to calculate the moving average after connecting to the database using postgres wire:
import psycopg2
import pandas as pd
df_trades = pd.DataFrame()
connection = psycopg2.connect(user="admin",
password="quest",
host="127.0.0.1",
port="8812",
database="qdb")
# get query as dataframe
df_trades = pd.read_sql_query("select * from my_table",connection)
# Simple moving average, k=10, of column called 'close'
df_trades['moving_av_10'] = df_trades['close'].rolling(window=10).mean()
print(df_trades.tail())

Brian Smith
- 1,222
- 7
- 17