QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.58k stars 3.23k forks source link

Support Custom Statistics For Python #7544

Open AlexCatarino opened 11 months ago

AlexCatarino commented 11 months ago

Expected Behavior

Use case: we don't want to consider non-trading and/or no-holdings days in the Statistics.

Actual Behavior

Only C#.

Potential Solution

Create IStatisticsServicePythonWrapper and add PyObject overload to SetStatisticsService.

Reproducing the Problem

New feature.

Checklist

jsehnert101 commented 11 months ago

Requested custom statistics in Python to better reflect the underlying characteristics of a trading strategy. For equity-based trading strategies, there is no/negligible opportunity cost during non-trading days (i.e. weekends), so their inclusion will underestimate volatility and average returns, consequently impacting metrics like the Sharpe ratio. In the presence of multiple return streams, one may be less concerned with the opportunity cost of their investment / cash positions of a single return stream - particularly those that are discreet in nature - and more concerned with capturing its behavior in absence of an opportunity cost. Custom statistics will allow users to make their own assumptions on the meaningfulness of the aforementioned concepts.

Martin-Molinero commented 8 months ago

This use case will be covered by https://github.com/QuantConnect/Lean/pull/7690, where we are adding a new algorithm setting TradingDaysPerYear where the user can overwrite the default value used for calculating statistics, default to 252, except for crypto brokerages which will use 365