santiment / sanpy

Santiment API Python Client
MIT License
94 stars 29 forks source link

Backtest: Annualized return and Sharpe ratio are wrong for non-daily granularity #104

Closed alexander-gr closed 3 years ago

alexander-gr commented 4 years ago

365 days are hardcoded here and here

JanSmirny commented 4 years ago

@alexander-gr Yes true. How could we improve that? Pandas has a function to infer the granularity of the data pd.infer_freq(data.index). Output would be "D". So we could do a bunch of conditions. If "D" then 365, if "H" then 365 * 24. But that only works if the entered time series has a datetime index...

Any better ideas?

valo commented 4 years ago

Should we count the number of intervals for an year and use that? So take self.strategy_returns and see how many data points per year it contains.

JanSmirny commented 4 years ago

But in that case we might run into problems if we use less than a years worth of data for the backtest.

alexander-gr commented 3 years ago

Backtest will be refactored soon. Closing the issue