Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

48 feature eval computation #55

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/pysrc/util/feature_eval.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why r we using dateutil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im stupid, removed and iterating with regular datetime

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from pysrc.adapters.kraken.historical.historical_data_client import HistoricalDataClient
from datetime import datetime
from dateutil.rrule import rrule, DAILY
from pysrc.util.types import TradeMessage, Asset
from pysrc.signal.base_feature_generator import BaseFeatureGenerator
import numpy as np


class Evaluator:

def __init__(self, features: list[str], asset: Asset, start: datetime, end: datetime):
self.features = features
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix with underscore pls

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix the helpers? are you talking about calculate_features()
I thought it wasn't a helper, but would it be better to combine calculate_features and evaluate_features into one "calc_and_eval_features" method

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb i meant like self._features = features

self.asset = asset
self.start = start
self.end = end
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def _get_data_daterange(self, start: datetime, end: datetime) -> list[TradeMessage]:
hist_client = HistoricalDataClient()
res = []
for date in rrule(DAILY, dtstart=start, until=end):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do all the path manip with pathlib

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not anything wrong with using but was there a reason you used rrule instead of doing this manually

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was dumb

res.extend(hist_client.get_trades(self.coin, date, ""))
return res

def calculate_features(self) -> dict[str, list[float]]:
trades = self._get_data_daterange(self.start, self.end)
# ^ this returns a list[TradeMessage], but on_tick expects dict[str, TradeMessage]
# What is key?
kyeoul marked this conversation as resolved.
Show resolved Hide resolved
snapshots = {}
kyeoul marked this conversation as resolved.
Show resolved Hide resolved
# ^ how to get snapshots?
generator_client = BaseFeatureGenerator()
feature_dict = generator_client.on_tick(snapshots, trades)
return feature_dict[self.asset]

# Suppose that returns is passed to evaluate_features
def evaluate_features(self, target: list[float]):
calc_features = self.calculate_features()
input_matrix = []
for feature in self.features:
input_matrix.append(calc_features[feature])
input_matrix.append(target)
return np.corrocoef(input_matrix)
Loading